Там есть синтаксическая ошибка в конце карты

я есть агент Dialogflow, для которого я использую Inline Editor (работает на Cloud Functions для Firebase). Когда я пытаюсь встроить обработчик HTTPS GET в обработчик Intent, происходит сбой с записью в журнале «Игнорирование исключения из завершенной функции». Может быть, есть лучший способ сделать это с обещаниями, но я новичок в этом. Я вижу, что на самом деле он выполняет внешний запрос после обновления до плана Blaze, так что это не ограничение платежного аккаунта. Во всяком случае, вот код:

'use strict';

const functions = require('firebase-functions');
//const rp = require('request-promise');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }

  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  function findWidget(agent) {

    const https = require("https");
    const url = "https://api.site.com/sub?query=";

    agent.add(`Found a widget for you:`);

    var widgetName = getArgument('Name');

    https.get(url + widgetName, res => {
      res.setEncoding("utf8");
      let body = "";
      res.on("data", data => {
        body += data;
      });
      res.on("end", () => {

        body = JSON.parse(body);

        agent.add(new Card({
            title: `Widget ` + body.name,
            text: body.description,
            buttonText: 'Open link',
            buttonUrl: body.homepage
          })
        );
      });
    });  
  }

// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('Find Old Movie Intent', findOldMovie);
intentMap.set('Find Movie Intent', findMovie);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});

Ответы на вопрос(1)

Ваш ответ на вопрос