-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
53 lines (46 loc) · 2 KB
/
bot.py
File metadata and controls
53 lines (46 loc) · 2 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
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, request
from utils import *
import requests
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
greetings = ['ola', 'tudo bem', 'oi', 'hello', 'welcome', 'bem vindo', 'blz', 'eaew', 'e aí', 'como esta', 'boa', 'tarde', 'noite', 'bom dia']
goodbyes = ['tchau', 'flw', 'embora', 'bye', 'adeus', 'goodbye', 'xau', 'fui', 'indo']
laughs = ['kk', 'asuah', 'hasuah', 'rsrs', 'lol', 'apoaks' ]
getout_try = ['o outro', 'outro cachorro', 'a outra', 'outra cachorra']
@app.route('/bot', methods=['POST'])
def bot():
incoming_msg = request.values.get('Body', '')
incoming_msg = normalize_words(incoming_msg)
resp = MessagingResponse()
msg = resp.message()
send_dog_image = False
history = 'É a história de dois cachorros: Pete e Repete. Pete morreu, quem ficou vivo?'
intro = 'Legal o que você falou. Agora eu tenho uma historia...\n'
if any(word in incoming_msg for word in greetings):
send_dog_image = True
intro = 'Olá! Vou lhe contar uma história...\n'
elif any(word in incoming_msg for word in goodbyes):
send_dog_image = True
intro = 'Antes de você ir, gostaria de contar uma história...\n'
elif any(word in incoming_msg for word in getout_try):
intro = 'Qual o nome do outro cachorro?'
history = ''
elif any(word in incoming_msg for word in laughs):
send_dog_image = True
intro = 'Engraçado kkk, mas você já viu essa história?\n'
elif 'repete' in incoming_msg or 'repeti' in incoming_msg or 'nao sei' in incoming_msg:
intro = ''
elif 'pete' in incoming_msg:
intro = 'Resposta errada! Vou explicar de novo...\n'
else:
send_dog_image = True
if(send_dog_image):
r = requests.get('https://dog.ceo/api/breeds/image/random')
data = r.json()
dog_image = data['message']
msg.media(dog_image)
msg.body(intro)
msg.body(history)
return str(resp)
if __name__ == '__main__':
app.run()