If you use TalkJS inside of a mobile app, you might want to use push notifications.

To use push notifications with TalkJS, you need to do three things:

  1. Add your Apple & Google credentials in the TalkJS Dashboard
  2. Add some code to your app that registers your user's device for push notifications. This is documented below.
  3. Optionally, add code that captures the push notifications that TalkJS sends and performs actions based on it (eg add a notifications to the phone's action center, open the app on the right page when the notifications is tapped, and so on)

In the JavaScript SDK, TalkJS sessions have a function called registerDevice which you should call to give TalkJS permission to send push notifications to this user. You first obtain the user's device token or registration token. How this is done depends on the language and platform you use for developing your app. Then, you make the following call to our JS SDK:

talkSession.registerDevice({ platform: "ios", pushRegistrationId: token});

or

talkSession.registerDevice({ platform: "android", pushRegistrationId: token});

The function returns a JavaScript Promise object which resolves once the data was sent successfully to our server. The same Promise object is rejected in case of any errors.

That's it! From this point onwards, any message sent to this user on TalkJS ought to trigger a push notification.