JavaScript Requires Chilkat v11.0.0+
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var http = new CkHttp();
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");
var data = new CkJsonObject();
data.UpdateString("invoiceNumber","INV-1042");
var resp = new CkHttpResponse();
var sent = http.HttpJson("POST","https://flow-callback.clickatell.com/chat/callback",data,"application/json",resp);
if (resp.StatusCode == 204) {
console.log("Clickatell already processed this reference.");
return;
}
if ((sent == true) && (resp.StatusCode == 202)) {
console.log("Invoice data accepted for the waiting conversation.");
return;
}
if (resp.StatusCode == 0) {
console.log("No response. Keep the same reference if the job retries.");
return;
}
console.log("Chat Flow returned HTTP " + resp.StatusCode);
if ((resp.StatusCode == 400) || (resp.StatusCode == 410)) {
console.log("Check the reference, result and whether the session is still waiting.");
}