首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用wit.ai中的图片回答?

如何用wit.ai中的图片回答?
EN

Stack Overflow用户
提问于 2016-11-10 06:59:10
回答 2查看 712关注 0票数 1

我正在尝试用fb_messenger wit.ai.In wit.ai来创建一个images.How机器人,我只能做回答和提问--我只想通过向用户展示images.How来回答这个问题?请指导我。非常感谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-10 12:53:33

您需要使用messenger在Wit操作中发送图像:

例如,如果您使用的是Node:

代码语言:javascript
复制
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上的故事中的“机器人发送”部分,这样你就不会同时发送图片和网址了。

希望这能有所帮助!

票数 0
EN

Stack Overflow用户

发布于 2016-11-10 09:17:01

您需要使用图像附件模板。

代码语言:javascript
复制
curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"<USER_ID>"
  },
  "message":{
    "attachment":{
      "type":"image",
      "payload":{
        "url":"<IMAGE_URL>"
      }
    }
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>" 

更多信息这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40521633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档