Dialogflow - Google 助手:显示消息后设置 FollowupEvent
Dialogflow - Google Assistant: setFollowupEvent after showing a message
这是我的用例:在我实现的某个地方,在处理 Intent A 时,我想使用 setFollowupEvent
调用 Intent B。类似于:
function intentA_Handler(){
....
agent.add('This is the response when calling Intent A');
agent.setFollowupEvent('call_intent_B_event');
}
function intentB_Handler(){
agent.add('I am in intent B now.');
....
}
我的期望:
- 小助手显示&说出字符串这是调用Intent A时的响应
- 然后调用
agent.setFollowupEvent('call_intent_B_event');
并显示并说出字符串 我现在处于意图 B。
会发生什么:
助手立即向我显示并说出字符串我现在在意图B中并省略了第一个字符串这是调用意图A时的响应
已经尝试过:
function intentA_Handler(){
....
new Promise((resolve, reject) => {
agent.add('This is the response when calling Intent A');
resolve();
});
agent.setFollowupEvent('call_intent_B_event');
}
但还是一样的结果。知道如何实现我的目标吗?
这是预期的行为。后续事件返回到 Dialogflow,而不是 Google 平台上的操作。第二个意图响应将作为来自代理的唯一响应返回给助手。
如果您使用 Actions on Google 客户端库(https://developers.google.com/actions/reference/nodejsv2/overview), the it has a way to pass parameters with the follow up event: https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#followup
您可以使用参数值来跟踪要包含在最终响应中的其他信息。
一般来说 - 如果您是通过履行来做事,则不需要使用后续事件。请记住 - 意图通常代表用户做某事或说某事,不是您想要的回复。
如果您需要在 A 和 B 的意图处理程序中调用一些代码 - 只需将该代码作为另一个函数调用即可。如果您想在 A 和 B 中以相同的消息结束 - 那么您可以直接或通过调用公共函数来调用 add()
并在 A 和 B 中使用您想要的消息。也许是这样的:
function addMessageB(){
agent.add('This was from adding message B.');
}
function intentA_Handler(){
....
agent.add('This is the response when calling Intent A');
addMessageB();
}
function intentB_Handler(){
addMessageB();
....
}
有一些限制(例如,您只能 add()
两个简单消息),但这是一般方法。
这是我的用例:在我实现的某个地方,在处理 Intent A 时,我想使用 setFollowupEvent
调用 Intent B。类似于:
function intentA_Handler(){
....
agent.add('This is the response when calling Intent A');
agent.setFollowupEvent('call_intent_B_event');
}
function intentB_Handler(){
agent.add('I am in intent B now.');
....
}
我的期望:
- 小助手显示&说出字符串这是调用Intent A时的响应
- 然后调用
agent.setFollowupEvent('call_intent_B_event');
并显示并说出字符串 我现在处于意图 B。
会发生什么:
助手立即向我显示并说出字符串我现在在意图B中并省略了第一个字符串这是调用意图A时的响应
已经尝试过:
function intentA_Handler(){
....
new Promise((resolve, reject) => {
agent.add('This is the response when calling Intent A');
resolve();
});
agent.setFollowupEvent('call_intent_B_event');
}
但还是一样的结果。知道如何实现我的目标吗?
这是预期的行为。后续事件返回到 Dialogflow,而不是 Google 平台上的操作。第二个意图响应将作为来自代理的唯一响应返回给助手。
如果您使用 Actions on Google 客户端库(https://developers.google.com/actions/reference/nodejsv2/overview), the it has a way to pass parameters with the follow up event: https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#followup 您可以使用参数值来跟踪要包含在最终响应中的其他信息。
一般来说 - 如果您是通过履行来做事,则不需要使用后续事件。请记住 - 意图通常代表用户做某事或说某事,不是您想要的回复。
如果您需要在 A 和 B 的意图处理程序中调用一些代码 - 只需将该代码作为另一个函数调用即可。如果您想在 A 和 B 中以相同的消息结束 - 那么您可以直接或通过调用公共函数来调用 add()
并在 A 和 B 中使用您想要的消息。也许是这样的:
function addMessageB(){
agent.add('This was from adding message B.');
}
function intentA_Handler(){
....
agent.add('This is the response when calling Intent A');
addMessageB();
}
function intentB_Handler(){
addMessageB();
....
}
有一些限制(例如,您只能 add()
两个简单消息),但这是一般方法。