如何回答wit.ai中的图像?

时间:2016-11-10 06:59:11

标签: facebook-messenger wit.ai

我正在尝试使用wit.ai.In wit.ai创建一个fb_messenger机器人,我只能回答和问题只是文本。但我想通过显示图像回复用户。如何做?请指导我。 非常感谢你。

2 个答案:

答案 0 :(得分:0)

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

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>" 

更多信息here

答案 1 :(得分:0)

您需要使用信使Bot:

在您的Wit动作中发送图像

示例,如果您正在使用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)
},

别忘了删除&#34; Bot发送&#34;部分来自你在Wit.ai的故事,这是你不发送图像和URL。

希望这有帮助!