Track Delivery Status of Messages in Python

In this guide, we'll show you how to track the delivery status of messages you send with Programmable SMS in your Python web application. Twilio will notify you about the status of your SMS and MMS messages via a webhook and you can notify Twilio about messages you have confirmed to be delivered.

The code snippets in this guide use the Flask web framework and the Twilio Python SDK.

What is a Webhook?

Webhooks are user-defined HTTP callbacks. They are usually triggered by some event, such as receiving an SMS message or an incoming phone call. When that event occurs, Twilio makes an HTTP request (usually a POST or a GET) to the URL configured for the webhook.

To handle a webhook, you only need to build a small web application that can accept the HTTP requests. Almost all server-side programming languages offer some framework for you to do this. Examples across languages include ASP.NET MVC for C#, Servlets and Spark for Java, Express for Node.js, Django and Flask for Python, and Rails and Sinatra for Ruby. PHP has its own web app framework built in, although frameworks like Laravel, Symfony and Yii are also popular.

Whichever framework and language you choose, webhooks function the same for every Twilio application. They will make an HTTP request to a URI that you provide to Twilio. Your application performs whatever logic you feel necessary - read/write from a database, integrate with another API or perform some computation - then replies to Twilio with a TwiML response with the instructions you want Twilio to perform.

Receive Status Events in your Web Application

Statuses for which you can receive notifications include: queuedfailedsentdelivered, and undelivered. For a full description of these and other message statuses, see the API reference.

To get Twilio to call your webhook, you need to provide a URL to your application in the StatusCallback parameter of each message for which you want the status callbacks. Below is an example of how you can specify this parameter. Normally, you would use a URL in your application, but let's use RequestBin so we can debug what Twilio sends your webhook.

Loading Code Samples...
Language
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
from twilio.rest import TwilioRestClient

# put your own credentials here
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "your_auth_token"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

client.messages.create(
    to="+15558675309",
    from_="+15017250604",
    body="McAvoy or Stewart? These timelines can get so confusing.",
    status_callback="http://requestb.in/1234abcd"
)
from twilio.rest import Client

# put your own credentials here
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

client.messages.create(
    to="+15558675309",
    from_="+15017250604",
    body="McAvoy or Stewart? These timelines can get so confusing.",
    status_callback="http://requestb.in/1234abcd"
)
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+16518675309",
  "from": "+14158141829",
  "body": "Hey Jenny! Good luck on the bar exam!",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+16518675309</To>
  <From>+14158141829</From>
  <Body>Hey Jenny! Good luck on the bar exam!</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
Send an SMS with a StatusCallback URL

To get this code sample to run, first fill in your Account SID and Auth Token (found on the Twilio Console dashboard), replace the 'From' phone number with one of your Twilio numbers, and replace the 'To' number with your mobile number. Then, head over to RequestBin and create a new bin. Replace the StatusCallback parameter in the snippet to the URL of your new bin.

When you run the code, you should receive your text message. In addition, you should see at least one request come in to your RequestBin similar to this:

SMS StatusCallback Result in RequestBin

This request shows the MessageStatus of sent. Assuming all was successful, you should see that followed up by another request with a status of delivered (it may take a few minutes to show up).

Once you get the hang of how the StatusCallback works, you're ready to handle the callback in your own application. Below is an example of how you might do this while logging the status for each message.

Loading Code Samples...
Language
SDK Version:
  • 5.x
  • 6.x
from flask import Flask, request
import logging

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

@app.route("/MessageStatus", methods=['POST'])
def incoming_sms():
    message_sid = request.values.get('MessageSid', None)
    message_status = request.values.get('MessageStatus', None)
    logging.info('SID: {}, Status: {}'.format(message_sid, message_status))
    
    return ('', 204)

if __name__ == "__main__":
    app.run(debug=True)
from flask import Flask, request
import logging

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

@app.route("/MessageStatus", methods=['POST'])
def incoming_sms():
    message_sid = request.values.get('MessageSid', None)
    message_status = request.values.get('MessageStatus', None)
    logging.info('SID: {}, Status: {}'.format(message_sid, message_status))

    return ('', 204)

if __name__ == "__main__":
    app.run(debug=True)
Handle a SMS StatusCallback

Getting Status Events for TwiML Generated Messages

When you reply to an incoming message with the <Message> verb, you can also provide an action attribute to specify the URL for your callback webhook. The callback can be the same as those explored in the previous sections.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Message action="http://requestb.in/1234abcd">This message will be tracked!</Message>
</Response>

Provide Message Delivery Feedback to Twilio

The Twilio Message Feedback API enables you to programmatically report back to Twilio critical deliverability information. Actions that indicate a message was received can then be used by Twilio to identify network issues and improve the deliverability of your messages. For example, a user action could be a person entering their two-factor authentication code or clicking a unique link in a message.

NOTE: You must contact our support team to enable the Message Feedback API on your account. Requests to this endpoint will report a 404 Response until you do.

Why do we want this feedback?

