Sample code for 30+ languages & platforms
Tcl Requires Chilkat v11.0.0+

Check message delivery status with Twilio

See more Twilio Examples

Fetch an outbound SMS or MMS using the Message SID returned by a live send. A queued message is waiting to be sent. A sent message has been accepted by the upstream carrier. Delivered means Twilio received delivery confirmation. Some routes provide no final delivery receipt.

Read the current status once per lookup. For failed or undelivered messages, display the available delivery error code and text for troubleshooting. A missing message or an HTTP authentication error is a separate result from a delivery failure.

Twilio documentation

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
#  Load an API key for the Twilio account from private application configuration.
set http [new_CkHttp]

CkHttp_put_RequireSslCertVerify $http 1
CkHttp_put_BasicAuth $http 1
CkHttp_put_Login $http "YOUR_API_KEY_SID"
CkHttp_put_Password $http "YOUR_API_KEY_SECRET"

set url [new_CkStringBuilder]

CkStringBuilder_Append $url "https://api.twilio.com/2010-04-01/Accounts/"
CkStringBuilder_Append $url "YOUR_ACCOUNT_SID"
CkStringBuilder_Append $url "/Messages"
CkStringBuilder_Append $url "/"
CkStringBuilder_Append $url "YOUR_MESSAGE_SID"
CkStringBuilder_Append $url ".json"
set resp [new_CkHttpResponse]

set reply [new_CkJsonObject]

set success [CkHttp_HttpNoBody $http "GET" [CkStringBuilder_getAsString $url] $resp]
if {[CkHttpResponse_get_StatusCode $resp] == 0} then {
    puts "No HTTP response from Twilio."
    delete_CkHttp $http
    delete_CkStringBuilder $url
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

set parsed [CkJsonObject_Load $reply [CkHttpResponse_bodyStr $resp]]
if {expr [$success != 1]  ||  [[CkHttpResponse_get_StatusCode $resp] != 200]} then {
    puts "Twilio returned HTTP [CkHttpResponse_get_StatusCode $resp]"
    if {expr [$parsed == 1]  &&  [[CkJsonObject_JsonTypeOf $reply "code"] == 2]} then {
        puts "Twilio error: [CkJsonObject_IntOf $reply code]  [CkJsonObject_stringOf $reply message]"
    }

    delete_CkHttp $http
    delete_CkStringBuilder $url
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

if {$parsed != 1} then {
    puts "Expected a JSON response from Twilio."
    delete_CkHttp $http
    delete_CkStringBuilder $url
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

if {[CkJsonObject_JsonTypeOf $reply "status"] != 1} then {
    puts "Message status missing from response."
    delete_CkHttp $http
    delete_CkStringBuilder $url
    delete_CkHttpResponse $resp
    delete_CkJsonObject $reply
    exit
}

puts "Delivery status: [CkJsonObject_stringOf $reply status]"
if {expr [[CkJsonObject_StringOfEquals $reply "status" "failed" 1] == 1]  ||  [[CkJsonObject_StringOfEquals $reply "status" "undelivered" 1] == 1]} then {
    if {[CkJsonObject_JsonTypeOf $reply "error_code"] == 2} then {
        puts "Delivery error code: [CkJsonObject_IntOf $reply error_code]"
    }

    if {[CkJsonObject_JsonTypeOf $reply "error_message"] == 1} then {
        puts [CkJsonObject_stringOf $reply error_message]
    }

}


delete_CkHttp $http
delete_CkStringBuilder $url
delete_CkHttpResponse $resp
delete_CkJsonObject $reply