wasdee / pymessenger

A Python Wrapper for the FB Messenger Bot API (Send/Receive API)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python Wrapper for Facebook Send/Receive API

Wrapper for Facebook's Messenger Platform.

Disclaimer: This wrapper is NOT an official wrapper and do not attempt to represent Facebook in anyway.

About

This wrapper has the following functions:

  • send_text_message(recipient_id, message)

The functions return the full JSON body of the actual API call to Facebook.

Register for an Access Token

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

Installation

$ pip install pymessenger

Usage

from pymessenger.bot import Bot

bot = Bot(<access_token>)
bot.send_text_message(recipient_id, message)

Note: From Facebook

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.

Sending a generic template message:

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:

Generic Bot Output

Todo

  • Structured Messages
  • Receipt Messages
  • Tests!

Example

Screenshot of Echo Facebook Bot

You can find an example of an Echo Facebook Bot in examples/

About

A Python Wrapper for the FB Messenger Bot API (Send/Receive API)


Languages

Language:Python 100.0%