PureBasic Requires Chilkat v11.0.0+
PureBasic
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 PureBasic Downloads
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
; Assumes Chilkat is unlocked. See Global Unlock Sample.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttp::setCkRequireSslCertVerify(http, 1)
; These values come from the waiting session and its configured result branch.
CkHttp::ckSetRequestHeader(http,"reference","WAITING_SESSION_UUID")
CkHttp::ckSetRequestHeader(http,"result","invoice_ready")
data.i = CkJsonObject::ckCreate()
If data.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(data,"invoiceNumber","INV-1042")
resp.i = CkHttpResponse::ckCreate()
If resp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
sent.i = CkHttp::ckHttpJson(http,"POST","https://flow-callback.clickatell.com/chat/callback",data,"application/json",resp)
If CkHttpResponse::ckStatusCode(resp) = 204
Debug "Clickatell already processed this reference."
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(data)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndIf
If (sent = 1) AND (CkHttpResponse::ckStatusCode(resp) = 202)
Debug "Invoice data accepted for the waiting conversation."
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(data)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndIf
If CkHttpResponse::ckStatusCode(resp) = 0
Debug "No response. Keep the same reference if the job retries."
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(data)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndIf
Debug "Chat Flow returned HTTP " + Str(CkHttpResponse::ckStatusCode(resp))
If (CkHttpResponse::ckStatusCode(resp) = 400) OR (CkHttpResponse::ckStatusCode(resp) = 410)
Debug "Check the reference, result and whether the session is still waiting."
EndIf
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(data)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndProcedure