Chat with us if you have any questions!

Virtual Agent - Queue White List from AD

Simple Virtual Agent for creating a queue white list from Active Directory.

Note: The Virtual Agent can be downloaded here » Virtual Agent SDK (zip) (VirtualAgentSDK\Samples\CS-ScriptVirtualAgents\VIPQueueBouncer.cs)

Overview

This simple Virtual Agent C# script file uses the AD service within Chime to enforce a queue White-List. When sessions enter the queue, the Virtual Agent checks if the guest's email address is present in the "InstantDevs" AD group (the group name can be replaced in SeekerConnected method). If the guest is a member, then the Virtual Agent disconnects and the session continue to route to a live expert. If the guest is not a member of the group, the Virtual Agent sends the guest a message "This is a VIP queue. Access denied." (this is also customizable).

Code Samples

In the IncomingSeekerOffer method the Virtual Agent accepts all sessions.

public bool IncomingSeekerOffer(int sessionId, string queueName, int queueID, string email, string question, PreviousSessionState? prevState)
{
        return true;
}

    
In the SeekerConnected method, the Virtual Agent performs the AD lookup and sends an "access denied" message to the guest if necessary.

public bool SeekerConnected(int sessionId)
{
	var userEmail = _pluginManager.GetSeekerEmail(sessionId);
	var groupName = "InstantDevs";
	var isVip = _pluginManager.ActiveDirectory.IsUserInGroup(userEmail, groupName);
	if (!isVip)
	{
		_pluginManager.LogMessageInChime(LoggingLevel.Warn, string.Format("Guest {0} is not a member of AD group {1}",userEmail, groupName));
		_pluginManager.SendIMToSeeker(sessionId, "This is a VIP queue. Access denied.");
	}
	else
	{
		_pluginManager.LogMessageInChime(LoggingLevel.Debug, string.Format("Guest {0} is a member of AD group {1}", userEmail, groupName));
	}
	_pluginManager.DisconnectVirtualAgent(sessionId, isVip);
    return true;
}

    

Full Source Code


using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;


/* © Instant Technologies 2017
 *
 *  This simple Virtual Agent script file uses the AD service within Chime to enforce a queue White-List. When sessions enter the queue, the Virtual Agent
 *  checks if the guest's email address is present in the "InstantDevs" AD group (this value can be replaces in SeekerConnected method). If the the guest is
 *  a member, then they Virtual Agent disconnects and the session continue to routing to a live expert. If the guest is not a member of the group, the Virtual
 *  Agent sends the guest a message "This is a VIP queue. Access denied." (this is also customizable).
 *
 *  In the IncomingSeekerOffer method the Virtual Agent accepts all sessions. In the SeekerConnected method, the Virtual Agent performs the AD lookup and sends
 *  an "access denied" message to the guest if necessary.
 *
 *  To deploy the Virtual Agent, copy this file to "C:\Program Files\Instant Technologies\Chime For Lync\Plugins" on the Chime server.
 *  Go to the Admin page in Chime and then the Virtual Agents section.
 *  First "Enable Virtual Agent Manager", then "Enable" the Virtual Agent named "Add Custom Tabs to CWE"
 *  Finally, assign this Virtual Agent to a queue in queue settings, under the People tab, then Virtual Agents.
 *  Select the Pre-Conversation Virtual Agent and save your changes.
 *
 */
public class VIPQueueBouncer : IVirtualAgent
{

    IPluginManager _pluginManager; //This is how you make calls to Chime.
    VirtualAgentState va_state;
	VirtualAgentProps vaData = new VirtualAgentProps("Bounce Non-VIP Guests From Queue", "1", VirtualAgentType.PreConversation, "Lookup guests in AD and only allow members of specific VIP group to enter queue routing", "Instant Technologies");


    /// <summary>
    /// Method called by the PluginManager when Chime starts, when an Office 365 queue starts,
    /// when global setting for virtual agents is turned on, and when the Plugin Manager is reloaded.
    /// </summary>
    /// <returns>The boolean represents whether this virtual agent is ready to be routed to. A virtual agent that returns false will be unavailable.
    /// The VirtualAgentProps is the properties that describe this virtual agent and is the data that will be displayed in Chime</returns>
    public Tuple<bool, VirtualAgentProps> Load()
    {
        va_state = VirtualAgentState.Online;
        bool isLoaded = true;
        return new Tuple<bool, VirtualAgentProps>(isLoaded, vaData);
    }

