Package: messenger-api-python
messenger-api-pythonPython Wrapper to various APIs fromFacebook Messenger Platform.FeaturesSend API (v12.0)Send text messagesSend attachments from a remote file (image, audio, video, file)Send attachments from a local file (image, audio, video, file)Send templates (generic messages)Send quick repliesSend buttonsProfile API (v12.0)Set welcome screenSet persistent menuAttachment Upload API (v12.0)Upload attachments from a remote file (image, audio, video, file)Upload attachments from a local file (image, audio video, file)Reusable componentsVarious components used when sending messages in Facebook Messenger are wrapped into Python objects to make them reusable and easy to use.Elements:used to contains various Element objectsElement:a card-like component that holds various other componentsButtons:used to contains various Button objectsButton:button used in various other components, can also be used aloneQuickReplies:used to contains various QuickReply objectsQuickReply:used when sending messages accompanied with quick repliesPersistentMenu:used when setting up persistent menuPrerequisitePython 3.7+installedYou'll need to setup aFacebook App, Facebook Page, get the Page Access Token and link the App to the Page.How to installFrom GitHubClone this repository :gitclonehttps://github.com/krishna2206/messenger-api-python.gitNavigate to the cloned repository folder and build the package :python-mbuildNavigate todistfolder and install the package, <package_name> may vary so I don't explicitly provide the name here :pipinstall<package_name>.whlFrom PypiPackage from Pypi.org may not be the latest one, if you want the latest version of this package, install it from the GitHub repository (see above)pipinstallmessenger-api-pythonUsageSend APIfrommessengerapiimportSendApisend_api=SendApi(<page_access_token>)send_api.send_text_message(<message>,<recipient_id>)Note: From Facebook regarding User IDsThese 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.Ifapp_secretis 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 theFacebook DocsSending a generic template message:Generic Template Messagesallows you to add cool elements like images, text all in a single bubble.frommessengerapiimportSendApifrommessengerapi.componentsimportElements,Element,Buttons,Button,POSTBACKsend_api=SendApi(<page_access_token>)elements=Elements()buttons=Buttons()button=Button(button_type=POSTBACK,title="My button")buttons.add_button(button.get_content())element=Element(title="My element",subtitle="The element's subtitle, image_url=<image_url>, buttons=buttons)elements.add_element(element.get_content())send_api.send_generic_message(elements.get_content(),recipient_id,image_aspect_ratio="horizontal")Sending remote (from URL) image/audio/video/file:frommessengerapiimportSendApisend_api=SendApi(<page_access_token>)# To send an imagesend_api.send_image_attachment(<image_url>,<recipient_id>)# To send an audiosend_api.send_audio_attachment(<audio_url>,<recipient_id>)# To send a videosend_api.send_video_attachment(<video_url>,<recipient_id>)# To send a filesend_api.send_file_attachment(<file_url>,<recipient_id>)Sending local image/audio/video/file:frommessengerapiimportSendApisend_api=SendApi(<page_access_token>)# To send an imagesend_api.send_local_image(<image_location>,<recipient_id>)# To send an audiosend_api.send_local_audio(<audio_location>,<recipient_id>)# To send a videosend_api.send_local_video(<video_location>,<recipient_id>)# To send a filesend_api.send_local_file(<file_location>,<recipient_id>)To doSecuring requestsUnit tests