Skip to main content
Version: 0.8 (next)

Push notifications

warning

@credo-ts/push-notifications 0.7.1, the latest release, requires Credo 0.5 (@credo-ts/core@^0.5.0) and hasn't been updated for later versions of Credo.

@credo-ts/push-notifications lets a mobile agent send its push notification token to another agent, usually its mediator, over a DIDComm connection. The other agent can then wake the app with a push notification when a message arrives. It implements Aries RFC 0699 for Apple Push Notification service (APNs) and Aries RFC 0734 for Firebase Cloud Messaging (FCM).

Install​

npm install @credo-ts/push-notifications@0.7.1

Send the device token​

Register the module for each service you use:

import { Agent } from '@credo-ts/core'
import { PushNotificationsApnsModule, PushNotificationsFcmModule } from '@credo-ts/push-notifications'

const agent = new Agent({
// ...config and dependencies
modules: {
pushNotificationsApns: new PushNotificationsApnsModule(),
pushNotificationsFcm: new PushNotificationsFcmModule(),
},
})

await agent.initialize()

Then send the token that you got from the operating system over a connection:

// iOS
await agent.modules.pushNotificationsApns.setDeviceInfo(connectionId, { deviceToken })

// Android, or iOS through Firebase
await agent.modules.pushNotificationsFcm.setDeviceInfo(connectionId, { deviceToken, devicePlatform: 'android' })

getDeviceInfo(connectionId) asks the other agent for the device info it has stored for the connection.