Xbase++ Requires Chilkat v11.0.0+
Xbase++
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.
Chilkat Xbase++ Downloads
LOCAL oHttp
LOCAL oData
LOCAL oResp
LOCAL nSent
// Assumes Chilkat is unlocked. See Global Unlock Sample.
oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
// These values come from the waiting session and its configured result branch.
oHttp:SetRequestHeader("reference", "WAITING_SESSION_UUID")
oHttp:SetRequestHeader("result", "invoice_ready")
oData := CreateObject("Chilkat.JsonObject")
oData:UpdateString("invoiceNumber", "INV-1042")
oResp := CreateObject("Chilkat.HttpResponse")
nSent := oHttp:HttpJson("POST", "https://flow-callback.clickatell.com/chat/callback", oData, "application/json", oResp)
IF (oResp:StatusCode == 204)
? "Clickatell already processed this reference."
oHttp:destroy()
oData:destroy()
oResp:destroy()
RETURN
ENDIF
IF ((nSent == 1) .AND. (oResp:StatusCode == 202))
? "Invoice data accepted for the waiting conversation."
oHttp:destroy()
oData:destroy()
oResp:destroy()
RETURN
ENDIF
IF (oResp:StatusCode == 0)
? "No response. Keep the same reference if the job retries."
oHttp:destroy()
oData:destroy()
oResp:destroy()
RETURN
ENDIF
? "Chat Flow returned HTTP " + Str(oResp:StatusCode)
IF ((oResp:StatusCode == 400) .OR. (oResp:StatusCode == 410))
? "Check the reference, result and whether the session is still waiting."
ENDIF
oHttp:destroy()
oData:destroy()
oResp:destroy()