Facebook Chatbot Application Using Python
Chatbot
Python
Webhook
Facebook Messenger
RNN
Generation Based
Sequence to Sequence
LSTM
Chatterbot
Rule Based
Task-Specific
- Introduction
- Hybrid Approach
- System Structure
- Environment
- Author
- Function
- Screenshots
- Installation
- Contact
- License
Important Notice: This project mix some different other project. You may find that the code is extremely messy. Do not expect learning something from here. Thank You!
The trained model file is oversized. If you want to try this program, you have to download my trained model file from ... nowhere, contact me please.
Our chatbot can reply in real time and it supports multi-lingual conversation (both Chinese and English).
Our system returns a response using generation-based and rule-based ensemble approaches. Our system is ensembled by two sequence-to-sequence models, one trained by Chinese corpus and another one trained by English corpus. We combined the two sequence-to-sequence models together with the Chatterbot model. The system will check the user input first, if it matches one of the rules we defined, the predefined response will be shown, this is task-specificed framed based system. Otherwise, the user input will be passed into one of the generation-based models we trained or the chatterbot for getting response from one of two system.
Our chatbot can chat freely with users as well as complete tasks like booking a cinema ticket. When the input message is detected to have the keywords “book” and “movie” or "ticket", it will trigger to make the booking cinema ticket services. After then, our chatbot will generate the booking reference number, and ask the related booking ticket contents including name, booking film, booking date and seat No. Finally, the booking information will be saved in to a text file called cinema_book.txt
and generate a confirmation message to user and ask for confirm.
The chatbot also includes functions like replying by using emojis and telling jokes as well as perform simple calculations.
- Generation based - (Sequence to Sequence)
- Rule based – Chatterbot
- Task-Specific Approach – Frame based
- Additional Functions – Customized
- How to Host a Python and Flask Facebook Messenger Bot on Heroku - the project is greater than 2G, cannot use heroku
- Chatterbot Official Website - Rule Based Chatbot
- ChatLearner - English Sequence to Sequence Chatbot
- just_another_seq2seq - Chinese Sequence to Sequence Chatbot
System Flow Chart
Chatbot Tech Stack
Dataflow between User and Chatbot
Chatterbot and S2S switching (Now is random)
- Python: 3.6.7
- pip: 18.1
- Flask
- Jieba
- NLTK
- Hanziconv
- Chatterbot
- Tensorflow: 1.7.0
- Generation based (Sequence to Sequence)
- Chinese chit-chat
- English chit-chat
- Rule based (Chatterbot)
- Chinese chit-chat
- English chit-chat
- Confidence evaluation
- Task-specific Approach (Frame based)
- Booking services for movies
- Additional functions (Chinese and English)
- Emoji response
- Telling Joke
- Simple calculation
- Provide date and time
- Prevent repetitive response
- Traditional Chinese compatible
- Chinese conversation corpus
- Cleaned reddit data
- Papaya dataset
- Cleaned Cornell movie dialogs
- Chatterbot dataset (Simplified Chinese & traditional Chinese)
- Chatterbot dataset (English)
Feature:
- Time checking
- Replying by emoji
- Telling jokes
- Simple calculations
- Chinese chit-chat
- Questions to check and confirm user intent and Framed based Template
- English Chitchat Template using Facebook API
- Repetitive Detection
- English chit-chat
$ git clone git@github.com:tavik000/python-key-chatbot.git
Download basic.data-00000-of-00001
and chatbot.pkl
from me (Contact me) tavik002@gmail.com.
locate model file basic.data-00000-of-00001
to "./Hybrid/chatbot/Data/Result/"
locate chatbot.pkl
to "./Hybrid/chatbot/"
Check this link to build up a Facebook Messenger Chatbot. You don't need to build up the server, it's already in this program
How to Host a Python and Flask Facebook Messenger Bot on Heroku - in this case, heroku are not applied.
Go to "./Hybrid/chatbot/", modify test_hybrid.py
file, change ACCESS_TOKEN (line 197) to your Facebook Page token generated in Facebook App (Follow the instruction No.4 then you will know what I mean) and set your own VERIFY_TOKEN (line 198) whatever you like
Go to project root folder python-key-chatbot
and set up your own server config base on your situation
$ python3 app.py
To run the python server
Go to Facebook for developer website and set up your Webhook, put your server url (you can use a real server or using tools such as ngrok or localtunnel for boardcast your localhost to Internet and get an url) and VERIFY_TOKEN in the textholder.
You are ready to go, test your chatbot by sending it message in Facebook Messenger.
If you like this, please leave a star.
Email: Key tavik002@gmail.com
MIT License
Copyright (c) 2018 key
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All Copyright Reserved