Choose:
Push Notifications
Most people will be familiar with push notifications- they’re the clickable pop-up messages across mobile applications. Push Notifications allow users to read messages from apps, without having to actually open the application.
These tutorials will guide you through how to implement push notifications in your WebRTC applications for iOS and Android devices. If you have any questions, click the chat box in the lower right hand corner for help from our support team.## iOS Push Notification Setup
The Telnyx iOS Client WebRTC SDK makes use of APNS in order to deliver push notifications. If you would like to receive notifications when receiving calls on your iOS mobile device you will have to configure a VoIP push certificate.
Creating a VoIP push certificate
In order to generate VoIP push certificates you will need:
- An Apple developer account
- App BundleID
- CSR (Certificate Signing Request): Explained on Step #7
- Go to https://developer.apple.com/ and login with your credentials.
- In the Overview section, select “Certificates, Identifiers & Profiles”
Press the blue “+” button to add a new Certificate:
Search for “VoIP Services Certificate” and Click “Continue”:
Select the BundleID of the target application, and click “Continue”
Then, you will be requested to upload a CSR from your Mac.
In order to generate a CSR: a. Open the KeyChain Access of your mac. b. Go to Keychain Access >> Certificate Assistance > Request a Certificate from a Certificate Authority.
c. Add your email address and select “Save to disk” option, and click “Continue”
d. Save the Certificate Signing Request (CSR) into your Mac.
Once you have created your CSR, press “Choose File” and select the certSign created on step #7. Click “Continue” and you are done.
The new Certificate has been created. Now you need to download it:
Search for the downloaded file (usually named voip_services.cer) and double click on it to install it on your Mac. And that’s all for now!
Obtain your Cert.pem and Key.pem files
In order to allow the Telnyx VoIP push service to send notifications to your app, you will need to export the VoIP certificate and key:
- Open Keychain Access on your Mac (where you have installed the VoIP certificate by following the “Creating a VoIP push certificate” instructions).
Search for “VoIP services” and verify that you have the certificate installed for the BundleID of your application.
Open the contextual menu and select “Export”:
Save the .p12 file (A password will be requested before saving it):
Once the certificate is created you will need to run the following commands to obtain the cert.pem and key.pem files:
$ openssl pkcs12 -in PATH_TO_YOUR_P12 -nokeys -out cert.pem -nodes
$ openssl pkcs12 -in PATH_TO_YOUR_P12 -nocerts -out key.pem -nodes
$ openssl rsa -in key.pem -out key.pem
- Now you can go to your Portal account and configure your PN credential.
Setup your iOS VoIP credentials on your Portal
Create an iOS Push Credential:
- Go to portal.telnyx.com and login.
- Go to the API Keys section on the left panel.
From the top bar go to the Credentials tab and select “Add” >> iOS Credential
Set a credential name (You can use your app bundle ID to easy identify your PN credential) and then copy and paste the contents of your cert.pem and key.pem files into the defined sections (Notice that you need to copy from ---BEGIN ####--- to ---END--- sections including those marks):
Save the new push credential by pressing the Add Push Credential button.
Assign your iOS Push Credential to a SIP Connection:
- Go to the SIP Connections section on the left panel.
- Open the Settings menu of the SIP connection that you want to add a Push Credential or create a new SIP Connection.
- Select the WEBRTC tab.
- Go to the iOS Section and select the PN credential created on “Create an iOS Push Credential”
That’s done. You can now go to your code and start implementing PushKit and Callkit using the TelnyxRTC SDK and receive VoIP push notifications into your iOS device.
Push Notifications
Most people will be familiar with push notifications- they’re the clickable pop-up messages across mobile applications. Push Notifications allow users to read messages from apps, without having to actually open the application.
These tutorials will guide you through how to implement push notifications in your WebRTC applications for iOS and Android devices. If you have any questions, click the chat box in the lower right hand corner for help from our support team.## Android Push Notification Setup
The Telnyx Android Client WebRTC SDK makes use of Firebase Cloud Messaging in order to deliver push notifications. If you would like to receive notifications when receiving calls on your Android mobile device you will have to enable Firebase Cloud Messaging within your application.
In order to do this you need to:
- Set up a Firebase console account
- Create a Firebase project
- Add Firebase to your Android Application
- Setup a Push Credential within the Telnyx Portal
- Generate a Firebase Cloud Messaging instance token
- Send the token with your login message
Adding Firebase to your application is a simple process. Click on the Android icon on the home screen of the console to start:
Next, enter your application details and register your application
After your application is registered, Firebase will generate a google-services.json file for you which will need to be added to your project root directory:
After that, you can follow this guide on how to enable the firebase products within your application https://firebase.google.com/docs/android/setup#add-config-file
An alternative method is to add Firebase using the Firebase Assistant within Android Studio if it is setup within your IDE. You can view steps on how to register via this option here: https://firebase.google.com/docs/android/setup#assistant
Once your application is set up within the Firebase Console, you will be able to access the server key required for portal setup. You can access the server key by going into your project overview -> project settings and selecting Cloud Messaging. Once there, the project credentials will be visible for use in our portal setup.
The next step is to set up your Android VoIP credentials in the portal.
- Go to portal.telnyx.com and login.
- Go to the API Keys section on the left panel.
- From the top bar go to the Credentials tab and select “Add” >> Android Credential
- Enter the details required for your Android Push Credentials. This includes a Credential name and the server key from firebase mentioned in an earlier step.
Save the new push credential by pressing the Add Push Credential button
We can now attach this Android Push Credential to a SIP Connection:
- Go to the SIP Connections section on the left panel.
- Open the Settings menu of the SIP connection that you want to add a Push Credential to or create a new SIP Connection.
- Select the WebRTC tab.
- Go to the Android Section and select the PN credential you previously created.
The portal setup is complete. Now when firebase is properly integrated within your application, you will be able to retrieve a token with a method such as this:
private fun getFCMToken() {
FirebaseApp.initializeApp(this)
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (!task.isSuccessful) {
Timber.d("Fetching FCM registration token failed")
}
else if (task.isSuccessful){
// Get new FCM registration token
try {
token = task.result
} catch (e: IOException) {
Timber.d(e)
}
Timber.d("FCM token received: $token")
}
}
}
This token can then be used with the Login Message to register yourself for Push notifications. You can read more about login Messages here https://developers.telnyx.com/docs/api/v2/webrtc#android-client-sdk
The final step is to create a MessagingService for your application. The MessagingService is the class that handles FCM messages and creates notifications for the device from these messages. You can read about the firebase messaging service class here: https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService
We have a sample implementation for you to take a look at here: https://github.com/team-telnyx/telnyx-webrtc-android/blob/main/app/src/main/java/com/telnyx/webrtc/sdk/utility/MyFirebaseMessagingService.kt
Once this class is created, remember to update your manifest and specify the newly created service like so:
https://firebase.google.com/docs/cloud-messaging/android/client#manifest
You are now ready to receive push notifications via Firebase Messaging Service.
Push Notifications
Most people will be familiar with push notifications- they’re the clickable pop-up messages across mobile applications. Push Notifications allow users to read messages from apps, without having to actually open the application.
These tutorials will guide you through how to implement push notifications in your WebRTC applications for iOS and Android devices. If you have any questions, click the chat box in the lower right hand corner for help from our support team.
Set up Push Notifications within the portal
Push notifications are a useful tool to notify mobile applications built with the Mobile SDKs that an incoming call is being received when not connected to the Telnyx Socket connection when the application is open and logged in.
When logged into the application, a general invite message will be received, but in the likely situation that the application is not open, a push notification will be received instead, allowing the user to react, connect back to the socket connection and receive the incoming call.
A key thing to note is that the invitation will always come in the form of an invitation message on the socket connection, the Push Notification serves more as a reminder to reconnect to the socket so that the invitation can be received. In this case, the call that is created is parked until the destination connection is reconnected. When the destination connection reconnects, as a result of a push notification, the call is unparked and an invitation is sent on the socket connection
Ultimately, push notifications are the only way to receive an incoming call when not connected to your application, be it closed or even in the background in the case of iOS applications, which is often the case.
Adding a Push Credential in the portal
To allow push notifications in your application, you need to create Push Credentials in the portal. Log into the portal and select the “API Keys tab”, and then select the “Credentials tab” which can be used to create and manage Push Credentials to use with the Telnyx API.
Hit the Add button drop-down and select the platform you want.
Adding an Android Push Credential
Our Android Push Notifications utilize the Firebase Messaging service, meaning you will require a Firebase account in order to generate a Firebase Server Key. You can read more about that process here
To finalize your new credential, provide a Credential Name and your Firebase Server Key and hit the Add Push Credential button
Adding an iOS Push Credential
Our iOS Push Notifications utilizes APNS (Apple Push Notification Service) to send notifications to iOS devices. You can read more about setting up APNS and creating the required fields here
To finalize your new credential, provide a Credential Name, your APNS private key, and the Certificate and hit the Add Push Credential button
Apply Push Credential to a Connection
To put our new credentials to use, we need to apply them to a credential. To do this, select the “SIP Connections” tab and select the connection you would like to apply the push credentials to and hit the “Basic Options” button on the right.
Then navigate to the WebRTC tab. Here you can apply your new Push Credentials for either or both platforms and hit the Save All Changes button.
What happens next?
Once a push credential has been applied to a connection for a specific platform, that platform will be able to receive notifications once a user has logged in via one of the Mobile SDKs and included either the Firebase Token with the login message for
Android:
[{
"id": "5e31078e-9085-4538-bd3b-1b9caed4124d",
"jsonrpc": "2.0",
"method": "login",
"params": {
"login": "<username>",
"loginParams": [],
"passwd": "<password>",
"userVariables": {
"push_device_token": "<Firebase token>",
"push_notification_provider": "android"
}
}
}]
Logging in with the firebase device token tells our servers that when this specific user receives a call and they aren’t logged in, instead of sending an invite socket message, they should receive a push notification to that device and then send an invite socket message once they are connected to our servers.
For iOS:
[{
"jsonrpc": "2.0",
"method": "login",
"id": "f3144369-c6c8-461a-bf4f-253407f7099e",
"params": {
"login": "<username>",
"passwd": "<password>",
"userVariables": {
"push_device_token": "<APNS Token>",
"push_notification_provider": "ios"
},
"loginParams": {}
}
}]
Adding and assigning Push Credentials via API Calls
Create new mobile_push_credential
Once you've obtained the certificate and private key for iOS (you can follow this guide for that), you can create a new iOS push_credential with the following request:
curl -X "POST" "https://api.telnyx.com/v2/mobile_push_credentials" \
-H 'Authorization: Bearer <my-telnyx-api-key>' \
-H 'Content-Type: application/json; charset=utf-8' \
-d '{
"certificate": "<my-iOS-Certificate>",
"alias": "<my-alias-for-ios-credential>",
"private_key": "<my-iOS-Private-Key>",
"type": "ios"
}'
Similarly for Android, you can follow this guide to obtain a server key and then you can create a new Android push_credential with the following request:
curl -X "POST" "https://api.telnyx.com/v2/mobile_push_credentials" \
-H 'Authorization: Bearer <my-telnyx-api-key>' \
-H 'Content-Type: application/json; charset=utf-8' \
-d '{
"alias": "<my-alias-for-android-credential>",
"type": "android",
"server_key": "<my-Server-Key>"
}'
List existing mobile_push_credentials
If you already have some mobile_push_credentials create with Telnyx, you can get information about them with the following requests:
curl "https://api.telnyx.com/v2/mobile_push_credentials" \
-H 'Authorization: Bearer <my-telnyx-api-key>'
Note: we'll need the id
field for a mobile_push_credential, in order to assoicate it with a SIP connection.
Create new SIP connections
If you need new SIP connections, please follow our Portal Setup guide to create them.
Associate a mobile_push_credential to a SIP connection
Now that we are ready to associate a mobile_push_credentials to a SIP connections.
For an iOS push_credential, you can use the following request:
curl -X "PATCH" "https://api.telnyx.com/v2/credential_connections/<connection_id>" \
-H 'Authorization: Bearer <my-telnyx-api-key>' \
-H 'Content-Type: application/json; charset=utf-8' \
-d '{
"ios_push_credential_id": "<ios_push_credential_id>"
}'
And for Android push_credential:
curl -X "PATCH" "https://api.telnyx.com/v2/credential_connections/<connection_id>" \
-H 'Authorization: Bearer <my-telnyx-api-key>' \
-H 'Content-Type: application/json; charset=utf-8' \
-d '{
"android_push_credential_id": "<android_push_credential_id>"
}'
Note: to get the connection_id, you can visit the SIP Connections page on Portal.