У меня есть успешный Webhook, но я не могу отправить тексту выполнения в диалоге - PullRequest
0 голосов
/ 05 апреля 2019

У меня проблема с запросом.Я получаю данные из API и Webhook успешно, но я не могу показать в полном тексте.Я отправляю запрос API и получаю ответ.Но я не понял, почему я не могу показать в качестве ответа пользователю.Нет ошибки в Firebase и о запросе.Кто-нибудь может помочь?

Вот мои скриншоты при запуске этого кода.

screenshot1 screenhot2

  'use strict';

  const http = require('http');
  const functions = require('firebase-functions')
  const {dialogflow} = require('actions-on-google');
  const app = dialogflow({debug: true});

  const host = 'https://www.boredapi.com/api/activity?participants=1';

  exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => {


    // Call the weather API
    callBored().then((output) => {
      res.json({ 'fulfillmentText': output }); // Return the results of the weather API to Dialogflow
    }).catch(() => {
      res.json({ 'fulfillmentText': `NOOOOOOO FAİLED` });
    });
  });

  function callBored () {
    return new Promise((resolve, reject) => {
      // Create the path for the HTTP request to get the weather


      // Make the HTTP request to get the weather
      https.get(host, (resp) => {
      let data = '';
         resp.on('data', (chunk) => {
          data += chunk;
      });

        res.on('end', () => {
          // After all the data has been received parse the JSON for desired data

          // Create response
          let output =JSON.parse(data).activity;

          // Resolve the promise with the output text
          console.log(output);
          resolve(output);


        });
        res.on('error', (error) => {
          console.log(`Error calling the weather API: ${error}`)
          reject();
        });
      });
    });
  }
...