Reputation: 677
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
Upvotes: 2
Views: 922
Reputation: 914
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.
Upvotes: 5