Delphi DLL Requires Chilkat v11.0.0+
Delphi DLL
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 Delphi DLL Downloads
var
http: HCkHttp;
schedule: HCkDateTime;
sendAt: PWideChar;
body: HCkJsonObject;
sender: PWideChar;
resp: HCkHttpResponse;
sent: Boolean;
reply: HCkJsonObject;
parsed: Boolean;
begin
// Assumes Chilkat is unlocked. See Global Unlock Sample.
http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);
// Load the key for this One API integration from your application configuration.
CkHttp_SetRequestHeader(http,'Authorization','ONE_API_KEY');
CkHttp_SetRequestHeader(http,'Accept','application/json');
schedule := CkDateTime_Create();
CkDateTime_SetFromCurrentSystemTime(schedule);
CkDateTime_AddSeconds(schedule,900);
sendAt := CkDateTime__getAsTimestamp(schedule,False);
body := CkJsonObject_Create();
CkJsonObject_UpdateString(body,'messages[0].channel','sms');
CkJsonObject_UpdateString(body,'messages[0].to','PHONE_NUMBER');
CkJsonObject_UpdateString(body,'messages[0].content','Appointment reminder: please check in at reception.');
CkJsonObject_UpdateString(body,'messages[0].scheduledDeliveryTime',sendAt);
CkJsonObject_UpdateInt(body,'messages[0].validityPeriod',60);
sender := '';
if (sender <> '') then
begin
CkJsonObject_UpdateString(body,'messages[0].from',sender);
end;
Memo1.Lines.Add('Requested send time (UTC): ' + sendAt);
resp := CkHttpResponse_Create();
sent := CkHttp_HttpJson(http,'POST','https://platform.clickatell.com/v1/message',body,'application/json',resp);
if (CkHttpResponse_getStatusCode(resp) = 0) then
begin
Memo1.Lines.Add('No HTTP response. Check the message report before resending.');
Exit;
end;
reply := CkJsonObject_Create();
parsed := CkJsonObject_Load(reply,CkHttpResponse__bodyStr(resp));
if ((sent <> True) or (CkHttpResponse_getStatusCode(resp) <> 202)) then
begin
Memo1.Lines.Add('Send returned HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
if (CkJsonObject_HasMember(reply,'error.description') = True) then
begin
Memo1.Lines.Add(CkJsonObject__stringOf(reply,'error.description'));
end;
Exit;
end;
if (CkJsonObject_HasMember(reply,'error.code') = True) then
begin
if (CkJsonObject_IsNullOf(reply,'error.code') <> True) then
begin
Memo1.Lines.Add('Submission error ' + CkJsonObject__stringOf(reply,'error.code') + ' ' + CkJsonObject__stringOf(reply,'error.description'));
Exit;
end;
end;
// HTTP acceptance and the recipient result are separate checks.
if ((parsed <> True) or (CkJsonObject_JsonTypeOf(reply,'messages[0].accepted') <> 5)) then
begin
Memo1.Lines.Add('Missing recipient result. Check the message report.');
Exit;
end;
if (CkJsonObject_BoolOf(reply,'messages[0].accepted') <> True) then
begin
Memo1.Lines.Add('Message rejected: ' + CkJsonObject__stringOf(reply,'messages[0].error.code') + ' ' + CkJsonObject__stringOf(reply,'messages[0].error.description'));
Exit;
end;
if (CkJsonObject_JsonTypeOf(reply,'messages[0].apiMessageId') <> 1) then
begin
Memo1.Lines.Add('Accepted without a message ID. Check the message report.');
Exit;
end;
Memo1.Lines.Add('Accepted. Message ID: ' + CkJsonObject__stringOf(reply,'messages[0].apiMessageId'));
CkHttp_Dispose(http);
CkDateTime_Dispose(schedule);
CkJsonObject_Dispose(body);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(reply);