We already have many sources of data to optimize overall delivery deliverability. We use direct feedback from our carrier partners, deliverability data from some our larger customers as well as various other monitoring techniques. But nothing trumps the live collective data of our customers. For your messages, we trust what you tell us the most.

By looking at both aggregate data and data specific to your account, we have a better chance at improving the delivery of your messages.

How It Works

Submitting Message Feedback to Twilio is a three step process:

  1. When you send a message, let Twilio know that you are expecting a trackable user action by including the new ProvideFeedback=true parameter in the initial HTTP POST.
  2. Save the Message SID from the POST response. You’ll need this later.
  3. When the user takes the expected action, such as entering a PIN code, let Twilio know the message was received by sending a POST request to the Message Feedback instance subresource with Outcome=confirmed parameter. If the user does not take an action, do not POST anything.

Let's look at some code. First, here's some code that sends a message with a unique URL, setting the ProvideFeedback parameter to true and also saving the Message SID for later recall.

Loading Code Samples...
Language
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
from twilio.rest import TwilioRestClient 
 
# put your own credentials here 
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 
AUTH_TOKEN = "your_auth_token" 
 
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) 
 
# TODO: Confirm passing provide_feedback works
client.messages.create(
    to="+15558675309", 
    from_="+15017250604", 
    body="Open to confirm: http://yourserver.com/confirm?id=1234567890",
    provide_feedback=True
)
from twilio.rest import Client

# put your own credentials here
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

client.messages.create(
        to="+15558675309",
        from_="+15017250604",
        body="Open to confirm: http://yourserver.com/confirm?id=1234567890",
        provide_feedback=True)
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675309",
  "from": "+15017250604",
  "body": "Open to confirm: http://yourserver.com/confirm?id=1234567890",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+15558675309</To>
  <From>+15017250604</From>
  <Body>Open to confirm: http://yourserver.com/confirm?id=1234567890</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
Send an SMS for which to provide Feedback

Next, here's the code we might run when the user clicks the unique URL. We use the requests Python library to help us send the request..

Based on the unique URL, we know the Message SID and can report back to Twilio that the message was successfully delivered.

Loading Code Samples...
Language
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
from flask import Flask, request
from requests.auth import HTTPBasicAuth

import logging
import requests

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

# Get your Account Sid and Auth Token from twilio.com/console
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "your_auth_token"

@app.route("/confirm", methods=['GET'])
def incoming_sms():
    unique_id = request.values.get('id', None)
    # Use a unique id associated with your user to figure out the Message Sid
    # of the message that prompted this action
    message_sid = 'SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    
    # Build the URL we need to report feedback
    url = 'https://api.twilio.com/2010-04-01/Accounts/{}/Messages/{}/Feedback.json' \
        .format(ACCOUNT_SID, message_sid)

    # Send a POST request to the URL confirming that your user received
    # the text message Twilio sent them
    response = requests.post(
        url,
        data={'Outcome': 'confirmed'},
        auth=HTTPBasicAuth(ACCOUNT_SID, AUTH_TOKEN))
    
    return ('Done!', 200)

if __name__ == "__main__":
    app.run(debug=True)
from flask import Flask, request
from requests.auth import HTTPBasicAuth

import logging
import requests

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

@app.route("/confirm", methods=['GET'])
def incoming_sms():
    unique_id = request.values.get('id', None)

    # Use a unique id associated with your user to figure out the Message Sid
    # of the message that prompted this action
    message_sid = 'SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

    # Get your Account Sid and Auth Token from twilio.com/console
    account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    auth_token = "your_auth_token"


    client = Client(account_sid, auth_token)
    client.messages(message_sid) \
          .feedback
          .create(outcome="confirmed")

    return ('Thank you!', 200)

