Detect Session Changes in Dynamics 365 Customer Service App

The Dynamics 365 Customer Service Workspace app is a powerful tool designed to help customer service agents manage multiple sessions and interactions efficiently. In a busy customer service environment, it is essential to track and manage session changes effectively. Detecting session changes can help agents understand the context of the interactions and provide better customer service. In this blog, we will explore how to detect session changes in the Dynamics 365 Customer Service Workspace app using a simple JavaScript code snippet.

Why Detect Session Changes?

Before diving into the implementation, let's understand why detecting session changes is important.

  1. Context Switching: Agents often handle multiple customer interactions simultaneously. Detecting session changes helps agents switch context quickly and efficiently.
  2. Improved Productivity: Automatically logging session changes can help agents keep track of their work and avoid mistakes.
  3. Enhanced Customer Experience: By understanding which session is active, agents can provide more accurate and timely responses, improving the overall customer experience.
  4. Session Analytics: Detecting and logging session changes can provide valuable insights into agent performance and customer interactions, which can be used for training and optimization.
  5. Session State Persistence: Store the data in session storage to persist the data and that data can be consumed by other components like Web Resource or etc.

Steps to Detect Session Changes

Below is a step-by-step guide to implementing session change detection in the Dynamics 365 Customer Service Workspace app using JavaScript.

Step 1. Define the Session Switched Handler Function

First, we need to define a handler function that will be triggered when a session is switched. This function will log the previous and new session IDs to the console.

let sessionSwitchedHandlerFunction = function(eventInput) {
    console.log("Previous session:  " + eventInput.data.previousSessionId +
                " - Current session: " + eventInput.data.newSessionId);
};

Step 2. Retrieve the Session Switch Event Topic

Next, we need to retrieve the event topic specific to session switching from the Dynamics 365 API. This topic will be used to subscribe to session switch events.

let sessionSwitchTopic = Microsoft.Apm.getEventPublisherTopic("ON_SESSION_SWITCH");

Step 3. Create a Broadcast channel for Session Switch Events

We will create a new broadcast channel that will allow us to subscribe to session switch events using the event topic retrieved in the previous step.

let sessionSwitchSubscriber = new BroadcastChannel(sessionSwitchTopic);

Step 4. Attach the Handler Function to the Broadcast Channel

Finally, we attach the session switched handler function to the message event of the broadcast channel. This ensures that our handler function is called whenever a session switch event occurs.

sessionSwitchSubscriber.onmessage = sessionSwitchedHandlerFunction;

Sample Output in Console on Session Switch.

Output

Conclusion

By detecting session changes in the Dynamics 365 Customer Service Workspace app, agents can enhance their productivity, provide better customer service, and gain valuable insights into their interactions. The simple JavaScript code snippet provided in this blog demonstrates how to set up session change detection by defining a handler function, retrieving the session switch event topic, creating a broadcast channel, and attaching the handler function to the broadcast channel.

Implementing this functionality can significantly improve the efficiency and effectiveness of customer service operations in Dynamics 365. Feel free to customize and expand upon this example to suit your specific needs and requirements.


Similar Articles