Sample code for 30+ languages & platforms
Lazarus Pascal 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 Lazarus Pascal Downloads

Lazarus Pascal
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
  http: THttp;
  data: TJsonObject;
  resp: THttpResponse;
  sent: Boolean;

begin
  //  Assumes Chilkat is unlocked. See Global Unlock Sample.
  http := THttp.Create;
  http.RequireSslCertVerify := True;

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


  http.Free;
  data.Free;
  resp.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.