Search in sources :

Example 1 with AgentChatSession

use of org.jivesoftware.openfire.fastpath.history.AgentChatSession in project Openfire by igniterealtime.

the class EmailTranscriptEvent method chatSupportFinished.

public void chatSupportFinished(Workgroup workgroup, String sessionID) {
    Log.debug("Chat Support Finished, sending transcripts");
    final EmailService emailService = EmailService.getInstance();
    String property = JiveGlobals.getProperty("mail.configured");
    if (!ModelUtil.hasLength(property)) {
        Log.debug("Mail settings are not configured, transcripts will not be sent.");
        return;
    }
    final ChatSession chatSession = ChatTranscriptManager.getChatSession(sessionID);
    if (chatSession == null || chatSession.getFirstSession() == null) {
        return;
    }
    final StringBuilder builder = new StringBuilder();
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyy hh:mm a");
    // Get duration of conversation
    Date date = new Date(chatSession.getFirstSession().getStartTime());
    int duration = getChatDuration(date, chatSession);
    TreeMap<String, List<String>> map = new TreeMap<String, List<String>>(chatSession.getMetadata());
    String body = JiveGlobals.getProperty("chat.transcript.body");
    if (ModelUtil.hasLength(body)) {
        builder.append(body).append("\n\n");
    }
    builder.append("formname=chat transcript\n");
    extractAndDisplay(builder, "question", map);
    display(builder, "fullname", chatSession.getCustomerName());
    extractAndDisplay(builder, "email", map);
    extractAndDisplay(builder, "Location", map);
    extractAndDisplay(builder, "userID", map);
    extractAndDisplay(builder, "username", map);
    extractAndDisplay(builder, "workgroup", map);
    display(builder, "chatduration", String.valueOf(duration));
    display(builder, "chatdate", formatter.format(date));
    if (chatSession.getFirstSession() != null && chatSession.getFirstSession().getAgentJID() != null) {
        try {
            display(builder, "agent", new JID(chatSession.getFirstSession().getAgentJID()).toBareJID());
        } catch (Exception e) {
            Log.debug("Could not display agent in transcript.", e);
        }
    }
    for (Iterator<Map.Entry<String, List<String>>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, List<String>> entry = iterator.next();
        display(builder, entry.getKey(), getListItem(entry.getValue()));
    }
    builder.append("ctranscript=\n");
    builder.append(ChatTranscriptManager.getTextTranscriptFromSessionID(sessionID));
    String subject = JiveGlobals.getProperty("chat.transcript.subject");
    String from = JiveGlobals.getProperty("chat.transcript.from");
    String to = JiveGlobals.getProperty("chat.transcript.to");
    if (!ModelUtil.hasLength(subject) || !ModelUtil.hasLength(from)) {
        Log.debug("Transcript settings (chat.transcript.subject, chat.transcript.from) are not configured, " + "transcripts will not be sent.");
        return;
    }
    if (ModelUtil.hasLength(to)) {
        emailService.sendMessage("Chat Transcript", to, "Chat Transcript", from, subject, builder.toString(), null);
        Log.debug("Transcript sent to " + to);
    }
    // NOTE: Do not sent to the customer. They will receive a prompt for a seperate chat transcript
    // that does not contain agent information.
    // Send to Agents
    UserManager um = UserManager.getInstance();
    for (Iterator<AgentChatSession> iterator = chatSession.getAgents(); iterator.hasNext(); ) {
        AgentChatSession agentSession = iterator.next();
        try {
            User user = um.getUser(new JID(agentSession.getAgentJID()).getNode());
            emailService.sendMessage("Chat Transcript", user.getEmail(), "Chat Transcript", from, subject, builder.toString(), null);
            Log.debug("Transcript sent to agent " + agentSession.getAgentJID());
        } catch (UserNotFoundException e) {
            Log.error("Email Transcript Not Sent:" + "Could not load agent user object for jid " + agentSession.getAgentJID());
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) TreeMap(java.util.TreeMap) ChatSession(org.jivesoftware.openfire.fastpath.history.ChatSession) AgentChatSession(org.jivesoftware.openfire.fastpath.history.AgentChatSession) Date(java.util.Date) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) AgentChatSession(org.jivesoftware.openfire.fastpath.history.AgentChatSession) UserManager(org.jivesoftware.openfire.user.UserManager) List(java.util.List) EmailService(org.jivesoftware.util.EmailService) SimpleDateFormat(java.text.SimpleDateFormat) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with AgentChatSession

use of org.jivesoftware.openfire.fastpath.history.AgentChatSession in project Openfire by igniterealtime.

the class EmailTranscriptEvent method getChatDuration.

private int getChatDuration(Date start, ChatSession session) {
    long startTime = start.getTime();
    long end = startTime;
    List<AgentChatSession> agents = session.getAgentList();
    for (AgentChatSession chatSession : agents) {
        if (end < chatSession.getEndTime()) {
            end = chatSession.getEndTime();
        }
    }
    return (int) ((end - startTime) / 1000 / 60);
}
Also used : AgentChatSession(org.jivesoftware.openfire.fastpath.history.AgentChatSession)

Aggregations

AgentChatSession (org.jivesoftware.openfire.fastpath.history.AgentChatSession)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ChatSession (org.jivesoftware.openfire.fastpath.history.ChatSession)1 User (org.jivesoftware.openfire.user.User)1 UserManager (org.jivesoftware.openfire.user.UserManager)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 EmailService (org.jivesoftware.util.EmailService)1 JID (org.xmpp.packet.JID)1