Flask based HTTP application to consume / provide data to a real time Facebook Messenger chat bot.
The project is up and running for demo purposes: ProjectDemo
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Linux system: Ubuntu 16.04 (Xenial) or later
python 3.5
pip
Clone source code from git repo
$ git clone https://github.com/fernandorovai/Messenger-ChatBOT
Setup and activate virtual environment
$ virtualenv Messenger-ChatBOT -p python3
$ cd Messenger-ChatBOT
$ source ./bin/activate
Install python dependencies via pip
$ pip install -r requirements.txt
Start the webserver
Facebook requires ssl certificate.
Setup ssl credentials in context variable (server.py):
context = ('/path/fullchain.pem',
'/path/privkey.pem')
obs: if your credentials are in root dir, you may have to install the dependencies also using root
$ cd Messenger-ChatBOT
$ python3 server.py or sudo python3 server.py
Expected output
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
- sendCarouselMsg(sender_id, elements)
# elements structure
elements = [
{'subtitle': 'Price or a subtitle',
'buttons': [{'url': 'url', 'type': 'web_url', 'title': 'Ver Detalhes'}],
'image_url': 'imageUrl',
'title': 'Product Title'},
{...}
]
- sendQuickReply(sender_id, quickReplies)
quickReplies = [{"content_type": "text","title": "Lustres","payload": "lustres"},
{"content_type": "text","title": "Embutidos","payload": "embutidos"},
{"content_type": "text","title": "Ir para Categorias","payload": "categorias"}]
- sendTypingBubble(sender_id)
- getPersonInfo(sender_id)
- callSendAPI(sender_id, {"text": "yourText"})
This bot uses pre-defined keywords to chat. These keywords are found in keywords.py file. In order to advance its intelligence, consider using RNN (Recurrent Neural Networks).
The file data.py holds all products offered by the bot. All products information belongs to HunterTrade company that authorized the usage for this demonstration. Consider retrieving information from database / API.
Flask’s built-in server is not suitable for production. Consider deploying the application to a WSGI Server. For more information, check Flask Documentation
- Fernando Rodrigues Jr - Initial work - Fernando