如何使用webhook在dialogflow中进行正确的处理? [英] How to make the correct flow in dialogflow with webhook?

查看:103
本文介绍了如何使用webhook在dialogflow中进行正确的处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些疑问。

我想用此过程制作一个机器人。

ㅡㅡㅡㅡㅡㅡ ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

我:您好

机器人:欢迎来到我的代理商!

机器人:您叫什么名字?

I:Smith

Bot:Smith

Bot:1

Bot:2

ㅡㅡ br

我将意图设为参数名称的意图 hello。

但是,当它运行,它按以下顺序工作。

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

I:您好

Bot:您叫什么名字?

I:Smith

Bot:欢迎来到我的经纪人!

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

这与我的意图完全不同。

您能推荐一种制作我的物体的正确方法吗?

谢谢

I have some questions.
I want to make a bot with this procedure.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
I : Hello
Bot : Welcome to my agent!
Bot : What's your name?
I : Smith
Bot : Smith
Bot : 1
Bot : 2
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
I made intents 'hello' that has parameter as 'name' required.
But when it runs, it works with the order below.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
I : Hello
Bot : What's your name?
I : Smith
Bot : Welcome to my agent!
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
It's totally different with my intention.
Could you recommend the correct way to make my object?
Thank you so much.

'use strict';

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

process.env.DEBUG = 'dialogflow:debug';

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 hello(agent) {
    agent.add(`Welcome to my agent!`);

    let city = request.body.queryResult.parameters['name']; 
    agent.add(`${city}`);

    information().then((a) => {
    agent.add(JSON.stringify(a)); 
  });
}

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

  let intentMap = new Map();
  intentMap.set('hello', hello);
  intentMap.set('Default Fallback Intent', fallback);

  agent.handleRequest(intentMap);
});

function information(){
  return new Promise(function (resolve, reject) {
    var a = ['1','2'];
    resolve(a);
         });
    }


推荐答案

由于已设置 name 作为必需参数,Dialogflow将等待调用实现Webhook,直到所有必需参数都被填充为止(除非您切换到将实现用于槽位填充,否则您不会这样做) t)。

Since you have set name as a required parameter, Dialogflow will wait to call the fulfillment webhook until all required parameter have been filled (unless you have the switch to use fulfillment for slot filling on, which you don't).

所以发生了什么事


  • 触发Intent是因为 hello与Intent匹配

  • 缺少参数 name ,因此Dialogflow会提示输入

  • 用户答复并填写名称

  • Dialogflow将信息发送到您的Webhook

  • 您的代码添加了欢迎消息

  • The Intent is triggered because "hello" matches the Intent
  • There is a missing parameter name, so Dialogflow prompts for it
  • The user replies and name is filled
  • Dialogflow sends the information to your webhook
  • Your code adds the "welcome" message

这是棘手的地方。并非所有客户端都支持答复中的多个消息,或者支持那么多消息,因此取决于与哪个客户端进行测试,附加的 add()调用可能会被忽略。通常,您应该只添加不同类型的响应(文本,卡片等)以实现跨平台兼容。

Here is where it gets tricky. Not all clients support multiple messages in the reply, or support that many, so the additional add() calls may get ignored depending which client you're testing with. In general - you should only be adding different types of responses (text, cards, etc) to be cross-platform compatible.

这篇关于如何使用webhook在dialogflow中进行正确的处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