Skip to main content

Pitel VoIP Push notification

Pitel VoIP Flow​

When user make call from Pitel Connect app, Pitel Server pushes a notification for all user login (who receives the call).

VoIP call flow

Image callkit​

Android(Alert) - AudioAndroid(Lockscreen | Fullscreen) - Audio

Setup & Certificate

Using FCM (Firebase Cloud Message) to handle push notification wake up app when app run on Background or Terminate

Warning Popup request permission only working with targetSdkVersion >= 33

Firebase Project​
  • Go to Project settings > Cloud Messaging and select Manage API in Google Cloud Console to open Google Cloud Console. fcm1
  • Go to API Library using the back button as shown below. fcm2
  • Search "cloud messaging" -> Select "Cloud Messaging" fcm3
  • Click Enable to start using the Cloud Messaging API. fcm4
Service Account​
  • Go to Project settings > Cloud Messaging and select Manage API in Google Cloud Console to open Google Cloud Console. fcm1
  • In tab "Credentials", scroll to "Service Accounts", click button edit with name "firebase-adminsdk". fcm7
  • Choose tab KEYS, click "Add key" -> "Create new key" and download json file. fcm8

Note

  • After completing the above steps, please provide the information to configure push notifications on the portal
  • Please check PORTAL_GUIDE.md to setup your config.

Using above app or test from Postman​

How to get access token?​

  • Go to https://developers.google.com/oauthplayground/
  • Navigate to Step 1 (Select & authorize APIs) → Select “Firebase Cloud Messaging API v1” and click “Authorize API’s” button. step_1
  • You will be redirected to Authentication and needs permission for Google OAuth 2.0 Playground to view and manage the GCP services. Click “Allow” button.
  • Navigate to Step 2 (Exchange authorization code for tokens) → Click “Exchange authorization code for tokens” button. This will generate “Refresh token” and “Access token”. step_2

Note:

  • project_id: this is your firebase project id.
  • fcm_token: replace your fcm token, get from your device.
  • access_token: get access token from oauth playground above.

cURL

curl --location 'https://fcm.googleapis.com/v1/projects/${project_id}/messages:send' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ${access_token}' \
--data '{
"message": {
"notification": {
"title": "",
"body": ""
},
"data": {
"uuid": "077712f3-9b56-4e26-96ea-382ea1206477",
"nameCaller": "Pitel Voip",
"phoneNumber": "101",
"appName": "Pitel Connect",
"callType": "CALL"
},
"apns": {
"headers": {
"apns-priority": "1",
"sound": ""
},
"payload": {
"aps": {
"mutable-content": 1,
"content-available": 1
}
}
},
"android": {
"priority": "high"
},
"token": "${fcm_token}"
}
}'

🛠️ Customizing FirebaseMessagingService​

If your host application already implements its own FirebaseMessagingService, prevent conflicts by overriding the SDK default service in AndroidManifest.xml and routing messages through PitelFirebaseHelper:

1. Remove the SDK's Default Service in AndroidManifest.xml​

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application>
<!-- Remove SDK built-in Firebase service -->
<service
android:name="com.pitel.voip.sdk.service.PitelFirebaseMessagingService"
tools:node="remove" />

<!-- Declare your app's custom Firebase service -->
<service
android:name=".service.MyFirebaseService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>

2. Forward Push Notifications in Kotlin​

package com.yourcompany.app.service

import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.pitel.voip.sdk.core.PitelClient
import com.pitel.voip.sdk.quickstart.PitelFirebaseHelper

class MyFirebaseService : FirebaseMessagingService() {

override fun onNewToken(token: String) {
super.onNewToken(token)
// Pass refreshed FCM token to the SDK
PitelClient.saveFcmToken(token)
}

override fun onMessageReceived(message: RemoteMessage) {
// Automatically checks if message belongs to Pitel VoIP; if so, handles incoming call wake-up
if (PitelFirebaseHelper.tryHandleMessage(this, message.data)) {
return
}

// Handle your application's regular notifications here
}
}