代码之家  ›  专栏  ›  技术社区  ›  Jul10

使用节点自定义快速回复。Dialogflow v2中的js Webook

  •  0
  • Jul10  · 技术社区  · 6 年前

    我的用例可以更好地理解这个问题

    我正在开发一个聊天机器人,为工人解决假设装配线中的问题提供支持。机器人与用户打招呼后,会建议用户使用自己的徽章号码进行身份识别。然后,如果用户接受bot的提示,bot会询问列表中需要支持的组件。
    每个工人只能管理装配线组件集合的一个子集。 enter image description here

    我的问题是关于通过节点设置快速回复。jswebhook。在这里你可以看到

    使用快速回复的我的webhook(简化)

    const functions = require('firebase-functions');
    const {WebhookClient} = require('dialogflow-fulfillment');
    const {QuickReplies}= require('dialogflow-fulfillment');
    const https=require('https');
    
    
    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 getAllowedParts(agent){
          /* deleted all unuseful details*/
          agent.add(new QuickReplies(['A','B','C']);
      }  //close getAllowedParts
    
    
      let intentMap = new Map();
      intentMap.set('UserIntro', getAllowedParts);
      agent.handleRequest(intentMap);
    
    }); 
    

    TypeError:QuickReplies不是构造函数

    我跟着我发现的 here 我在 https://github.com/dialogflow/dialogflow-fulfillment-nodejs/blob/master/docs/WebhookClient.md#WebhookClient+handleRequest

    真正的问题是,我无法理解使用Node添加非默认快速回复的正确过程。DialogFlowV2中的JSWebhook。 我也看了看 rich messages documentantion 任何帮助都将不胜感激,谢谢

    1 回复  |  直到 4 年前
        1
  •  1
  •   Sarah Dwyer    6 年前

    您应该看到默认索引中设置的注释掉的快速回复示例。Dialogflow控制台中的js文件。

     agent.add(new Suggestion(`Quick Reply`));
     agent.add(new Suggestion(`Suggestion`));
    

    你也可以从 Github repo 还有其他可用的快速回复方法:

    let suggestion = new Suggestion('reply to be overwritten');
    suggestion.setReply('reply overwritten');