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

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // Assumes Chilkat is unlocked. See Global Unlock Sample.
  final http = 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');
  final data = CkJsonObject();
  data.updateString('invoiceNumber', 'INV-1042');
  final resp = CkHttpResponse();
  var sent = true;
  try {
    http.httpJson('POST', 'https://flow-callback.clickatell.com/chat/callback', data, 'application/json', resp);
  } on ChilkatException {
    sent = false;
  }
  if (resp.statusCode == 204) {
    print('Clickatell already processed this reference.');
    return;
  }

  if ((sent) && (resp.statusCode == 202)) {
    print('Invoice data accepted for the waiting conversation.');
    return;
  }

  if (resp.statusCode == 0) {
    print('No response. Keep the same reference if the job retries.');
    return;
  }

  print('Chat Flow returned HTTP ${resp.statusCode}');
  if ((resp.statusCode == 400) || (resp.statusCode == 410)) {
    print('Check the reference, result and whether the session is still waiting.');
  }
}