aiofb package

Submodules

aiofb.api module

class aiofb.api.GraphAPI(access_token=None, session=None, timeout=10)[source]

Bases: object

A Facebook Graph API wrapper.

https://developers.facebook.com/docs/graph-api/

ROOT_URL = 'https://graph.facebook.com'
URL = 'https://graph.facebook.com/v3.0'
VERSION = '3.0'
access_token = None

str: API access token

async_timeout = None

int: timeout for HTTP requests

get(path, session=None, **kwargs)[source]

Make a HTTP GET request to the API.

A wrapper to request() for GET requests.

post(path, session=None, **kwargs)[source]

Make a HTTP POST request to the API.

A wrapper to request() for POST requests.

request(method, path, session=None, **kwargs)[source]

Make an HTTP request to the API

method : str
HTTP method
path : str
API endpoint
session : ClientSession, optional
An aiohttp.ClientSession to be used for making the request.
**kwargs
Keyword arguments to be passed to aiohttp request. For more info check http://aiohttp.readthedocs.io/en/stable/client_reference.html#aiohttp.ClientSession.request
session = None

aiohttp.ClientSession: Aiohttp session.

class aiofb.api.Messenger(access_token=None, session=None, timeout=10)[source]

Bases: aiofb.api.GraphAPI

Messenger Platform API wrapper.

This class provides some additional for accessing Messenger API a bit more conveniently

DEFAULT_USER_PROFILE_FIELDS = ['name', 'first_name', 'last_name', 'profile_pic']

list of str: Default user profile properties to be requested

get_user_profile(psid, fields=None, session=None)[source]

Retrieve user profile information using PSID.

https://developers.facebook.com/docs/messenger-platform/identity/user-profile

psid : str
User PSID
fields : list
List of field to be retieved. If not provided Messenger.DEFAULT_USER_PROFILE_FIELDS will be used.
pass_thread_control(data, session=None)[source]

Pass thread control from your app to another app.

https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/pass-thread-control

data : dict
Data for the handover.
send_message(data, session=None)[source]

Send messages to user

This may include text, attachments, structured message templates, sender actions, and more.

https://developers.facebook.com/docs/messenger-platform/reference/send-api

data : dict
Message data.
take_thread_control(data, session=None)[source]

Take thread control from another app.

https://developers.facebook.com/docs/messenger-platform/handover-protocol/take-thread-control

data : dict
Data for the handover.
update_profile(data, session=None)[source]

Update bot’s Messenger profile properties.

Sets the values of one or more Messenger Profile properties. Only properties set in the request body will be overwritten.

To set or update Messenger Profile properties you must have the ‘Administrator’ role for the Page associated with the bot.

https://developers.facebook.com/docs/graph-api/reference/page/messenger_profile#post

data : dict
data for the update

aiofb.exceptions module

exception aiofb.exceptions.GraphAPIException(message='', response=None)[source]

Bases: Exception

Module contents

Top-level package for aiofb.