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页面,获取 页面访问令牌并将应用程序链接到页面,然后才能真正 开始使用发送/接收服务。
安装
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)
输出:
通用机器人输出
使用url发送图像/视频/文件:
frompymessenger2.botimportBotbot=Bot(<access_token>)image_url="http://url/to/image.png"bot.send_image_url(recipient_id,image_url)
待办事项
- 结构化消息
- 接收消息
- 航空公司
- 测试!
示例
Echo Facebook机器人的屏幕截图
您可以在examples/