Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

Clickatell Chat Flow: Resume a waiting conversation

See more Clickatell Examples

Use this outbound REST call from a billing job after it generates an invoice. Configure a Wait for Callback node with the same reference UUID supplied to the job and the result value used by the flow. Reuse that UUID for retries. Clickatell hosts the endpoint. The billing job needs no inbound HTTP listener.

Clickatell API reference

Chilkat Delphi DLL Downloads

Delphi DLL
var
http: HCkHttp;
data: HCkJsonObject;
resp: HCkHttpResponse;
sent: Boolean;

begin
//  Assumes Chilkat is unlocked. See Global Unlock Sample.
http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);

//  These values come from the waiting session and its configured result branch.
CkHttp_SetRequestHeader(http,'reference','WAITING_SESSION_UUID');
CkHttp_SetRequestHeader(http,'result','invoice_ready');
data := CkJsonObject_Create();
CkJsonObject_UpdateString(data,'invoiceNumber','INV-1042');
resp := CkHttpResponse_Create();
sent := CkHttp_HttpJson(http,'POST','https://flow-callback.clickatell.com/chat/callback',data,'application/json',resp);
if (CkHttpResponse_getStatusCode(resp) = 204) then
  begin
    Memo1.Lines.Add('Clickatell already processed this reference.');
    Exit;
  end;
if ((sent = True) and (CkHttpResponse_getStatusCode(resp) = 202)) then
  begin
    Memo1.Lines.Add('Invoice data accepted for the waiting conversation.');
    Exit;
  end;
if (CkHttpResponse_getStatusCode(resp) = 0) then
  begin
    Memo1.Lines.Add('No response. Keep the same reference if the job retries.');
    Exit;
  end;
Memo1.Lines.Add('Chat Flow returned HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
if ((CkHttpResponse_getStatusCode(resp) = 400) or (CkHttpResponse_getStatusCode(resp) = 410)) then
  begin
    Memo1.Lines.Add('Check the reference, result and whether the session is still waiting.');
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(data);
CkHttpResponse_Dispose(resp);