In this competitive world, it is very important to understand the linguistic tone of a customer so that we can decide whether we need to respond to the customer immediately.

These days, customer satisfaction is more important to a sales manager or representative. A sales manager or representative may want to understand the linguistic tone from his customer's sent mail. For example, when a customer sends a mail to a sales manager or representative, the sales manager or representative may want to understand the tone of the mail so that the sales manager or representative can decide on further actions. This powerful feature can be achieved by leveraging IBM Watson Tone Analyzer service.

Here we want to show how a Salesforce user (sales manager or representative) can understand the tone of his customer's sent mail by integrating Salesforce and IBM Watson Tone Analyzer service using Mule Soft ESB.

Prerequisites

A custom contact field CutomerTone__c on Salesforce. See here to create a custom field on any Salesforce object.

Flow Steps

Receive mail from the configured mailbox using Mule IMAP connector. Once mail is received, the current Mule Message contains email body as payload and the customer mail address as an inbound header fromAddress.

Enrich the current Mule Message with the Salesforce contact ID corresponding to the fromAddress retrieved above. The enriched Mule Message now contains a flow variable contactId that holds the Salesforce contact ID corresponding to the customer mail address.

Post the mail body held in the current payload to the IBM Tone Analyzer service. The Tone Analyzer service gives a JSON response representing the tone of the mail in the case of success. See here for a sample response.

Calculate the tone based on the rule described here. As of now, we are interested only in Emotion Tone. The Emotion Tone has three children tones named Cheerfulness, Negative, and Anger. Each of these tones has an attribute called normalized_score representing the value of the tone. If the sum of normalized_scores of Negative and Anger tones is greater than Cheerfulness tone, then we consider the tone of the customer to be Angry otherwise Normal.

Update the Salesforce Contact corresponding to the contact ID held in the flow variable contactId with the tone calculated above.

Tone-Analyzer Flow

Below is the main flow that receives an incoming mail from a customer.

This sub-flow finally returns a contact ID corresponding to the customer mail address. In the tone analyzer flow, we use an enricher to enrich the message with the contact ID retrieved from Salesforce and this contact id is stored in a flow variable #[flowVars.contactId]

Get-Tone Flow

This sub-flow gets the tone of the mail from the customer. It posts the mail body received from the customer to IBM Watson Tone Analyzer and retrieves the linguistic tone of the mail.

The above flow applies some logic on the tone response retrieved from the get-tone flow. This logic is encapsulated in the Mule expression-component. This logic finally gives a JSON payload, represents the tone either Angry or Normal, and is updated to Salesforce contact's custom field CustomerTone__c.

The corresponding Dataweave transformation that transforms tone payload to such a payload corresponds to Salesforce Contact update is shown below: