forked from pranshukharkwal/ChatBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
28 lines (25 loc) · 729 Bytes
/
server.py
File metadata and controls
28 lines (25 loc) · 729 Bytes
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
from bot import telegram_chatbot
import tensorflow as tf
tf.get_logger().setLevel('ERROR')
import main
bot = telegram_chatbot("config.cfg")
def make_reply(msg):
reply = None
if msg is not None:
print(msg)
reply = main.get_answer(msg)
return reply
update_id = None
while True:
updates = bot.get_updates(offset=update_id)
updates = updates["result"]
if updates:
for item in updates:
update_id = item["update_id"]
try:
message = str(item["message"]["text"])
except:
message = None
from_ = item["message"]["from"]["id"]
reply = make_reply(message)
bot.send_message(reply, from_)