Sample code for 30+ languages & platforms
Ruby 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 Ruby Downloads

Ruby
require 'chilkat'

success = false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
#  Load an API key for the Twilio account from private application configuration.
http = Chilkat::CkHttp.new()
http.put_RequireSslCertVerify(true)
http.put_BasicAuth(true)
http.put_Login("YOUR_API_KEY_SID")
http.put_Password("YOUR_API_KEY_SECRET")

url = Chilkat::CkStringBuilder.new()
url.Append("https://api.twilio.com/2010-04-01/Accounts/")
url.Append("YOUR_ACCOUNT_SID")
url.Append("/Messages")
url.Append("/")
url.Append("YOUR_MESSAGE_SID")
url.Append(".json")
resp = Chilkat::CkHttpResponse.new()
reply = Chilkat::CkJsonObject.new()

success = http.HttpNoBody("GET",url.getAsString(),resp)
if (resp.get_StatusCode() == 0)
    print "No HTTP response from Twilio." + "\n";
    exit
end

parsed = reply.Load(resp.bodyStr())
if ((success != true) or (resp.get_StatusCode() != 200))
    print "Twilio returned HTTP " + resp.get_StatusCode().to_s() + "\n";
    if ((parsed == true) and (reply.JsonTypeOf("code") == 2))
        print "Twilio error: " + reply.IntOf("code").to_s() + "  " + reply.stringOf("message") + "\n";
    end

    exit
end

if (parsed != true)
    print "Expected a JSON response from Twilio." + "\n";
    exit
end

if (reply.JsonTypeOf("status") != 1)
    print "Message status missing from response." + "\n";
    exit
end

print "Delivery status: " + reply.stringOf("status") + "\n";
if ((reply.StringOfEquals("status","failed",true) == true) or (reply.StringOfEquals("status","undelivered",true) == true))
    if (reply.JsonTypeOf("error_code") == 2)
        print "Delivery error code: " + reply.IntOf("error_code").to_s() + "\n";
    end

    if (reply.JsonTypeOf("error_message") == 1)
        print reply.stringOf("error_message") + "\n";
    end

end