Facebook Messenger平台的Python包装器

pymessenger2的Python项目详细描述


Facebook Messenger Platform的python包装器。

disclaimer:此包装是not正式包装,不 无论如何都要代表Facebook。

关于

此包装具有以下功能:

  • send_text_message(recipient_id, message)
  • send_message(recipient_id, message)
  • send_generic_message(recipient_id, elements)
  • send_button_message(recipient_id, text, buttons)
  • send_quick_reply(recipient_id, text, buttons)
  • send_attachment(recipient_id, attachment_type, attachment_path)
  • send_attachment_url(recipient_id, attachment_type, attachment_url)
  • send_image(recipient_id, image_path)
  • send_image_url(recipient_id, image_url)
  • send_audio(recipient_id, audio_path)
  • send_audio_url(recipient_id, audio_url)
  • send_video(recipient_id, video_path)
  • send_video_url(recipient_id, video_url)
  • send_file(recipient_id, file_path)
  • send_file_url(recipient_id, file_url)
  • send_action(recipient_id, action)
  • send_raw(payload)
  • get_user_info(recipient_id)

您可以在中查看其中的代码/文档 bot.py

函数返回对 脸谱网。

注册访问令牌

你需要设置一个Facebook App,facebook页面,获取 页面访问令牌并将应用程序链接到页面,然后才能真正 开始使用发送/接收服务。

This quickstart guide should help

安装

pip install pymessenger2

用法

frompymessenger2.botimportBotbot=Bot(<access_token>,[optional:app_secret])bot.send_text_message(recipient_id,message)

注意:来自Facebook关于用户ID的信息

These ids are page-scoped. These ids differ from those returned from Facebook Login apps which are app-scoped. You must use ids retrieved from a Messenger integration for this page in order to function properly.

If ^{tt19}$ is initialized, an app_secret_proof will be generated and send with every request. Appsecret Proofs helps further secure your client access tokens. You can find out more on the Facebook Docs

发送通用模板消息:

Generic Template Messages allows you to add cool elements like images, text all in a single bubble.
frompymessenger2.botimportBotfrompymessenger2importElementbot=Bot(<access_token>)elements=[]element=Element(title="test",image_url="<arsenal_logo.png>",subtitle="subtitle",item_url="http://arsenal.com")elements.append(element)bot.send_generic_message(recipient_id,elements)

输出:

Generic Bot Output

通用机器人输出

使用url发送图像/视频/文件:

frompymessenger2.botimportBotbot=Bot(<access_token>)image_url="http://url/to/image.png"bot.send_image_url(recipient_id,image_url)

待办事项

  • 结构化消息
  • 接收消息
  • 航空公司
  • 测试!

示例

Screenshot of Echo Facebook Bot

Echo Facebook机器人的屏幕截图

您可以在examples/

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在表被注释到配置之前获取表的元数据?   java滚动条不会出现在JList上   java JOGL监视器GPU内存   java为什么要使用RecyclerView onDraw延迟   java定制Oppo Reno 2 Z CPH1951(手机型号)的固件(闪存文件)   java自定义线程池执行器   java如何解决发布版本中重复的jar条目[com/安卓/volley/R.class]?   java如何使用Bukkit API触发事件?   java在blazemeter jmeter RTE插件中使用ctrl+w输入   C#/Visual Studio的java JDT等价物   java为什么当maxread值很大而收到的消息数量很小时,卡夫卡消费者会无限期消费?   java游戏2。x:包含模板列表的绑定模型   带压缩的java日志旋转   运行时。exec用java运行程序读取它正在做什么