Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
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 Delphi ActiveX Downloads
var
success: Integer;
http: TChilkatHttp;
url: TChilkatStringBuilder;
resp: TChilkatHttpResponse;
reply: TChilkatJsonObject;
parsed: Integer;
begin
success := 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Load an API key for the Twilio account from private application configuration.
http := TChilkatHttp.Create(Self);
http.RequireSslCertVerify := 1;
http.BasicAuth := 1;
http.Login := 'YOUR_API_KEY_SID';
http.Password := 'YOUR_API_KEY_SECRET';
url := TChilkatStringBuilder.Create(Self);
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 := TChilkatHttpResponse.Create(Self);
reply := TChilkatJsonObject.Create(Self);
success := http.HttpNoBody('GET',url.GetAsString(),resp.ControlInterface);
if (resp.StatusCode = 0) then
begin
Memo1.Lines.Add('No HTTP response from Twilio.');
Exit;
end;
parsed := reply.Load(resp.BodyStr);
if ((success <> 1) or (resp.StatusCode <> 200)) then
begin
Memo1.Lines.Add('Twilio returned HTTP ' + IntToStr(resp.StatusCode));
if ((parsed = 1) and (reply.JsonTypeOf('code') = 2)) then
begin
Memo1.Lines.Add('Twilio error: ' + IntToStr(reply.IntOf('code')) + ' ' + reply.StringOf('message'));
end;
Exit;
end;
if (parsed <> 1) then
begin
Memo1.Lines.Add('Expected a JSON response from Twilio.');
Exit;
end;
if (reply.JsonTypeOf('status') <> 1) then
begin
Memo1.Lines.Add('Message status missing from response.');
Exit;
end;
Memo1.Lines.Add('Delivery status: ' + reply.StringOf('status'));
if ((reply.StringOfEquals('status','failed',1) = 1) or (reply.StringOfEquals('status','undelivered',1) = 1)) then
begin
if (reply.JsonTypeOf('error_code') = 2) then
begin
Memo1.Lines.Add('Delivery error code: ' + IntToStr(reply.IntOf('error_code')));
end;
if (reply.JsonTypeOf('error_message') = 1) then
begin
Memo1.Lines.Add(reply.StringOf('error_message'));
end;
end;