B4X Requires Chilkat v11.0.0+
B4X
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.
Chilkat B4X Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
' Load an API key for the Twilio account from private application configuration.
Dim http As ChilkatHttp
http.Initialize("http")
http.RequireSslCertVerify = True
http.BasicAuth = True
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
Dim url As ChilkatStringBuilder
url.Initialize
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")
Dim resp As ChilkatHttpResponse
resp.Initialize
Dim reply As ChilkatJsonObject
reply.Initialize
success = http.HttpNoBody("GET", url.GetAsString, resp)
If resp.StatusCode = 0 Then
Log("No HTTP response from Twilio.")
Return
End If
Dim parsed As Boolean = reply.Load(resp.BodyStr)
If (success <> True) Or (resp.StatusCode <> 200) Then
Log("Twilio returned HTTP " & resp.StatusCode)
If (parsed = True) And (reply.JsonTypeOf("code") = 2) Then
Log("Twilio error: " & reply.IntOf("code") & " " & reply.StringOf("message"))
End If
Return
End If
If parsed <> True Then
Log("Expected a JSON response from Twilio.")
Return
End If
If reply.JsonTypeOf("status") <> 1 Then
Log("Message status missing from response.")
Return
End If
Log("Delivery status: " & reply.StringOf("status"))
If (reply.StringOfEquals("status", "failed", True) = True) Or (reply.StringOfEquals("status", "undelivered", True) = True) Then
If reply.JsonTypeOf("error_code") = 2 Then
Log("Delivery error code: " & reply.IntOf("error_code"))
End If
If reply.JsonTypeOf("error_message") = 1 Then
Log(reply.StringOf("error_message"))
End If
End If