I am trying to create a connection to whatsapp and my python script via Twilio, to generate automatic conversations. I follow every step in order of this link https://www.pragnakalp.com/create-whatsapp-bot-with-twilio-using-python-tutorial-with-examples/?unapproved=4864&moderation-hash=3861b2bc00104a39b5f3211076dda854#comment-4864
I started with a problem of ngrok http 5000 that said "POST/ 403 Forbidden", in the section of https requests. But now it dissapeared, which I guess is because I add in the command vi "path of ngyrok" a different web address. The reason what I did this is because I was realizing that putting a different port of my localhost to connect the web server for twilio is not compatible. In other words, the connection was not going to the final destinary, which is Twilio. Despite of all these changes, the port of local host is still appearing 4040, as in the following image I show:
When I activate the connection for my whatsapp number, and save the forwarding url of ngrok in twilio, as I said before, it dissapears the warning "POST/ 403 Forbidden", instead it is appearing nothing:
I found that adding in the forwarding url the /message
Twilio receives my request and it answers me, but is not the case, and that´s why you can see in the https request the POST /message
Before sending the message to the bot I run my python script:
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
#@app.route("/wa")
#def wa_hello():
# return "Hello, World!"
@app.route("/wasms", methods=['POST'])
def wa_sms_reply():
"""Respond to incoming calls with a simple text message."""
# Fetch the message
msg = request.form.get('Body').lower() # Reading the message from the whatsapp
print("msg-->", msg)
resp = MessagingResponse()
reply = resp.message()
# Create reply
if msg == "hi":
reply.body("hello!")
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
I tried running commands like ngrok http https://localhost:5000
, turning off firewalls on my Mac, allowing my country on the Twilio´s web page, inserting config.hosts << /.*.ngrok.io/ in my terminal and restaring my laptop, config.hosts << "a0000000.ngrok.io" and skip_before_action :verify_authenticity_token but nothing of this work for me. Does anyone knows what is the problem?