Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Clickatell One API: Schedule a time-limited SMS reminder
See more Clickatell Examples
Schedule a reminder 15 minutes from now in UTC. The scheduledDeliveryTime includes its time zone and validityPeriod is expressed in minutes. Set both from the appointment and the period for which the reminder will still be useful. Use the returned message ID for a later status lookup.
Supply an international number as digits. Set the sender to the provisioned number when the integration requires it.
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.CkDateTime,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
http: THttp;
schedule: TCkDateTime;
sendAt: string;
body: TJsonObject;
sender: string;
resp: THttpResponse;
sent: Boolean;
reply: TJsonObject;
parsed: Boolean;
begin
// Assumes Chilkat is unlocked. See Global Unlock Sample.
http := THttp.Create;
http.RequireSslCertVerify := True;
// Load the key for this One API integration from your application configuration.
http.SetRequestHeader('Authorization','ONE_API_KEY');
http.SetRequestHeader('Accept','application/json');
schedule := TCkDateTime.Create;
schedule.SetFromCurrentSystemTime();
schedule.AddSeconds(900);
sendAt := schedule.GetAsTimestamp(False);
body := TJsonObject.Create;
body.UpdateString('messages[0].channel','sms');
body.UpdateString('messages[0].to','PHONE_NUMBER');
body.UpdateString('messages[0].content','Appointment reminder: please check in at reception.');
body.UpdateString('messages[0].scheduledDeliveryTime',sendAt);
body.UpdateInt('messages[0].validityPeriod',60);
sender := '';
if (sender <> '') then
begin
body.UpdateString('messages[0].from',sender);
end;
WriteLn('Requested send time (UTC): ' + sendAt);
resp := THttpResponse.Create;
sent := http.HttpJson('POST','https://platform.clickatell.com/v1/message',body,'application/json',resp);
if (resp.StatusCode = 0) then
begin
WriteLn('No HTTP response. Check the message report before resending.');
Exit;
end;
reply := TJsonObject.Create;
parsed := reply.Load(resp.BodyStr);
if ((sent <> True) or (resp.StatusCode <> 202)) then
begin
WriteLn('Send returned HTTP ' + resp.StatusCode);
if (reply.HasMember('error.description') = True) then
begin
WriteLn(reply.StringOf('error.description'));
end;
Exit;
end;
if (reply.HasMember('error.code') = True) then
begin
if (reply.IsNullOf('error.code') <> True) then
begin
WriteLn('Submission error ' + reply.StringOf('error.code') + ' ' + reply.StringOf('error.description'));
Exit;
end;
end;
// HTTP acceptance and the recipient result are separate checks.
if ((parsed <> True) or (reply.JsonTypeOf('messages[0].accepted') <> 5)) then
begin
WriteLn('Missing recipient result. Check the message report.');
Exit;
end;
if (reply.BoolOf('messages[0].accepted') <> True) then
begin
WriteLn('Message rejected: ' + reply.StringOf('messages[0].error.code') + ' ' + reply.StringOf('messages[0].error.description'));
Exit;
end;
if (reply.JsonTypeOf('messages[0].apiMessageId') <> 1) then
begin
WriteLn('Accepted without a message ID. Check the message report.');
Exit;
end;
WriteLn('Accepted. Message ID: ' + reply.StringOf('messages[0].apiMessageId'));
http.Free;
schedule.Free;
body.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.