第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Dialogflow 實現(xiàn)內(nèi)聯(lián)編輯器 API 請求

Dialogflow 實現(xiàn)內(nèi)聯(lián)編輯器 API 請求

白衣非少年 2021-12-23 14:16:33
我正在嘗試讓機器人回答從 API 收到的信息,但無法正常工作。在 firebase 控制臺日志中,我可以看到 api 確實響應(yīng)了我需要的信息。下面的所有代碼:'use strict';const axios = require('axios');const functions = require('firebase-functions');const {WebhookClient} = require('dialogflow-fulfillment');const {Card, Suggestion} = require('dialogflow-fulfillment');process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statementsexports.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 callAPI(agent){    const food = agent.parameters.Food;    const subject = agent.parameters.Subject;    const number = agent.parameters.number;    const question = subject + " "+number +" "+food;    const questionReady = question.replace(/ /g, '+');    const apiKey = "key";    const baseUrl = "https://api.spoonacular.com/recipes/quickAnswer?q=";    const apiUrl =  baseUrl + questionReady + "&apiKey=" + apiKey;    axios.get(apiUrl).then((result) => {        console.log(result);           console.log(result.data);           console.log(result.data.answer);        agent.add(result);        agent.add(result.data);        agent.add(result.data.answer);    });  }  let intentMap = new Map();  intentMap.set('Default Welcome Intent', welcome);  intentMap.set('Default Fallback Intent', fallback);  intentMap.set('food', callAPI);  agent.handleRequest(intentMap);});
查看完整描述

1 回答

?
蠱毒傳說

TA貢獻1895條經(jīng)驗 獲得超3個贊

最可能的原因是您沒有使用 aPromise或async函數(shù)調(diào)用,因此您的 Handler 在您對 API 的調(diào)用完成之前沒有返回任何內(nèi)容。


要解決這個問題,callAPI()需要返回返回的 Promise axios.get()。同樣,調(diào)用的 Intent Handler 也callAPI()需要返回該 Promise(或來自then()塊的另一個 Promise )。


Dialogflow 庫需要這樣做,因此它知道在將任何內(nèi)容返回給用戶之前等待 API 調(diào)用完成(從而解決 Promise)。


在您的情況下,這就像將呼叫更改axios.get()為類似的東西一樣簡單


return axios.get(apiUrl).then((result) => {

  // Rest of this call here


查看完整回答
反對 回復(fù) 2021-12-23
  • 1 回答
  • 0 關(guān)注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號