问题
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);
});
}
回答1:
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).
So what happens is:
- 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
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.
来源:https://stackoverflow.com/questions/53795822/how-to-make-the-correct-flow-in-dialogflow-with-webhook