i am building a send and receive sms service with flask and twilio. i still 
have problems sending text


from flask import *
from twilio import twiml
from twilio.rest import TwilioRestClient

from flask import render_template
import os


#Pull in configuration from system environment variables
TWILIO_ACCOUNT_SID = os.environ.get('ACd52bcee874a12b5cdb448cb67c4d81db')
TWILIO_AUTH_TOKEN = os.environ.get('b57d71a0e1b2ff2c9e6a510c04d20019')
TWILIO_NUMBER = os.environ.get('(203) 437-4507')


# create an authenticated client that can make requests to Twilio for your
# account.

#client = TwilioRestClient(account='ACd52bcee874a12b5cdb448cb67c4d81db', 
token='b57d71a0e1b2ff2c9e6a510c04d20019')

#create a flask web app
app = Flask(__name__)

client = TwilioRestClient(account='ACd52bcee874a12b5cdb448cb67c4d81db', 
token='b57d71a0e1b2ff2c9e6a510c04d20019')

@app.route('/')
def homepage():
    """ sending sms """
return render_template('message.html')

#Handling a post request to send text messages.

@app.route('/message', methods=['POST', 'GET'])
def message():
     # Send a text message to the number provided
    #if request.method == 'POST':

    message = client.sms.messages.create(to=request.form['Phone_number'],
                                         from_=TWILIO_NUMBER,
                                         body=request.form['body'])

    return render_template('message.html')

@app.route("/", methods=['GET', 'POST'])
def respond_sms():
    """Responding to sms messages"""
    resp = twilio.twiml.Response()
    if resp == message():
        resp.message("Thanks for the message! We will call you latter.")
    return  str(resp)



if __name__ == '__main__':
    # Note that in production, you would want to disable debugging
    port = int(os.environ.get('PORT', 5000))
    app.run(debug=True)
    app.run(host='0.0.0.0', port=port)



>

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to