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 Motion 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 MTSservice, 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?