A telegram bot based on a finite state machine.
- Python 3
pip install -r requirements.txt
- pygraphviz (For visualizing Finite State Machine)
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 either setup https server or using ngrok
as a proxy.
ngrok
would be used in the following instruction
ngrok http 5000
After that, ngrok
would generate a https URL.
You should set WEBHOOK_URL
(in app.py) to your-https-URL/hook
.
python3 app.py
The initial state when chatting is set to user
.
Moreover, I designed an actual initial state init
that accepts any input text to enter user
state, in order to wake up the chatbot.
So you can simply wake the chatbot up by sending anythins like Hello!
, 嗨~
.
Assume we're now in user
state. Next, my bot will prompt a welcome message.
After that, user can input +1
, +2
, +3
to chat with the bot.
Let's talk about the function of +2
first, which is also the primary function of the bot.
It's for fortune analysis based on constellation and Chinese zodiac/animal sign. User can choose one of the both when chatting with the bot.
I write a crawler to parse the fortune analysis website to get the corresponding response for different user. Also use reply_photo()
to interact
with the users.
As for the function of +1
or +3
in user
state, User can interact with the bot for fun.