NSRPureCld | 2018-07-30 13:18:45 UTC | #1
I have set up a notifications so that they will be received in the "handleNotification" function. I do get the notifications in handleNotification when the station is called. How do I get the conversation id of a notification object in handleNotification ?
Setting up notifications (Scroll down to Setting up Notifications......).
Handling Notification (Scroll down to Handling Notifications......).
Setting up Notifications......
$(document).ready(function(){ alert("in ready function of LoginToPureCloud.jsp)")
client.loginImplicitGrant(clientId, redirectUri) .then(function() { console.log('Logged in'); //System.out.println("Logged in");
// Get authenticated user's info return usersApi.getUsersMe(); }) .then(function(userMe) { console.log('userMe: ', userMe); //System.out.println("userMe = " + userMe); me = userMe;
// Create notification channel return notificationsApi.postNotificationsChannels(); }) .then(function(channel) { console.log('channel: ', channel); console.log('me.id: ', me.id); //System.out.println("channel = " + channel); notificationChannel = channel;
// Set up web socket webSocket = new WebSocket(notificationChannel.connectUri); webSocket.onmessage = handleNotification;
// Subscribe to authenticated user's conversations conversationsTopic = 'v2.users.' + me.id + '.conversations'; const body = [ { id: conversationsTopic } ]; return notificationsApi.putNotificationsChannelSubscriptions(notificationChannel.id, body); })
Handling Notifications......
function handleNotification(message) { // Parse notification string to a JSON object const notification = JSON.parse(message.data); const topicName = ""; const eventBody = ""; const caller = ""; const callerState = ""; const user = ""; const userState = "";
if (notification.topicName.toLowerCase() == conversationsTopic.toLowerCase()){ //console.log('in handleNotification notification=', notification); const notification = JSON.parse(message.data); const topicName = notification.topicName; console.log('topicName = ' + topicName ); const eventBody = notification.eventBody; console.log('eventBody = ' + eventBody );
const caller = eventBody.participants[0]; const callerState = caller.calls[0].state; const user = eventBody.participants[1]; const userState = user.calls[0].state;
console.log('callerState = ' + callerState ); console.log('userState = ' + userState ); }
// Discard unwanted notifications if (notification.topicName.toLowerCase() === 'channel.metadata') { // Heartbeat //console.info('Ignoring metadata: ', notification); return; } else if (notification.topicName.toLowerCase() !== conversationsTopic.toLowerCase()) { // Unexpected topic //console.info('Unknown notification: ', notification); return; } else { console.info('Conversation notification: ', notification); }
}
tim.smith | 2018-07-30 13:20:36 UTC | #2
NSRPureCld, post:1, topic:3271
How do I get the conversation id of a notification object in handleNotification ?
The notification topics and schemas are documented here: Available Topics. For a conversation object, look at the id property.
system | 2018-08-30 13:20:38 UTC | #3
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 3271