Lua Requires Chilkat v11.0.0+
Lua
Clickatell One API: Look up SMS delivery status
See more Clickatell Examples
Use the apiMessageId returned by the One API send example and the same integration key. The ID goes in the URL path. The SMS result contains sms.status and the timestamp of the last status change. For example, QUEUED means processing is pending and DEVICE_ACK indicates a device acknowledgment.
The response can also contain a WhatsApp result or have no identifiable channel for an unknown message. For ongoing delivery updates, configure delivery notifications in the integration. This example performs one lookup.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local http = chilkat.Http.new()
http.require_ssl_cert_verify = true
-- Supply the key for this One API integration from application configuration.
http:set_request_header("Authorization", "ONE_API_KEY")
http:set_request_header("Accept", "application/json")
-- Use the provider-generated ID from an accepted One API send.
http:set_url_var("id", "ONE_API_MESSAGE_ID")
local resp = chilkat.HttpResponse.new()
local success = http:http_no_body("GET", "https://platform.clickatell.com/v1/message/{$id}", resp)
if resp.status_code == 0 then
print("No HTTP response. Check the connection and retry the lookup.")
return
end
local reply = chilkat.JsonObject.new()
local parsed = reply:load(resp.body_str)
if (not success) or ((resp.status_code ~= 200)) then
print("Clickatell returned HTTP " .. resp.status_code)
if parsed then
if reply:has_member("error.description") then
print(reply:string_of("error.description"))
end
end
return
end
if not parsed then
print("Expected a JSON response.")
return
end
-- A known SMS has a string status under the sms member.
if reply:json_type_of("sms.status") ~= 1 then
if reply:json_type_of("whatsapp.status") == 1 then
print("This message has WhatsApp status: " .. reply:string_of("whatsapp.status"))
else
print("No SMS status was returned. Check the message ID and integration.")
if reply:json_type_of("status") == 1 then
print("Reported status: " .. reply:string_of("status"))
end
end
return
end
print("SMS status: " .. reply:string_of("sms.status"))
if reply:json_type_of("sms.timestamp") == 2 then
-- Read the provider timestamp as text to preserve every digit.
print("Last status change (provider timestamp): " .. reply:string_of("sms.timestamp"))
end