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

Lua
local chilkat = require("chilkat")

-- Assumes Chilkat is unlocked. See Global Unlock Sample.
-- Load an API key for the Twilio account from private application configuration.
local http = chilkat.Http.new()
http.require_ssl_cert_verify = true
http.basic_auth = true
http.login = "YOUR_API_KEY_SID"
http.password = "YOUR_API_KEY_SECRET"

local url = chilkat.StringBuilder.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")
local resp = chilkat.HttpResponse.new()
local reply = chilkat.JsonObject.new()

local success = http:http_no_body("GET", url:get_as_string(), resp)
if resp.status_code == 0 then
    print("No HTTP response from Twilio.")
    return
end

local parsed = reply:load(resp.body_str)
if (not success) or (resp.status_code ~= 200) then
    print("Twilio returned HTTP " .. resp.status_code)
    if (parsed) and (reply:json_type_of("code") == 2) then
        print("Twilio error: " .. reply:int_of("code") .. "  " .. reply:string_of("message"))
    end

    return
end

if not parsed then
    print("Expected a JSON response from Twilio.")
    return
end

if reply:json_type_of("status") ~= 1 then
    print("Message status missing from response.")
    return
end

print("Delivery status: " .. reply:string_of("status"))
if (reply:string_of_equals("status", "failed", true)) or (reply:string_of_equals("status", "undelivered", true)) then
    if reply:json_type_of("error_code") == 2 then
        print("Delivery error code: " .. reply:int_of("error_code"))
    end

    if reply:json_type_of("error_message") == 1 then
        print(reply:string_of("error_message"))
    end
end