如何在Facebook Messenger机器人中接收图像 [英] How to receive an image in a Facebook Messenger bot

查看:102
本文介绍了如何在Facebook Messenger机器人中接收图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Facebook Messenger API接收图像形式的附件? 他们的文档仅提供有关如何接收基于文本的消息的说明.

How can I receive an attachment in form of an image through the Facebook Messenger API? Their documentation only provides instructions on how to receive text-based messages.

推荐答案

我不确定您使用哪种语言编写机器人代码,但是由于您所指的是Facebook文档,其中大多数Messenger代码段都位于节点中. js 这是您可以尝试的方法,如果有帮助,请告诉我.

I am not sure what language you are using to code your bot but since you are referring to the facebook documents where most of the messenger code snippets are in node.js Here's something for you to try, let me know if this helps.

app.post('/webhook/', function (req, res) {
 //Getting the mesagess
 var messaging_events = req.body.entry[0].messaging;
  //Looping through all the messaging events
  for (var i = 0; i < messaging_events.length; i++) {
   var event = req.body.entry[0].messaging[i];
   //Checking for attachments
   if (event.message.attachments) {
    //Checking if there are any image attachments 
    if(atts[0].type === "image"){
     var imageURL = atts[0].payload.url;
     console.log(imageURL);
    }
   }
  }      
 }

这篇关于如何在Facebook Messenger机器人中接收图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