I tried to code a simple sms chatbot using Twilio & Flask. The code runs fine, and the console connects, but Twilio doesn't. Some website also said something about ngrok? When I text the Twilio phone number it says, "Thanks for the message. Configure your number's SMS URL to change this message. Cheers, Londo.
try:
from flask import Flask, request
import requests
from twilio.twiml.messaging_response import MessagingResponse
import datetime
except ModuleNotFoundError:
from subprocess import call
modules = ["flask","datetime"]
call("pip install " + ' '.join(modules), shell=True)
app = Flask(__name__)
x = datetime.datetime.now()
@app.route('/bot', methods=['POST'])
def bot():
incoming_msg = request.values.get('Body', '').lower()
resp = MessagingResponse()
msg = resp.message()
responded = False
if 'Hi' in incoming_msg:
msg.body("Hello Londo! *Type: 'Yo*")
responded = True
if 'Yo' in incoming_msg:
msg.body(f'Good morning!, the date is {x.strftime("%X")}. *Type: I am up*')
responded = True
if 'I am up' in incoming_msg:
msg.body('Do 10 pushups and 5 pullups! *Type: Done*')
responded = True
if 'Done' in incoming_msg:
msg.body('Now make the bed. *Type: Ok')
responded = True
if 'Ok' in incoming_msg:
msg.body('Wake TF up!')
responded = True
if not responded:
msg.body('I only respond to certian commands')
return str(resp)
if __name__ == '__main__':
app.run()