Automatically Tag Conversations in Front using Machine Learning

Automatically Tag Conversations in Front using Machine Learning

In this blog post, I'd like to show you how you can automate business workflows (either for support, sales or operations) that involve customer conversations by combining three tools: Front, MonkeyLearn, and Zapier.

Front will help us gather and manage conversations with customers from various different channels. MonkeyLearn will apply machine learning: automatically tagging conversations based on the content. Zapier will be the glue that sticks everything together.

Let's do it!

About Front

Front is a beautiful application that allows your team to manage a shared inbox. Front is redesigning email for business, where collaboration is key.

Some of Front's top features:

  • Centralize your communication channels into one place (e.g., email, texts, social and more).
  • Collaborate with your team behind-the-scenes (i.e., assign, comment on messages).
  • Handle messages faster with powerful automations (e.g., set up rules to automatically assign, remind and respond to messages based on tags and keywords).
  • Generate performance analytics and integrate with the rest of your business apps.

Front's set of features is a nice fit for multiple use cases; support, sales, and operations being the most frequent.

Why are Tags and Rules so important in Front?

Tags are labels to help you keep track of conversations related to a given topic. Team Tags are visible to everyone on your Team. In analytics, admins can create reports based on tags. You can click the +tag button at the top of the message to apply a tag.

Rules save you time by automating repetitive processes. For example, you can create a rule to assign incoming messages to specific teammates, add tags to certain types of conversations, or always reply with a canned response.

By combining tags and rules in Front you can automate many of your workflows. These rules can help you handle repetitive tasks to save time and increase your team's efficiency:

  • Automatic routing to assign messages to your team members based on tags such as topic or issue type.

  • Automatic prioritization to enrich incoming messages with additional context to help prioritize or triage based on tags such as urgency, sentiment or topic.

  • Automatic responses to trigger auto responses based on tags such as intent, issue type, topic, urgency, and sentiment.

  • Consistent analytics to build reports within Front or using external BI tools, with the aim to detect:

    • Trends on topics, regular bug reports, issues, requests, product aspects to improve, etc.
    • How sentiment in your user base is evolving.
    • Trending keywords and to discover potential new topics or features.

Why is Tagging a pain?

Tagging is important and has many benefits but at the cost of time and effort. Tagging every single message that comes in can be a pain for many teams:

  • It takes time; something your team is doing instead of actually replying to messages.
  • It must be consistent, ensuring the same criteria across your team as it scales, which is not easily done.
  • It is repetitive and boring, and it's a part of the job that can lead to burnout.

The Solution

In MonkeyLearn we believe that manual repetitive tasks that involve text processing should be done by machines. By combining text classifiers and text extractors, MonkeyLearn can turn unstructured text data (such as emails, texts, and social media) into structured data, i.e., tags. Those tags can then be used to automate your business workflows as described above. Picture each MonkeyLearn model (classifier or extractor) as a dedicated robot working just for you, handling the repetitive stuff while you focus on the strategic.

Benefits

  • Save time by avoiding manual processing.
  • Ensure consistent tagging criteria without errors, real-time, 24/7.
  • Have a quick and consistent context on each conversation.
  • Make your team more efficient.

How Does it Work?

So far this sounds beautiful, doesn't it? Let's jump right in and show you how to set it up.

Decide on the kinds of tags you want to assign to messages

To figure out how you want to tag messages, you can look at some of MonkeyLearn's premade models (such as sentiment, urgency, keywords and more) or build your own custom models (where you define your own set of tags, and train a custom classifier or extractor to recognize them).

Connect MonkeyLearn to Front to tag every single message

One of the quickest ways to connect Front with MonkeyLearn is through Zapier, which will allow us to create a zap with the following steps:

  1. Set Trigger for when a "New Inbound Message" comes into Front. Then connect your Front account to Zapier (admin access in Front is required).
  1. Add an Action from MonkeyLearn to Extract the relevant content from the message using the Email Cleaner model, this will remove last replies and email signatures. This is important because we will use the cleaned text for analysis in the next steps.
  1. Add any additional classifiers or extractors as desired. For example, you could add a Sentiment Analysis model (Classifier) to detect if the message has a positive, negative or neutral sentiment (useful to detect priority). As you can see below, the text input will be both the message subject from step 1 and the cleaned message body from step 2:
  1. Add a topic classifier. As an example, you can check out the E-commerce support classifier that is a generic way of determining what a message is about. You can build a custom classifier with tags that apply to your unique business context as well. This is useful to automate routing based on topic and skills. As you can see below, we selected a particular classifier by specifying a custom value for the classifier id.
  1. Finally, the last step is to add a Python code snippet to send the tags to Front through the Front API. Not a technical user? Not to worry, it's easy to add and you'll be able to tell everyone you're a hacker. I promise :)

First, you have to add three inputs, and fill them with the following info:

  • convo_id, which is the id of the triggered Front conversation from step 1.
  • write_key, which is your API token from Front that will allow Zapier to communicate with the Front API (you can get your API token here).
  • tags, which are the tags predicted by the models in each of the previous steps. If you have more than one model, just concatenate the results separated by a comma ",".

Then, with the above filled out, you must copy the following Python code snippet in the Code field:

from datetime import date, datetime
import json
from requests import sessions

_session = sessions.Session()

class Serializer(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, (date, datetime)):
            return obj.isoformat()
        return json.JSONEncoder.default(self, obj)

class APIError(Exception):
    def __init__(self, status, code, message):
        self.message = message
        self.status = status
        self.code = code

    def __str__(self):
        msg = "[Error] {0}: {1} ({2})"
        return msg.format(self.code, self.message, self.status)

def patch(convo_id, tags, write_key):
    """Post the `kwargs` to the API"""
    
    data = {
        'tags': tags
    }
    url = 'https://api2.frontapp.com/conversations/' + convo_id
    data = json.dumps(data, cls=Serializer)
    headers = {
        'Content-type': 'application/json',
        "Accept": "application/json",
        "Authorization": 'Bearer ' + write_key
    }
    res = _session.patch(url, data=data, headers=headers, timeout=15)

    if res.status_code == 200 or res.status_code == 204:
        return "[Response]: OK"

    try:
        payload = res.json()
        raise APIError(res.status_code, payload['code'], payload['message'])
    except:
        raise APIError(res.status_code, 'unknown', res.text)
        
res = patch(input_data['convo_id'],
            input_data['tags'].split(","),
            input_data['write_key'])

output = [{'res': res}]

When your zap is set up and running, this is what a Front message will look like. You will see the automatically populated tags on the top of every message. Cool!

Set up rules in Front to automate your workflows based on tags

These are some cool rules that you can set up in Front to trigger when tags are automatically populated:

Routing

Auto Responders

You can also get some cool analytics based on your tags that can help spot trends in your messages and conversations:

Final Thoughts

With the above, we have quickly created a way to automate tagging incoming messages in Front using machine learning. Based on these tags, you can trigger even more automations within Front, such as assigning convos or replying with canned responses. Feel free to add, edit and experiment with more models and rules, and reach out to me if you have any questions or comments. Happy hacking!

Raúl Garreta

August 17th, 2018

Posts you might like...

MonkeyLearn Logo

Text Analysis with Machine Learning

Turn tweets, emails, documents, webpages and more into actionable data. Automate business processes and save hours of manual data processing.

Try MonkeyLearn
Clearbit LogoSegment LogoPubnub LogoProtagonist Logo