Search in sources :

Example 1 with MetaData

use of org.jivesoftware.smackx.workgroup.MetaData in project Smack by igniterealtime.

the class AgentSession method setStatus.

/**
     * Sets the agent's current status with the workgroup. The presence mode affects how offers
     * are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
     * <p/>
     * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
     * (equivalent to Presence.Mode.CHAT).
     * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
     * However, special case, or extreme urgency chats may still be offered to the agent.
     * <li>Presence.Mode.AWAY -- the agent is not available and should not
     * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
     * <p/>
     * The max chats value is the maximum number of chats the agent is willing to have routed to
     * them at once. Some servers may be configured to only accept max chat values in a certain
     * range; for example, between two and five. In that case, the maxChats value the agent sends
     * may be adjusted by the server to a value within that range.
     *
     * @param presenceMode the presence mode of the agent.
     * @param maxChats     the maximum number of chats the agent is willing to accept.
     * @param status       sets the status message of the presence update.
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * @throws IllegalStateException if the agent is not online with the workgroup.
     */
public void setStatus(Presence.Mode presenceMode, int maxChats, String status) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (!online) {
        throw new IllegalStateException("Cannot set status when the agent is not online.");
    }
    if (presenceMode == null) {
        presenceMode = Presence.Mode.available;
    }
    this.presenceMode = presenceMode;
    this.maxChats = maxChats;
    Presence presence = new Presence(Presence.Type.available);
    presence.setMode(presenceMode);
    presence.setTo(this.getWorkgroupJID());
    if (status != null) {
        presence.setStatus(status);
    }
    // Send information about max chats and current chats as a packet extension.
    StandardExtensionElement.Builder builder = StandardExtensionElement.builder(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE);
    builder.addElement("max_chats", Integer.toString(maxChats));
    presence.addExtension(builder.build());
    presence.addExtension(new MetaData(this.metaData));
    StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
    collector.nextResultOrThrow();
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) MetaData(org.jivesoftware.smackx.workgroup.MetaData) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 2 with MetaData

use of org.jivesoftware.smackx.workgroup.MetaData in project Smack by igniterealtime.

the class Workgroup method handlePacket.

// PacketListener Implementation.
private void handlePacket(Stanza packet) {
    if (packet instanceof Message) {
        Message msg = (Message) packet;
        // Check to see if the user left the queue.
        ExtensionElement pe = msg.getExtension("depart-queue", "http://jabber.org/protocol/workgroup");
        ExtensionElement queueStatus = msg.getExtension("queue-status", "http://jabber.org/protocol/workgroup");
        if (pe != null) {
            fireQueueDepartedEvent();
        } else if (queueStatus != null) {
            QueueUpdate queueUpdate = (QueueUpdate) queueStatus;
            if (queueUpdate.getPosition() != -1) {
                fireQueuePositionEvent(queueUpdate.getPosition());
            }
            if (queueUpdate.getRemaingTime() != -1) {
                fireQueueTimeEvent(queueUpdate.getRemaingTime());
            }
        } else {
            // Check if a room invitation was sent and if the sender is the workgroup
            MUCUser mucUser = (MUCUser) msg.getExtension("x", "http://jabber.org/protocol/muc#user");
            MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null;
            if (invite != null && workgroupJID.equals(invite.getFrom())) {
                String sessionID = null;
                Map<String, List<String>> metaData = null;
                pe = msg.getExtension(SessionID.ELEMENT_NAME, SessionID.NAMESPACE);
                if (pe != null) {
                    sessionID = ((SessionID) pe).getSessionID();
                }
                pe = msg.getExtension(MetaData.ELEMENT_NAME, MetaData.NAMESPACE);
                if (pe != null) {
                    metaData = ((MetaData) pe).getMetaData();
                }
                WorkgroupInvitation inv = new WorkgroupInvitation(connection.getUser(), msg.getFrom(), workgroupJID, sessionID, msg.getBody(), msg.getFrom(), metaData);
                fireInvitationEvent(inv);
            }
        }
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) MetaData(org.jivesoftware.smackx.workgroup.MetaData) WorkgroupInvitation(org.jivesoftware.smackx.workgroup.WorkgroupInvitation) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) QueueUpdate(org.jivesoftware.smackx.workgroup.packet.QueueUpdate) Map(java.util.Map) SessionID(org.jivesoftware.smackx.workgroup.packet.SessionID)

Example 3 with MetaData

use of org.jivesoftware.smackx.workgroup.MetaData in project Smack by igniterealtime.

the class AgentSession method setStatus.

/**
     * Sets the agent's current status with the workgroup. The presence mode affects how offers
     * are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
     * <p/>
     * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
     * (equivalent to Presence.Mode.CHAT).
     * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
     * However, special case, or extreme urgency chats may still be offered to the agent.
     * <li>Presence.Mode.AWAY -- the agent is not available and should not
     * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
     *
     * @param presenceMode the presence mode of the agent.
     * @param status       sets the status message of the presence update.
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * @throws IllegalStateException if the agent is not online with the workgroup.
     */
