Also in ngrok, there appears an internal server error 500 when attempting to make a post request using twilio.
Here is the section of my code where I feel there is a problem with:
from flask import Flask, request
from twilio import twiml
import wolframalpha
import wikipedia
app = Flask(__name__)
wolf = wolframalpha.Client(wolfram_app_id)
@app.route('/', methods=['POST'])
def sms():
message_body = request.form['Body']
resp = twiml.Response()
replyText = getReply(message_body)
resp.message('Hi\n\n' + replyText )
return str(resp)
I have updated all latest versions of ngrok, python, twilio and Flask. I also followed all the steps to activate the virtualenv.
Twilio developer evangelist here.
If you are using the latest version of the Twilio Python module then there is no Response
method. Instead, since you are replying to a message, you need to use the MessagingResponse
instead.
Try the following:
from flask import Flask, request
from twilio.twiml.messaging_response import Message, MessagingResponse
import wolframalpha
import wikipedia
app = Flask(__name__)
wolf = wolframalpha.Client(wolfram_app_id)
@app.route('/', methods=['POST'])
def sms():
message_body = request.form['Body']
resp = MessagingResponse()
replyText = getReply(message_body)
resp.message('Hi\n\n' + replyText )
return str(resp)
This code is been using Flask for sending message
For installing use:
* pip install flask
* pip install twilio
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
@app.route("/sms", methods =['POST'])
def sms():
number = request.form['From']
message_body = request.form['Body']
resp = MessagingResponse()
response_message = 'Hello {}, You said:{}'.format(number, message_body)
resp.message(response_message)
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With