Android™ Requires Chilkat v11.0.0+
Android™
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 Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkHttp http = new CkHttp();
http.put_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");
CkJsonObject data = new CkJsonObject();
data.UpdateString("invoiceNumber","INV-1042");
CkHttpResponse resp = new CkHttpResponse();
boolean sent = http.HttpJson("POST","https://flow-callback.clickatell.com/chat/callback",data,"application/json",resp);
if (resp.get_StatusCode() == 204) {
Log.i(TAG, "Clickatell already processed this reference.");
return;
}
if ((sent == true) and (resp.get_StatusCode() == 202)) {
Log.i(TAG, "Invoice data accepted for the waiting conversation.");
return;
}
if (resp.get_StatusCode() == 0) {
Log.i(TAG, "No response. Keep the same reference if the job retries.");
return;
}
Log.i(TAG, "Chat Flow returned HTTP " + String.valueOf(resp.get_StatusCode()));
if ((resp.get_StatusCode() == 400) or (resp.get_StatusCode() == 410)) {
Log.i(TAG, "Check the reference, result and whether the session is still waiting.");
}
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}