Wit.ai如何添加动态快速回复 [英] Wit.ai How to add dynamic Quick Replies
问题描述
这是Wit.ai文档中的句子: https ://wit.ai/docs/recipes#categorize-the-user-intent
如何添加动态快速回复
如果要以编程方式创建快速回复,您需要
使用Bot Executes触发您身边的功能,将创建
这些快速回复。
好的,我可以轻松实现!
然后,您可以将它们存储在上下文中。在你身边的
发送函数中,如果你在上下文中有
,那么你可以将它们与bot的答案一起发送。
有人可以为我翻译这句最后一句话,因为我不明白我所做的事情。我想添加动态快速回复在我的Node.js bot与Wit.ai
谢谢
p>我正在为我的机器人使用Wit.ai做Facebook Messenger。
在我的动作中,我在上下文中存储我的动态快速回复:
myAction({context,text,entities}){
context.quick_replies = [
{
标题:'选项A',
content_type:'text',
有效载荷:'空'
},
{
标题:'选项B',
content_type:'text',
payload:'empty'
},
]
}
然后在 send()
我附加任何快速回复我的短信:
send(req,res){
await textMessage(messenger_id,res.text,req.context.quick_replies)
}
其中 textMessage()
看起来像这样: / p>
导出异步函数textMessage(recipientId,text,quick_replies = null){
const messageData = {
收件人:{id:recipientId},
message:{
quick_replies:quick_replies,
text:text
}
}
await request {
url:'https://graph.facebook.com/v2.6/me/messages',
qs:{access_token:FB_PAGE_TOKEN},
方法:'POST',
json:messageData
})
}
基本上,我创建并附上我自己的快速回复。
如果您在Wit.ai中有静态快速回复,那么您将在 send()
以下格式: res.quickreplies = ['是','否']
然后您可以格式化并附加这些选项。 >
Here is the sentence from the Wit.ai doc : https://wit.ai/docs/recipes#categorize-the-user-intent
How to add dynamic Quick Replies
If you want to programmically create Quick Replies, you will need to use a Bot Executes to trigger a function on your side that will create these Quick Replies.
Ok, I can do that easily !
You can then store them in your context. In the send function on your side, if you have them in the context you will send them with the bot’s answer.
Can someone translate this last sentence for me because I don't understand what I shroud do. I want to add dynamic Quick Replies in my Node.js bot With Wit.ai
Thank you
I'm doing something like this for my bots using Wit.ai for Facebook Messenger.
In my action I store my dynamic quick replies in context:
myAction({ context, text, entities }) {
context.quick_replies = [
{
title: 'Option A',
content_type: 'text',
payload: 'empty'
},
{
title: 'Option B',
content_type: 'text',
payload: 'empty'
},
]
}
And then in send()
I attach any quick replies to my text message:
send(req, res) {
await textMessage(messenger_id, res.text, req.context.quick_replies)
}
Where textMessage()
looks something like this:
export async function textMessage(recipientId, text, quick_replies = null) {
const messageData = {
recipient: { id: recipientId },
message: {
quick_replies: quick_replies,
text: text
}
}
await request({
url: 'https://graph.facebook.com/v2.6/me/messages',
qs: { access_token: FB_PAGE_TOKEN },
method: 'POST',
json: messageData
})
}
Basically, I create and attach the quick replies on my own.
If you have static quick replies in Wit.ai, then you will get them in send()
in this format: res.quickreplies = ['Yes', 'No']
and then you can format and attach these options.
这篇关于Wit.ai如何添加动态快速回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!