pford
pford

Reputation: 23

Getting parameters from SMS message

This is basic. I'm pretty new to programming and twilio. I'm simply trying to get the parameter info that Twilio describes here.https://www.twilio.com/docs/sms/twiml#twilios-request-to-your-application

and include it in an sms response back to the user.

Specifically, I'm trying to get two things: (1) the "FromCountry" parameter (2) the message text of what they sent

For (1) I'm trying to pull in the country on line 9, but it always returns "None" from the sms response

I don't know how to begin to do (2)

Here's what I've got

from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse

app = Flask(__name__)

@app.route("/sms", methods=['GET', 'POST'])
def sms_ahoy_reply():

    country = request.args.get('FromCountry')
    
    """Respond to incoming messages with a friendly SMS."""
    # Start our response
    resp = MessagingResponse()

    # Add a message
    resp.message("Your Country: %s" % country)

    return str(resp)

if __name__ == "__main__":
    app.run(debug=True)

Upvotes: 2

Views: 257

Answers (1)

schillingt
schillingt

Reputation: 13731

You can get the body of the message with:

body = request.values.get('Body', None)

I can't find the documentation, but I'd suspect the country would be accessed with

country = request.values.get('FromCountry')

Upvotes: 1

Related Questions