if __name__ == "__main__":
    app.run(debug=True)
{
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"message_sid": "SM6d4d807e10f24d83a1ab01da10ccc0f5",
	"outcome": "confirmed",
	"date_created": "Fri, 02 Sep 2016 18:19:59 +0000",
	"date_updated": "Fri, 02 Sep 2016 18:42:40 +0000",
	"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback.json"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
  <Feedback>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <MessageSid>SM6d4d807e10f24d83a1ab01da10ccc0f5</MessageSid>
    <Outcome>confirmed</Outcome>
    <DateCreated>Fri, 02 Sep 2016 18:19:59 +0000</DateCreated>
    <DateUpdated>Fri, 02 Sep 2016 18:46:58 +0000</DateUpdated>
    <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback</Uri>
  </Feedback>
</TwilioResponse>
Send Delivery Confirmation Feedback

Examples of Trackable User Actions 

Examples of user actions include:

  •      A user receives a passcode via SMS and enters it into a web site or app
  •      A user enters a temporary password.
  •      A user replies to a message with a call or SMS.
  •      A user clicks on a unique link contained in the message.

Once a user takes an action, you know for certain that they received the message. This information is submitted to Twilio, and we take care of the rest.

Andrew Baker
David Prothero
Paul Kamp

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
from twilio.rest import TwilioRestClient

# put your own credentials here
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "your_auth_token"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

client.messages.create(
    to="+15558675309",
    from_="+15017250604",
    body="McAvoy or Stewart? These timelines can get so confusing.",
    status_callback="http://requestb.in/1234abcd"
)
from twilio.rest import Client

# put your own credentials here
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

client.messages.create(
    to="+15558675309",
    from_="+15017250604",
    body="McAvoy or Stewart? These timelines can get so confusing.",
    status_callback="http://requestb.in/1234abcd"
)
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+16518675309",
  "from": "+14158141829",
  "body": "Hey Jenny! Good luck on the bar exam!",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+16518675309</To>
  <From>+14158141829</From>
  <Body>Hey Jenny! Good luck on the bar exam!</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
SDK Version:
  • 5.x
  • 6.x
from flask import Flask, request
import logging

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

@app.route("/MessageStatus", methods=['POST'])
def incoming_sms():
    message_sid = request.values.get('MessageSid', None)
    message_status = request.values.get('MessageStatus', None)
    logging.info('SID: {}, Status: {}'.format(message_sid, message_status))
    
    return ('', 204)

if __name__ == "__main__":
    app.run(debug=True)
from flask import Flask, request
import logging

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

@app.route("/MessageStatus", methods=['POST'])
def incoming_sms():
    message_sid = request.values.get('MessageSid', None)
    message_status = request.values.get('MessageStatus', None)
    logging.info('SID: {}, Status: {}'.format(message_sid, message_status))

    return ('', 204)

if __name__ == "__main__":
    app.run(debug=True)
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
from twilio.rest import TwilioRestClient 
 
# put your own credentials here 
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 
AUTH_TOKEN = "your_auth_token" 
 
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) 
 
# TODO: Confirm passing provide_feedback works
client.messages.create(
    to="+15558675309", 
    from_="+15017250604", 
    body="Open to confirm: http://yourserver.com/confirm?id=1234567890",
    provide_feedback=True
)
from twilio.rest import Client

# put your own credentials here
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"

client = Client(account_sid, auth_token)

client.messages.create(
        to="+15558675309",
        from_="+15017250604",
        body="Open to confirm: http://yourserver.com/confirm?id=1234567890",
        provide_feedback=True)
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675309",
  "from": "+15017250604",
  "body": "Open to confirm: http://yourserver.com/confirm?id=1234567890",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+15558675309</To>
  <From>+15017250604</From>
  <Body>Open to confirm: http://yourserver.com/confirm?id=1234567890</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
SDK Version:
  • 5.x
  • 6.x
Format:
  • JSON
  • XML
from flask import Flask, request
from requests.auth import HTTPBasicAuth

import logging
import requests

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

# Get your Account Sid and Auth Token from twilio.com/console
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "your_auth_token"

@app.route("/confirm", methods=['GET'])
def incoming_sms():
    unique_id = request.values.get('id', None)
    # Use a unique id associated with your user to figure out the Message Sid
    # of the message that prompted this action
    message_sid = 'SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    
    # Build the URL we need to report feedback
    url = 'https://api.twilio.com/2010-04-01/Accounts/{}/Messages/{}/Feedback.json' \
        .format(ACCOUNT_SID, message_sid)

    # Send a POST request to the URL confirming that your user received
    # the text message Twilio sent them
    response = requests.post(
        url,
        data={'Outcome': 'confirmed'},
        auth=HTTPBasicAuth(ACCOUNT_SID, AUTH_TOKEN))
    
    return ('Done!', 200)

if __name__ == "__main__":
    app.run(debug=True)
from flask import Flask, request
from requests.auth import HTTPBasicAuth

import logging
import requests

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)

@app.route("/confirm", methods=['GET'])
def incoming_sms():
    unique_id = request.values.get('id', None)

    # Use a unique id associated with your user to figure out the Message Sid
    # of the message that prompted this action
    message_sid = 'SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

    # Get your Account Sid and Auth Token from twilio.com/console
    account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    auth_token = "your_auth_token"


    client = Client(account_sid, auth_token)
    client.messages(message_sid) \
          .feedback
          .create(outcome="confirmed")

    return ('Thank you!', 200)

if __name__ == "__main__":
    app.run(debug=True)
{
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"message_sid": "SM6d4d807e10f24d83a1ab01da10ccc0f5",
	"outcome": "confirmed",
	"date_created": "Fri, 02 Sep 2016 18:19:59 +0000",
	"date_updated": "Fri, 02 Sep 2016 18:42:40 +0000",
	"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback.json"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
  <Feedback>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <MessageSid>SM6d4d807e10f24d83a1ab01da10ccc0f5</MessageSid>
    <Outcome>confirmed</Outcome>
    <DateCreated>Fri, 02 Sep 2016 18:19:59 +0000</DateCreated>
    <DateUpdated>Fri, 02 Sep 2016 18:46:58 +0000</DateUpdated>
    <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM6d4d807e10f24d83a1ab01da10ccc0f5/Feedback</Uri>
  </Feedback>
</TwilioResponse>