To run the example project, you have to request for valid credentials, than clone the repo and run it
- Add jitpack to the root build.gradle file of your project at the end of repositories.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.ServicePattern:MobileAPI_Android:<LATEST_VERSION>'
}
- Generate the unique
clientID
for your application. TheclientID
should be generated when application runs for the first time on the mobile device and saved in the local storage. The application should use same value until it is deleted from the device. TheclientID
should be unique for the application / device combination.
val clientID = UUID.randomUUID().toString()
- Сreate an instance of the
ContactCenterCommunicator
class which would handle communications with the BPCC server:
val baseURL = "https://<your server URL>"
val tenantURL = "<your tenant URL>"
var appID = "<your messaging scenario entry ID>"
val api = ContactCenterCommunicator.init(baseURL, tenantURL, appID, clientID, applicationContext)
- Register for push notifications. Request for a token and register it in the API
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w("*****", "Fetching FCM registration token failed", task.exception)
// TODO: handle it !!!!!
}
api.subscribeForRemoteNotificationsFirebase(chatID, task.result) { r -> resultProcessing(r) /* define a result processing function */}
}
- Creeate FireBaseMessaging service
class CDFirebaseMessagingService : FirebaseMessagingService() {
val api: ContactCenterCommunicator? = <API reference>
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (remoteMessage.data.containsKey("chatID"))
<API reference>?.appDidReceiveMessage(remoteMessage.data.toMap())
}
override fun onNewToken(token: String) {
ifNotNull(token.isNotEmpty(), ChatDemo.chatID) {
<API reference>?.subscribeForRemoteNotificationsFirebase(token, ChatDemo.chatID) {
Log.e("onNewToken", " subscribeForRemoteNotificationsFirebase > $it")
}
}
}
}
- Add the callback
api.callback = object : ContactCenterEventsInterface {
override fun chatSessionEvents(result: Result<List<ContactCenterEvent>, Error>) {
/* process the callback' result */
this@<ACTIVITY>.resultProcessing(result)
}
}
BPMobileMessaging is available under the MIT license. See the LICENSE file for more info.