I have a Whatsapp bot written in python and flask with Twilio as the Messaging API. The app was working fine until I noticed that responses sent from the app are not being delivered. Twilio however is still routing messages to my app correctly but whatsapp messages sent from my flask app to the whatsapp are not being delivered. Is there a problem going on with Twilio? Is anyone facing the same problem.
My code looks similar to this.
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 and cats, sorry!')
return str(resp)
if __name__ == '__main__':
app.run()
I faced the same problem.Just downloading and adding ngrok to the path is not gonna work. You need to sign up for ngrok and then connect your account (authenticate) to the installed ngrok in your os . You will get the steps in the ngrok dashboard once you sign in.[1]:
For tutorial, refer to this video -> (from 9.03) https://www.youtube.com/watch?v=hW3zfd0mIfw&ab_channel=pyGuru
The ngrok execution on the terminal should like this after authentication.