如何用wit.ai中的图像回答? [英] How to answer back with images in wit.ai?
本文介绍了如何用wit.ai中的图像回答?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用wit.ai创建一个fb_messenger机器人.在wit.ai中,我只能回答和提问仅是文本的问题.但是我想通过显示图像来回复用户.该怎么做?请指导我. 非常感谢.
I am trying to create a fb_messenger bot using wit.ai.In wit.ai,i can only do answering and question which is only text.But I want to answering back to user by showing images.How to do it?Please guide me. Thank you very much.
推荐答案
您需要使用Messenger Bot在Wit操作中发送图像:
You need to send the image in your Wit action using the messenger Bot:
使用Node js的示例:
Example if you're using Node js:
const actions = {
/**
* This is used by the "Bot sends" action in Wit
* @param sessionId
* @param text
* @returns {Promise.<T>}
*/
send({sessionId}, {text}) {
// Our bot has something to say!
// Let's retrieve the Facebook user whose session belongs to
const recipientId = sessions[sessionId].fbid;
if (recipientId) {
// Yay, we found our recipient!
// Let's forward our bot response to her.
// We return a promise to let our bot know when we're done sending
//bot is a simple wrapper for Messenger node code provided [here][1]
return bot.sendTextMessage(recipientId, text)
.catch((err) => {
console.error(
'Oops! An error occurred while forwarding the response to',
recipientId,
':',
err.stack || err
);
});
} else {
console.error('Oops! Couldn\'t find user for session:', sessionId);
// Giving the wheel back to our bot
return Promise.resolve()
}
},
['my-custom-action']({sessionId, context, entities, message}) {
//Api calls ...
//now i got an image URL i want to send to the user
return bot.sendImageMessage(recipientId, image_url);
return Promise.resolve(context)
},
别忘了从Wit.ai的故事中删除自动发送"部分,这样做是为了避免同时发送图片和URL.
Don't forget to delete the "Bot sends" part from your story on Wit.ai, this is so you don't send both the Image and the URL.
希望这会有所帮助!
这篇关于如何用wit.ai中的图像回答?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文