{{announcement.body}}
{{announcement.title}}

Axway Integration Builder in a Sentiment Analysis Application, Part 2

DZone 's Guide to

Axway Integration Builder in a Sentiment Analysis Application, Part 2

In the second part of this tutorial, we put the sentiment analysis application to work to try to detect sentiment in a Salesforce Opportunity.

· Integration Zone ·
Free Resource
In part 1 of this blog post series, we introduced sentiment analysis and how we can use Integration Builder to extract the text from our data source, make a call to Amazon Comprehend natural language processing (NLP) service, through API Builder, to determine the sentiment and send a notification to the appropriate stakeholder in Microsoft Teams. In part 1, we looked at the Net Promoter Score (NPS) survey example. In this post, we'll look at detecting the sentiment in a Note in a Salesforce.com Opportunity.

Setup

The diagram below illustrates the flow of data:

Data flow
  • We'll configure an Integration Builder Salesforce connector for Webhook events, monitoring the Notes object
  • We'll create a flow that is triggered on Events
  • We'll use the API Builder Detect Sentiment connector we created in part 1 to detect the sentiment of the note
  • If the sentiment is determined to be negative or mixed, we'll send a notification to Microsoft Teams, as shown below:
Microsoft Teams notification

Note that the information in the notification contains the sentiment, the contents of the note, the account name, and a link to the note.

Integration Builder Salesforce Sales Cloud Connector

Follow the instructions here to configure Webhooks in your Salesforce account.

When you're done, instantiate a Salesforce Sales Cloud connector in Integration Builder and make sure you enable events and select Webhook (instead of polling) and enter Note in the Object to Monitor for Changes as shown below:

Connector configuration

Note that you don't need to enter the Webhook URL. Integration Builder will populate that field automatically when you authenticate.

Integration Builder Flow

In this section, we'll create our Integration Builder flow. You can download the flow here.

The resulting flow is shown below:

Integration builder flow

  • Create a new flow and select Event as the trigger type. I entered crm as the connector variable name during creation. Refer to this post if you don't recall how to accomplish this.
  • Add two value variables to your flow template:
    • crmBaseAddress - this is the base address of your Salesforce instance
    • msTeamsWebhookURL - this is the URL of your MS Teams Webhook
Shell
 




x


 
1
done(trigger.event.eventType != 'DELETED');


Add a JS Script step, prepareGetAccount, with the following content:

This will ensure that we only notify on new or edited notes and not deleted notes.

Shell
 




xxxxxxxxxx
1


 
1
let url = '/accounts/'+trigger.body.message.raw.objects[0].AccountId;
2
done({url:url});


  • Add a Connector API Request step, getAccount, as follows:

getAccount API request step

This will create the URL (/accounts/{accountId}) for retrieving the account information associated with the Note. We are doing this so that the notification we send to Teams will have the name of the account that the note is associated with.

  • Add a JS Script step, prepareGetSentiment, with the following content:
Java
 




xxxxxxxxxx
1


1
let query = {
2
  text: trigger.body.message.raw.objects[0].Body
3
}
4
 
           
5
done({query: query});


Recall that when I created my flow template, I named the connector variable crm

  • Add a Connector API Request, getSentiment, as follows:

getSentiment Connector API Request

This gets the note's text from the trigger and creates a query parameter for my API Builder sentiment API call as we did in part 1.

  • Add a JS Filter step, shouldNotify with the following content:

This will retrieve the sentiment for the note. Refer to part 1 for details of the returned data.

done(steps.getSentiment.response.body.Sentiment === 'NEGATIVE' || steps.getSentiment.response.body.Sentiment === 'MIXED');
  • Add a JS Script step, prepareNotifyTeams, with the following content:
Java
 




xxxxxxxxxx
1
32


 
1
var sentiment;
2
if(steps.getSentiment.response.body.Sentiment === 'NEGATIVE') {
3
  sentiment = 'Negative';
4
} else if(steps.getSentiment.response.body.Sentiment === 'MIXED') {
5
  sentiment = 'Mixed';
6
} else {
7
  sentiment = 'Unknown';
8
}
9
 
           
10
let body = {
11
    "@type": "MessageCard",
12
    "@context": "http://schema.org/extensions",
13
    "themeColor": "0076D7",
14
    "summary": "CRM Opportunity Note Sentiment Notifier",
15
    "sections": [{
16
        "activityTitle": "CRM Opportunity Note Sentiment Notifier",
17
        "activitySubtitle": "'"+trigger.body.message.raw.objects[0].Body+"'",
18
        "facts": [{
19
            "name": "Sentiment",
20
            "value": sentiment
21
        },{
22
            "name": "Account",
23
            "value": "["+steps.getAccount.response.body.Name+"]("+config.crmBaseAddress+trigger.body.message.raw.objects[0].AccountId+")"
24
        },{
25
            "name": "Note",
26
            "value": "[Click to view note]("+config.crmBaseAddress+trigger.event.objectId+")"
27
        }],
28
        "markdown": true
29
    }]
30
}
31
 
           
32
done({body: body});


This will ensure that we only send a notification to Teams if the sentiment is Negative or Mixed.

  • Finally, add an HTTP Request step, notifyTeams, as follows:

notifyTeams HTTP Request Step

  • Create an instance of your flow as follows:

Flow Instance Settings

This creates the body for our call to the MS Teams webhook for a nicely formatted notification.

Test Your Flow

Create a note in a Salesforce opportunity and enter a negative sentiment: "Prospect mentioned that support was poor during the POC" as shown below:



You should get a notification in MS Teams as follows:

Notification in MS Teams


Summary

In this blog post, we saw how Integration Builder and API Builder can be used together with AWS Comprehend Natural Language Processing service to implement a sentiment analysis application to alert Sales via MS Teams. This enables a company to be more proactive in analyzing CRM Notes and ultimately the sales pipeline.

Topics:
amazon comprehend, axway, integration, salesforce, sentiment analysis

Published at DZone with permission of Leor Brenman , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}