Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
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 Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.HttpResponse,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
resp: THttpResponse;
reply: TJsonObject;
parsed: Boolean;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
http := THttp.Create;
http.RequireSslCertVerify := True;
// Supply the key for this One API integration from application configuration.
http.SetRequestHeader('Authorization','ONE_API_KEY');
http.SetRequestHeader('Accept','application/json');
// Use the provider-generated ID from an accepted One API send.
http.SetUrlVar('id','ONE_API_MESSAGE_ID');
resp := THttpResponse.Create;
success := http.HttpNoBody('GET','https://platform.clickatell.com/v1/message/{$id}',resp);
if (resp.StatusCode = 0) then
begin
WriteLn('No HTTP response. Check the connection and retry the lookup.');
Exit;
end;
reply := TJsonObject.Create;
parsed := reply.Load(resp.BodyStr);
if ((success <> True) or ((resp.StatusCode <> 200))) then
begin
WriteLn('Clickatell returned HTTP ' + resp.StatusCode);
if (parsed = True) then
begin
if (reply.HasMember('error.description') = True) then
begin
WriteLn(reply.StringOf('error.description'));
end;
end;
Exit;
end;
if (parsed <> True) then
begin
WriteLn('Expected a JSON response.');
Exit;
end;
// A known SMS has a string status under the sms member.
if (reply.JsonTypeOf('sms.status') <> 1) then
begin
if (reply.JsonTypeOf('whatsapp.status') = 1) then
begin
WriteLn('This message has WhatsApp status: ' + reply.StringOf('whatsapp.status'));
end
else
begin
WriteLn('No SMS status was returned. Check the message ID and integration.');
if (reply.JsonTypeOf('status') = 1) then
begin
WriteLn('Reported status: ' + reply.StringOf('status'));
end;
end;
Exit;
end;
WriteLn('SMS status: ' + reply.StringOf('sms.status'));
if (reply.JsonTypeOf('sms.timestamp') = 2) then
begin
// Read the provider timestamp as text to preserve every digit.
WriteLn('Last status change (provider timestamp): ' + reply.StringOf('sms.timestamp'));
end;
http.Free;
resp.Free;
reply.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.