This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Help us improve Python packaging - Donate today!
Project Description

Installation

Minimum Requirements

  • Python 2.7+ or Python 3.3+

Install from pip

pip install fb_messenger

Build from source

git clone https://github.com/shananin/fb_messenger
cd fb_messenger
python setup.py install

How to develop

make install # create virtualenv folder and install requirements
make lint # run pylint
make test # run tests
make clean # remove virtualenv folder

How to Use

Send simple text

from fb_messenger.client import FBMessenger
from fb_messenger import attachments
from fb.messenger.exceptions import MessengerAPIError

client = FBMessenger(ACCESS_TOKEN, logger_level=logging.DEBUG)
text = attachments.Text('hello!')

try:
    response = client.send_attachment(RECIPIENT_ID, text)
except MessengerAPIError as e:
    LOGGER.debug(e)

Send attachment

More examples look into examples folder.

image = attachments.Image('http://example.com/img.jpg')

try:
    response = client.send_attachment(RECIPIENT_ID, text)
except MessengerAPIError as e:
    LOGGER.debug(e)

Send action

from fb_messenger.types import action_types

try:
    response = client.send_action(RECIPIENT_ID, action_types.MARK_SEEN)
except MessengerAPIError as e:
    LOGGER.debug(e)

How to process messages in Flask

from flask import Flask, request
import logging
from fb_messenger.client import FBMessenger
from fb_messenger.types import webhook_types

app = Flask(__name__)

logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)

client = FBMessenger(ACCESS_TOKEN, logger_level=logging.DEBUG)


@app.route('/webhook', methods=['GET'])
def get_webhook():
    if request.args.get('hub.verify_token', '') == VERIFY_TOKEN:
        return request.args.get('hub.challenge', '')

    return 'Error', 400


@app.route('/webhook', methods=['POST'])
def post_webhook():
    try:
        client.process_message(request.get_json())
    except Exception as e:
        LOGGER.debug(e)

    return 'ok'


@client.register_webhook(webhook_types.MESSAGE_RECEIVED)
def message_received(webhook):
    """
    :type webhook: fb_messenger.webhooks.MessageReceived
    """
    LOGGER.debug((webhook_types.MESSAGE_RECEIVED, webhook))


@client.register_webhook(webhook_types.POSTBACK_RECEIVED)
def postback_received(webhook):
    """
    :type webhook: fb_messenger.webhooks.Postback
    """
    LOGGER.debug((webhook_types.POSTBACK_RECEIVED, webhook))


@client.register_webhook(webhook_types.AUTHENTICATION)
def authentication(webhook):
    """
    :type webhook: fb_messenger.webhooks.Authentication
    """
    LOGGER.debug((webhook_types.AUTHENTICATION, webhook))


@client.register_webhook(webhook_types.ACCOUNT_LINKING)
def account_linking(webhook):
    """
    :type webhook: fb_messenger.webhooks.AccountLinking
    """
    LOGGER.debug((webhook_types.ACCOUNT_LINKING, webhook))


@client.register_webhook(webhook_types.MESSAGE_DELIVERED)
def message_delivered(webhook):
    """
    :type webhook: fb_messenger.webhooks.MessageDelivered
    """
    LOGGER.debug((webhook_types.MESSAGE_DELIVERED, webhook))


@client.register_webhook(webhook_types.MESSAGE_READ)
def message_read(webhook):
    """
    :type webhook: fb_messenger.webhooks.MessageRead
    """
    LOGGER.debug((webhook_types.MESSAGE_READ, webhook))


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')
Release History

Release History

0.3.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
fb_messenger-0.3.0.tar.gz (8.0 kB) Copy SHA256 Checksum SHA256 Source Jul 27, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting