Metadata-Version: 1.1
Name: fbmessenger
Version: 0.1.0
Summary: A python library to communicate with the Facebook Messenger API's
Home-page: https://github.com/rehabstudio/fbmessenger
Author: Ricky Dunlop
Author-email: ricky@rehabstudio.com
License: Apache
Description: Facebook Messenger
        ==================
        
        .. figure:: https://travis-ci.com/rehabstudio/fbmessenger.svg?token=GC74DPVqhupkfZm2TAsz&branch=master
           :alt: https://travis-ci.com/rehabstudio/fbmessenger.svg?token=GC74DPVqhupkfZm2TAsz&branch=master
        
           https://travis-ci.com/rehabstudio/fbmessenger.svg?token=GC74DPVqhupkfZm2TAsz&branch=master
        
        A python library to communicate with the Facebook Messenger API's
        
        Installation
        ------------
        
        Install from pip
        
        ::
        
            pip install fbmessenger
        
        Facebook app setup
        ------------------
        
        -  `Create a page <https://www.facebook.com/pages/create/>`__ for your
           app, if you don't already have one
        -  `Create an
           app <https://developers.facebook.com/quickstarts/?platform=web>`__
        -  Add the Messenger product
        -  Select the Page to generate a page token
        
        Example usage with Flask
        ------------------------
        
        First you need to create a verify token, this can be any string e.g.
        ``'my_verify_token'``.
        
        Messenger class
        ~~~~~~~~~~~~~~~
        
        We need to extend the ``BaseMessenger`` class and implement methods for
        each of the following subscription fields.
        
        -  ``messages``
        -  ``message_deliveries``
        -  ``messaging_optins``
        -  ``messaging_postbacks``
        
        ::
        
            from fbmessenger import BaseMessenger
        
            class Messenger(BaseMessenger):
                def __init__(self, verify_token, page_access_token):
                    self.verify_token = verify_token
                    self.page_access_token = page_access_token
                    super(BaseMessenger, self).__init__(self.verify_token,
                                                        self.page_access_token)
        
                def messages(self, message):
                    self.send({'text': 'Received: {0}'.format(message['message']['text'])})
        
                def messages_delivered(self, message):
                    pass
        
                def messaging_postbacks(self, messages):
                    pass
        
                def messagin_optins(self, messages):
                    pass
        
        Create a route for the callback url
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        
        This can be used to process any messages received and also to verify
        your app
        
        ::
        
            import os
            from flask import Flask, request
        
            app = Flask(__name__)
        
            messenger = Messenger(os.environ.get('FB_VERIFY_TOKEN'), os.environ.get('FB_PAGE_TOKEN'))
        
            @app.route('/webhook')
            def webhook():
                if request.method == 'GET':
                    return messenger.verify(request.args.get('hub.verify_token'), request.args.get('hub.challenge'))
                elif request.method == 'POST':
                    messenger.handle(request.get_json(force=True))
                return ''
        
            if __name__ == "__main__":
                app.run(host='0.0.0.0')
        
        Elements
        --------
        
        ``from fbmessenger import elements``
        
        Text
        ~~~~
        
        You can pass a simple dict or use the Class
        
        ::
        
            messenger.send({'text': msg})
        
            elem = elements.Text('Your Message')
            messenger.send(elem.to_dict())
        
        Images
        ~~~~~~
        
        ::
        
            image = elements.Image(url='http://example.com/image.jpg')
            messenger.send(image.to_dict())
        
        Web button
        ~~~~~~~~~~
        
        ::
        
            btn = elements.Button(title='Web button', url='http://example.com')
            messenger.send(btn.to_dict())
        
        Payload button
        ~~~~~~~~~~~~~~
        
        To use these buttons you must have the ``message_deliveries``
        subscription enabled
        
        ::
        
            btn = elements.Button(title='Postback button', payload='payload')
            messenger.send(btn.to_dict())
        
        Development Notes
        -----------------
        
        Pydoc should be installed locally to convert the README to
        reStructuredText format for uploading to PyPi
        
Keywords: Facebook Messenger
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
