SDKs & Sample Apps
SDKs

Dispatch SDK

43min

For every Execution Taskďťż, a corresponding pre-coded module is expected in the app as part of SDK. This module executes the Task on the device running the Delivery Agent app. Thus, the Dispatcher SDK allows you to build this app with the minimum amount of effort.

The Mobile App SDK will orchestrate the execution of Tasks. Objective status updates will flow back as objective events to dispatch service through API calls made by the SDK and they will be stored in the Objective Events Store. This SDK can be used to render execution task screens on UI, maintain their states, and manage Movement Tracking Systemďťż.

Dispatch SDK is an expo-based SDK that is written in Typescript and some Modules in Java/Kotlin.

Currently supports SDK>=21 (Android).

Features

  • Sync Manager: Provides Sync Manager for syncing events & Docs in the background with retry functionality.
  • Execution Tasks: Provides a list of Execution Tasks which are as follows: Deliver, Capture Input, Deliver Cash, Complete-Success, Complete-Failure, Pickup, Doodle, Forms, Display, Verify Location, Verify OTP, Verify String, Scan QR/Barcode, Image Capture, Init Payment, Process Payment, and Complete Payment.
  • Execution Engine: Provides methods for Executing a given Workflow/Job in a dispatch.
  • Firebase Cloud Messaging: Provides a method for receiving Firebase Cloud Messaging.
  • Async Storage: Provides async storage for storing key-value pairs.
  • Higher-Order ETs: Provides a way to customize Execution Task UI.
  • Asynchronous Event Handling: Provides a method for handling Execution Tasks asynchronously.

Installation

Setup Expo (For non-expo projects only)

Text
ďťż

Install Dispatch SDK Package

Text
ďťż
Text
ďťż

Install these dependencies

JSON
ďťż

Async Storage Size Increase

Add the following line in gradle.properties file for increasing storage (AsyncStorage_db_size_in_MB=10)

JSON
ďťż

Add jcenter() if not added already added in the Project-level build.gradle (/build.gradle): (Android only)

JSON
ďťż

Fix for Apollo GraphQL Client (metro.config.js)

Add the following changes in the metro.config.js file. Issue Linkďťż

JSON
ďťż

Usage

Init Dispatch SDK

JS
ďťż

Init Execution Engine

JS
ďťż

Query Objective Status

JS
ďťż

Start Objective Execution

JS
ďťż

FCM

Setup (Android only)

Add the Firebase Android configuration file to your app:

  • Create a Firebase project (Check Firebase instructions for creating an app).
  • Click Download google-services.json to obtain your Firebase Android config file (google-services.json).
  • Move your config file into the module (app-level) directory of your app.
  • To enable Firebase products in your app, add the Google services plugin to your Gradle files.

In your module (app-level) Gradle file (usually app/build.gradle), apply the Google Services Gradle plugin:

JSON
ďťż

In your root-level (project-level) Gradle file (build.gradle), add rules to include the Google Services Gradle plugin. Check that you have Google's Maven repository, as well.

JS
ďťż

Get FCM Token

JS
ďťż

Background FCM Messages

Register a callback for receiving FCM Messages in the background.

📘 NOTE

Call this function in the root component, i.e, in the `index.js file of the app.

ďťż

JS
ďťż

Foreground FCM Messages

useFcmMessage() custom hook in functional components to receive FCM Messages in Foreground.

JS
ďťż

OR

Extend FCM base class in case of class components

JS
ďťż

MTS

In the case of the dispatch mobile app, the Location Tracking module of the SDK provides a configurable way to capture and stream location data from the mobile device to the MTSďťżservice, without any user intervention. To learn more, see Dispatch Documentationďťż.

MTS Default Config

JSON
ďťż

Check For Mandatory MTS Permissions

JSON
ďťż

Init MTS

JSON
ďťż

Start MTS

JSON
ďťż

Publish Event

JSON
ďťż

Stop MTS

JSON
ďťż

Error Codes

JSON
ďťż

Sync Manager

Import Sync Manager

JSON
ďťż

Start Sync Manager as a Foreground Service in Android

JSON
ďťż

Asynchronous Event Handling

The Dispatch SDK support handling Execution Tasks asynchronously by emitting two events for each ET. This lets your apps to listen to these events and perform necessary actions.

For every ET, two events will be triggered in a fire-and-forget mode:

  • Task Start event: Triggered upon arrival of the ET, along with input data
  • Task End event: Triggered just before moving to the next ET, with the output data of objectives executed in that ET and the ID of the next ET to be executed.

To use this feature, you need to work with the eventListener method, which is used to listen and remove events. It contains the following methods:

  • .on: To listen to a specific event
  • .remove: To remove a specific event
JS
ďťż

Example

JS
ďťż

Event Payloads

See the examples below to describe event payloads using a CaptureImage Event

On Task Start

Triggered before starting the execution of ET

JS
ďťż

On Task End

Triggered after the completion of ET and before moving to the next ET.

JS
ďťż

On Task Back

Triggered when goBack is executed for an ET, before moving to the next ET.

JS
ďťż

Sample Events for CaptureImage

JSON
ďťż
JSON
ďťż

SDK Utility Methods

JS
ďťż

Download API from Public URL

JS
ďťż

Open and Install an APK file

JS
ďťż

Send events to Firebase analytics

JS
ďťż

Log events to console

JS
ďťż

Error Codes

JS
ďťż

ďťż

Updated 28 Feb 2024
Did this page help you?