-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpa.py
30 lines (25 loc) · 791 Bytes
/
pa.py
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
import telepot, time
from nltk.chat.iesha import iesha_chatbot
is_chatting = False
def handle(msg):
global is_chatting
chat_id = msg['chat']['id']
command = msg['text']
print 'Got command: %s' % command
if command == '/hello':
bot.sendMessage(chat_id, "Hello, how are you?")
if command == '/chat':
is_chatting = True
bot.sendMessage(chat_id, 'Hi I am Iesha. Who are You?')
elif command == '/stopchat':
is_chatting = False
bot.sendMessage(chat_id, 'Bye Bye. take care!')
elif not command.startswith('/') and is_chatting:
bot.sendMessage(chat_id, iesha_chatbot.respond(command))
else:
pass
# Insert API
bot = telepot.Bot('API your bot')
bot.notifyOnMessage(handle)
while 1:
time.sleep(10)