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引用不明确:ExecutorService中的提交(可调用)和ExecutorService中的方法提交(可运行)匹配   java Get()和Set()在多个@Test、Selenium WebDriver之间   java更改同一会话中的entitymanager数据源   java为不同的日志文件配置不同的JDK日志格式   JavaSpring从JSON响应到网页   java IN子句在PreparedStatement上仅返回1行   java在使用数据提供程序时使用Testng优先级   如何在java中实现ketama算法?   java弹出窗口宽度和高度=0   java JLayeredPane未使用JFrame调整大小   将iCalendar DateTime转换为Java日期对象   java Fibonacci堆问题   java如何在spring数据jpa中映射友元请求实体   java Instanceof for generic with<?>或者没有<?>   java Hibernate回调用于许多联接表操作?