-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
50 lines (39 loc) · 1.57 KB
/
bot.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from flask import Flask, request
import requests
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
@app.route('/bot', methods=['POST'])
def bot():
incoming_msg = request.values.get('Body', '').lower()
resp = MessagingResponse()
msg = resp.message()
responded = False
if 'quote' in incoming_msg:
# return a quote
r = requests.get('https://api.quotable.io/random')
if r.status_code == 200:
data = r.json()
quote = f'{data["content"]} ({data["author"]})'
else:
quote = 'I could not retrieve a quote at this time. Sorry!'
msg.body(quote)
responded = True
if 'cat' in incoming_msg:
# return a cat pic
msg.media('https://cataas.com/cat')
responded = True
#if not responded:
# msg.body('I only know about famous quotes, cute cats and dogs. Sorry!')
if 'dog' in incoming_msg:
# return a dog pic
msg.media('https://images.dog.ceo/breeds/frise-bichon/7.jpg')
responded = True
#if not responded:
# msg.body('I only know about famous quotes, cute cats and dogs. Sorry!')
if 'hello' in incoming_msg:
msg.body('Hello! I am Moody! I know about famous quotes, cute cats and dogs. What do you want to see?')
if 'hi' in incoming_msg:
msg.body('Hello! I am Moody! I know about famous quotes, cute cats and dogs. What do you want to see?')
return str(resp)
if __name__ == '__main__':
app.run()