问题
The dialogflow fulfillment code sample can return response in intent as follow.
function welcome(agent) {
agent.add(`Welcome to agent!`);
}
Suppose that I want to trigger another intent name "faq" right after that without any user input. How can it be done? I am expecting something as follow but could not find any documentation.
function welcome(agent) {
agent.add(`Welcome to agent!`);
agent.triggerIntent('faq');
}
I look at the custom event documentation but still unable get the idea to implement it.
Conversation sample:
User A: Hi
Bot: Welcome to agent!
Bot: Please pick FAQ to see detail:
1) FAQ 1
2) FAQ 2
3) FAQ 3
User: Show FAQ
Bot: Please pick FAQ to see detail:
1) FAQ 1
2) FAQ 2
3) FAQ 3
回答1:
In general, you can't do this. But you also don't need to.
Remember that an Intent represents what the user has said and not how you respond to that. So your welcome Intent can reply with a welcome message, and then the FAQ prompting. And a second Intent can reply with just the FAQ prompting.
The easiest way to do this is to have all your replies in your Fulfillment, and have both the handler for the "Welcome" Intent and the "FAQ" Intent call the same function that sends back the prompting reply.
回答2:
you are on the right track, you need to send an event to trigger another intent.
agent.setFollowupEvent('myEventName');
See doc on how to set a followUp event. You also need to define the event in the Intent screen (after Contexts): once an event with that name (ie myEventName) is found the intent is triggered.
来源:https://stackoverflow.com/questions/61172410/trigger-intent-after-bot-response