User Presence with Notifications Guide
Introduction
This tutorial will walk through the steps of getting the current user's status, how to listen for notifications when the presence is changed, and how to update their status.
For more information on the Presence APIs see the REST Documentation and the Understanding Presence guide.
Get Current Presence State
After authorizing your application, you can get all of the presences defined in the system to provide the user with controls to change their presence.
You will also want to get the current user's information, which contains a reference to their presence. Using the presence definition ID, you can get the presence definition data.
Registering for Notifications
In order to receive notifications, we must first create a channel. The result of the channel create will give us a websocket URI that we can connect to. We will then create a subscription on that channel for the current user's status.
Receiving Web Socket Events
The web socket messages will contain a payload in the eventBody property that looks similar to this:
{
"topicName": "v2.users.9ed7d9f6-0c59-4360-ac54-40dd35eb9c2f.presence",
"version": "2",
"eventBody": {
"source": "PURECLOUD",
"presenceDefinition": {
"id": "6a3af858-942f-489d-9700-5f9bcdcdae9b",
"systemPresence": "AVAILABLE"
},
"primary": true,
"message": ""
},
"metadata": {
"CorrelationId": "290034f4-c3d7-46fd-8342-ee5bc859b7e9"
}
}
Here, eventBody contains a value of status which should mimic what you would get from the status property on the user object.
Updating Presence
Finally, we can update the presence. The call to update the presence requires a "Source Id". Genesys Cloud could potentially have different status sources from external systems, but here we want to update the Genesys Cloud status so we can pass in the key of PURECLOUD.