A telegram bot based on a finite state machine
This telegram bot contains three features:
- Search for uniform-invoice prize winning numbers
- Search for newest articles in PTT website
- Search for vocabulary in English-Chinese(Traditional) dictionary
- Python 3
Simply use pip3
command to install from the requirements file
pip3 install -r requirements.txt
Below is the list of required packages:
- Flask
- transitions
- pygraphviz (For visualizing Finite State Machine)
- python-telegram-bot
- requests (For HTTP requests)
- beautifulsoup4 (For pulling out data from HTML files)
API_TOKEN
and WEBHOOK_URL
in app.py MUST be set to proper values.
Otherwise, you might not be able to run your code.
You can get API_TOKEN
from @botfather (web link)
You can either setup https server or using ngrok
as a proxy.
ngrok
would be used in the following instruction
(or run the executable file with same arguments)
ngrok http 5000
After that, ngrok
would generate a https URL.
You should set WEBHOOK_URL
(line 11 in app.py) to your-https-URL/hook
.
python3 app.py
The initial state is set to init
.
There has three branches leave from init
. These branches correspond to different features memtioned above.
If the user entered "1", "2" or "3", init
is triggered to advance
to the corresponding state, and telegram bot will ask for more details in order to retrive data the user want
Finally, if the result has sent to the user, states will go_back
to init
state
Sequence of actions started from typing "1" at init
state
Sequence of actions started from typing "2" at init
state
Sequence of actions started from typing "3" at init
state
The project template is provided by Lee-W