    /// <summary>
    /// This method is called when the global setting for virtual agents is turned off. 
    /// This gives a chance for the virtual agent to do any necessary house keeping before it is unloaded by the system.
    /// </summary>
    /// <returns>A bool representing whether this virtual agent was able to "shut down" correctly</returns>
    public bool UnLoad()
    {
        return true;
    }

    /// <summary>
    /// If the virtual agent returns true in the Tuple it returns from the Load method, then the Plugin Manager will call this method and give this virtual agent a reference to itself. 
    /// This allows the virtual agent to have a reference to call the IPluginManager methods on.
    /// </summary>
    /// <param name="pm">Instance provided by the PluginManager after succesfully loading</param>
    public void SetPluginManager(IPluginManager pm)
    {
        _pluginManager = pm;
    }

    /// <summary>
    /// The Plugin Manager asks the virtual agent for its state.
    /// The virtual agent state must be Online to receive a seeker offer, to be connected with a seeker,
    /// to receive a message from the seeker, and to be notified that the seeker has left the session.
    /// </summary>
    /// <returns>The current state of the virtual agent</returns>
    public VirtualAgentState GetState()
    {
        return va_state;
    }

    /// <summary>
    /// The Plugin Manager will call this method when a seeker enters a queue and state that this virtual agent is associated with.
    /// These parameters are designed for certain virtual agents that can quickly tell if they want to be connected with the session or not,
    /// for example, only e-mail addresses from the @acme.com domain, or only questions that contain the word 'password'.
    /// </summary>
    /// <param name="sessionId">The Chime session ID associated with the session being offered</param>
    /// <param name="queueName">Name of the queue the seeker is coming from</param>
    /// <param name="queueID">ID of the queue the seeker is coming from</param>
    /// <param name="email">The email address of the seeker that is being offered</param>
    /// <param name="question">The question of the seeker that is being offered</param>
    /// <param name="prevState">The previous state of the session that is being offered</param>
    /// <returns>This boolean value represents whether the virtual agent will be connected with the session,
    /// if false, the Plugin Manager will move this session along to the next state in the session life-cycle</returns>
    public bool IncomingSeekerOffer(int sessionId, string queueName, int queueID, string email, string question, PreviousSessionState? prevState)
    {
        return true;
    }

    /// <summary>
    /// This method will be called by the Plugin Manager if true was returned from IncomingSeekerOffer for this session ID.
    /// </summary>
    /// <param name="sessionId">The Chime session ID associated with the session being connected</param>
    /// <returns>The bool value represents if the virtual agent was able to connect successfully, if the virtual agent returns false the session will move to the next state in the session lifecycle.
    /// If the virtual agent returns true, the session will stay connected until either the virtual agent or the seeker disconnect (virtual agents disconnect by called the PluginManager.DisconnectVirtualAgent method).</returns>
    public bool SeekerConnected(int sessionId)
	{
		var userEmail = _pluginManager.GetSeekerEmail(sessionId);
		var groupName = "InstantDevs";
		var isVip = _pluginManager.ActiveDirectory.IsUserInGroup(userEmail, groupName);
		if (!isVip)
		{
			_pluginManager.LogMessageInChime(LoggingLevel.Warn, string.Format("Guest {0} is not a member of AD group {1}",userEmail, groupName));
			_pluginManager.SendIMToSeeker(sessionId, "This is a VIP queue. Access denied.");
		}
		else
		{
			_pluginManager.LogMessageInChime(LoggingLevel.Debug, string.Format("Guest {0} is a member of AD group {1}", userEmail, groupName));
		}
		_pluginManager.DisconnectVirtualAgent(sessionId, isVip);
		return true;
	}

    /// <summary>
    /// The Plugin Manager will call this method to notify the virtual agent if the seeker closes their chat window, i.e., leaves the session.
    /// </summary>
    /// <param name="sessionId">The Chime session ID associated with the session being disconnected</param>
    public void SeekerDisconnected(int sessionId)
    {
    }

    /// <summary>
    /// The Plugin Manager will call this method to broker a message it received from the seeker while connected with the virtual agent.
    /// </summary>
    /// <param name="sessionId">The Chime session ID associated with the seeker sending the message</param>
    /// <param name="email">The email address of the sender</param>
    /// <param name="msg">The text of the message</param>
    /// <returns></returns>
    public bool ReceiveMessage(int sessionId, string email, string msg)
    {
        return true;
    }

}

    

Questions?

Have a question about Chime virtual agents? Ask one of our developers at InstantDev@instant-tech.com.