public void setStatus(Presence.Mode presenceMode, String status) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (!online) {
        throw new IllegalStateException("Cannot set status when the agent is not online.");
    }
    if (presenceMode == null) {
        presenceMode = Presence.Mode.available;
    }
    this.presenceMode = presenceMode;
    Presence presence = new Presence(Presence.Type.available);
    presence.setMode(presenceMode);
    presence.setTo(this.getWorkgroupJID());
    if (status != null) {
        presence.setStatus(status);
    }
    presence.addExtension(new MetaData(this.metaData));
    StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
    collector.nextResultOrThrow();
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) MetaData(org.jivesoftware.smackx.workgroup.MetaData) Presence(org.jivesoftware.smack.packet.Presence) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 4 with MetaData

use of org.jivesoftware.smackx.workgroup.MetaData in project Smack by igniterealtime.

the class AgentSession method handlePacket.

// PacketListener Implementation.
private void handlePacket(Stanza packet) {
    if (packet instanceof Presence) {
        Presence presence = (Presence) packet;
        // The workgroup can send us a number of different presence packets. We
        // check for different packet extensions to see what type of presence
        // packet it is.
        Resourcepart queueName = presence.getFrom().getResourceOrNull();
        WorkgroupQueue queue = queues.get(queueName);
        // If there isn't already an entry for the queue, create a new one.
        if (queue == null) {
            queue = new WorkgroupQueue(queueName);
            queues.put(queueName, queue);
        }
        // QueueOverview packet extensions contain basic information about a queue.
        QueueOverview queueOverview = (QueueOverview) presence.getExtension(QueueOverview.ELEMENT_NAME, QueueOverview.NAMESPACE);
        if (queueOverview != null) {
            if (queueOverview.getStatus() == null) {
                queue.setStatus(WorkgroupQueue.Status.CLOSED);
            } else {
                queue.setStatus(queueOverview.getStatus());
            }
            queue.setAverageWaitTime(queueOverview.getAverageWaitTime());
            queue.setOldestEntry(queueOverview.getOldestEntry());
            // Fire event.
            fireQueueUsersEvent(queue, queueOverview.getStatus(), queueOverview.getAverageWaitTime(), queueOverview.getOldestEntry(), null);
            return;
        }
        // QueueDetails packet extensions contain information about the users in
        // a queue.
        QueueDetails queueDetails = (QueueDetails) packet.getExtension(QueueDetails.ELEMENT_NAME, QueueDetails.NAMESPACE);
        if (queueDetails != null) {
            queue.setUsers(queueDetails.getUsers());
            // Fire event.
            fireQueueUsersEvent(queue, null, -1, null, queueDetails.getUsers());
            return;
        }
        // Notify agent packets gives an overview of agent activity in a queue.
        StandardExtensionElement notifyAgents = presence.getExtension("notify-agents", "http://jabber.org/protocol/workgroup");
        if (notifyAgents != null) {
            int currentChats = Integer.parseInt(notifyAgents.getFirstElement("current-chats", "http://jabber.org/protocol/workgroup").getText());
            int maxChats = Integer.parseInt(notifyAgents.getFirstElement("max-chats", "http://jabber.org/protocol/workgroup").getText());
            queue.setCurrentChats(currentChats);
            queue.setMaxChats(maxChats);
            // TODO: might need another event for current chats and max chats of queue
            return;
        }
    } else if (packet instanceof Message) {
        Message message = (Message) packet;
        // Check if a room invitation was sent and if the sender is the workgroup
        MUCUser mucUser = (MUCUser) message.getExtension("x", "http://jabber.org/protocol/muc#user");
        MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null;
        if (invite != null && workgroupJID.equals(invite.getFrom())) {
            String sessionID = null;
            Map<String, List<String>> metaData = null;
            SessionID sessionIDExt = (SessionID) message.getExtension(SessionID.ELEMENT_NAME, SessionID.NAMESPACE);
            if (sessionIDExt != null) {
                sessionID = sessionIDExt.getSessionID();
            }
            MetaData metaDataExt = (MetaData) message.getExtension(MetaData.ELEMENT_NAME, MetaData.NAMESPACE);
            if (metaDataExt != null) {
                metaData = metaDataExt.getMetaData();
            }
            this.fireInvitationEvent(message.getFrom(), sessionID, message.getBody(), message.getFrom(), metaData);
        }
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) QueueOverview(org.jivesoftware.smackx.workgroup.packet.QueueOverview) Resourcepart(org.jxmpp.jid.parts.Resourcepart) QueueDetails(org.jivesoftware.smackx.workgroup.packet.QueueDetails) MetaData(org.jivesoftware.smackx.workgroup.MetaData) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) Map(java.util.Map) HashMap(java.util.HashMap) SessionID(org.jivesoftware.smackx.workgroup.packet.SessionID)

Aggregations

MetaData (org.jivesoftware.smackx.workgroup.MetaData)4 Presence (org.jivesoftware.smack.packet.Presence)3 Map (java.util.Map)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)2 AndFilter (org.jivesoftware.smack.filter.AndFilter)2 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)2 Message (org.jivesoftware.smack.packet.Message)2 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)2 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)2 SessionID (org.jivesoftware.smackx.workgroup.packet.SessionID)2 HashMap (java.util.HashMap)1 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 WorkgroupInvitation (org.jivesoftware.smackx.workgroup.WorkgroupInvitation)1 QueueDetails (org.jivesoftware.smackx.workgroup.packet.QueueDetails)1 QueueOverview (org.jivesoftware.smackx.workgroup.packet.QueueOverview)1 QueueUpdate (org.jivesoftware.smackx.workgroup.packet.QueueUpdate)1 Resourcepart (org.jxmpp.jid.parts.Resourcepart)1