Return to Common Add-in functions

Watching a Queue for Interactions

When you are creating add-ins, you'll want to be able to watch a queue for specific interaction events and perform actions based on those events. The following steps and example code will show you how to go about watching a queue:

  1. Create a queue object.
  2. Bind for the appropriate events.
  3. Call subscribe.
  4. Dispose of the queue.

Note: The pattern shown here applies to other subscriptions that implement ININ.Addins.IC.ISubscription such as ININ.Addins.IC.Interactions.WatchedInteraction.


Create a queue object

This code creates an instance of a queue.

var queue = new ININ.Addins.IC.Queues.Queue();

Bind to the appropriate events

This example code illustrates how you go about binding to the appropriate events.

queue.on("interactionAdded", function(interaction) {
    console.log(
        interaction.getAttribute(ININ.Addins.IC.Interaction.attributeNames.interactionType), 
        "Interaction", interaction.interactionId, "was added to queue. State is:",
        ININ.Addins.IC.Interaction.attributeNames.stateDisplay
    );
});
queue.on("interactionChanged", function(interaction) {
    console.log(
        interaction.getAttribute(ININ.Addins.IC.Interaction.attributeNames.interactionType), 
        "Interaction", interaction.interactionId, "has changed. State is:",
        ININ.Addins.IC.Interaction.attributeNames.stateDisplay
    );
});
queue.on("interactionRemoved", function(interaction) {
    console.log("Interaction", interaction.interactionId, "has been removed from queue.");
});

Call subscribe

Subscriptions provide a live view of the current values on the server. This example code illustrates how you would subscribe to the My Interactions queue while watching the Eic_ObjectType and Eic_CallStateString attributes.

queue.subscribe({
    attributeNames: [
        ININ.Addins.IC.Interaction.attributeNames.interactionType, 
        ININ.Addins.IC.Interaction.attributeNames.stateDisplay
    ]
    queueIds: [
        { type: ININ.Addins.IC.Queues.queueTypes.system, name: ININ.Addins.IC.sessionInfo.userId }
    ]
});

Disposing the queue

When you are finished with the queue instance, you should dispose it by calling dispose.

queue.dispose();