Search in sources :

Example 1 with EmailService

use of org.jivesoftware.util.EmailService in project Openfire by igniterealtime.

the class UserInterceptor method sendNotifications.

private void sendNotifications(Packet packet, String packetSender) {
    EmailService emailService = EmailService.getInstance();
    String body;
    if (fromEmail == null) {
        return;
    }
    for (String toEmail : emailNotifyList) {
        body = StringUtils.replace(emailBody, "{packet}", packet.toXML());
        body = StringUtils.replace(body, "{sender}", packetSender);
        emailService.sendMessage(null, toEmail, fromName, fromEmail, emailSubject, body, null);
    }
}
Also used : EmailService(org.jivesoftware.util.EmailService)

Example 2 with EmailService

use of org.jivesoftware.util.EmailService 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 3 with EmailService

use of org.jivesoftware.util.EmailService in project Openfire by igniterealtime.

the class EmailProvider method executeSet.

public void executeSet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);
    Element iq = packet.getChildElement();
    String from = iq.element("fromAddress").getTextTrim();
    String to = iq.element("toAddress").getTextTrim();
    String subject = iq.element("subject").getTextTrim();
    String body = iq.element("message").getTextTrim();
    // Need to replace the \\n for \n to allow for text sending.
    body = body.replace("\\n", "\n");
    String html = iq.element("useHTML").getTextTrim();
    boolean useHTML = false;
    if ("true".equals(html)) {
        useHTML = true;
    }
    String sessionID = null;
    if (iq.element("sessionID") != null) {
        sessionID = iq.element("sessionID").getTextTrim();
    }
    // Handle missing information.
    if (!ModelUtil.hasLength(from) || !ModelUtil.hasLength(to) || !ModelUtil.hasLength(subject) || (!ModelUtil.hasLength(body) && !ModelUtil.hasLength(sessionID))) {
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.not_acceptable));
        workgroup.send(reply);
        return;
    }
    if (ModelUtil.hasLength(sessionID)) {
        ChatTranscriptManager.sendTranscriptByMail(sessionID, to);
    } else {
        EmailService emailService = EmailService.getInstance();
        if (!useHTML) {
            emailService.sendMessage(null, to, null, from, subject, body, null);
        } else {
            emailService.sendMessage(null, to, null, from, subject, null, body);
        }
    }
    workgroup.send(reply);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) PacketError(org.xmpp.packet.PacketError) EmailService(org.jivesoftware.util.EmailService)

Example 4 with EmailService

use of org.jivesoftware.util.EmailService in project Openfire by igniterealtime.

the class ChatTranscriptManager method sendTranscriptByMail.

/**
     * Sends a transcript mapped by it's sessionID.
     *
     * @param sessionID the sessionID of the Chat.
     * @param from      specify who the email is from.
     * @param to        specify the email address of the person to receive the email.
     * @param body      specify header text to use in the email.
     * @param subject   specify the subject of this email.
     */
public static void sendTranscriptByMail(String sessionID, String from, String to, String body, String subject) {
    final ChatSession chatSession = getChatSession(sessionID);
    if (chatSession != null) {
        final StringBuilder builder = new StringBuilder();
        String transcript = chatSession.getTranscript();
        if (ModelUtil.hasLength(body)) {
            builder.append(body);
        }
        builder.append("<br/>");
        builder.append("<table>").append(transcript).append("</table>");
        EmailService emailService = EmailService.getInstance();
        emailService.sendMessage(null, to, null, from, subject, null, builder.toString());
    }
}
Also used : EmailService(org.jivesoftware.util.EmailService)

Aggregations

EmailService (org.jivesoftware.util.EmailService)4 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 Element (org.dom4j.Element)1 AgentChatSession (org.jivesoftware.openfire.fastpath.history.AgentChatSession)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 IQ (org.xmpp.packet.IQ)1 JID (org.xmpp.packet.JID)1 PacketError (org.xmpp.packet.PacketError)1