forked from kercos/ExamplesPythonTelegramBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_01_simple.py
More file actions
40 lines (33 loc) · 1.28 KB
/
ex_01_simple.py
File metadata and controls
40 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
import bot_manager
from bot_manager import (send_message, send_photo, send_location,
direct_user_to_state, repeatState, set_user_var_value, get_user_var_value)
##############################
# STATES FUNCTIONS
# * each function's name has to start with 'state_X' where X is the name of the state
# * each function is split in two parts:
# - if bot_turn: bot's turn to say something
# - else: the user said something
##############################
def state_0(user, message):
"""
state 0 is the initial state by default (see bot_manager) and must be defined
This is where the bot sends the user after s/he starts the bot (or types the command /start)
"""
bot_turn = message is None
if bot_turn:
reply_text = 'You are in the initial state'
send_message(user, reply_text)
else:
if message.text:
input_text = message.text
reply_text = "Hi, {} you said: {}".format(user.first_name, input_text)
send_message(user, reply_text)
else:
reply_text = "You sent me something which I cannot handle."
send_message(user, reply_text)
##############################
# MAIN
##############################
if __name__ == '__main__':
bot_manager.startBot()