Python Wrapper for Facebook Messenger Platform.
Disclaimer: This wrapper is NOT an official wrapper and do not attempt to represent Facebook in anyway.
This wrapper has the following functions:
You can see the code/documentation for there in bot.py.
The functions return the full JSON body of the actual API call to Facebook.
You'll need to setup a Facebook App, Facebook Page, get the Page Access Token and link the App to the Page before you can really start to use the Send/Receive service.
This quickstart guide should help
pip install pymessenger
from pymessenger.bot import Bot
bot = Bot(<access_token>, [optional: app_secret])
bot.send_text_message(recipient_id, message)
Note: From Facebook regarding User IDs
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
app_secret
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.
from pymessenger.bot import Bot
bot = 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)
Output:
from pymessenger.bot import Bot
bot = Bot(<access_token>)
image_url = "http://url/to/image.png"
bot.send_image_url(recipient_id, image_url)
You can find an example of an Echo Facebook Bot in examples/