ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Einstein Intent and Einstein Sentiment Analysis on Facebook Posts

Home / Article & Blogs / Apex / Einstein Intent and Einstein Sentiment Analysis on Facebook Posts
By Team ABSYZ inApex, Integration, REST, Salesforce Einstein, Trigger

Einstein Language

Einstein Language Is used to build natural language processing into your apps and unlock insights within text. Einstein Language contains two NLP services:

  • Einstein Sentiment
  • Einstein Intent
Einstein Intent

—Categorize unstructured text into user-defined labels to better understand what users are trying to accomplish. Leverage the Einstein Intent API to analyze text from emails, chats, or web forms to

  • Determine which products prospects are interested in, and send customer inquiries to the appropriate sales person.
  • Route service cases to the correct agents or departments, or provide self-service options.
  • Understand customer posts to provide personalized self-service in your communities.
Einstein Sentiment

—Classify the sentiment of text into positive, negative, and neutral classes to understand the feeling behind text. You can use the Einstein Sentiment API to analyze emails, social media, and text from chat to:

  • Identify the sentiment of a prospect’s emails to trend a lead or opportunity up or down.
  • Provide proactive service by helping dissatisfied customers first or extending promotional offers to satisfied customers.
  • Monitor the perception of your brand across social media channels, identify brand evangelists, and monitor customer satisfaction.

 

Lets suppose I have a Facebook Page for an E-Commerce site. If any user sharing their feedback through posts or comments on the page, We can retrieve the post and comments to Salesforce and find Intent of the post and the Sentiment of the comments.

This can be achieved by following these steps:

step 1. Create a Facebook page.

step 2. Create a Facebook app using Facebook Developers account.

To Connect with Facebook we Should use Graph API, To use Graph API we need to Create a Facebook Developers account using Facebook credentials,

To create a Facebook app

  • login to https://developers.facebook.com/
  • click on My Apps -> Add a New App.

Enter basic information and make the App Live, If the app is not Live we can’t use it for Communicating with Facebook.

Now click on Tools & Support and go to Graph API Explorer, here we can generate Access token and test the app.

Steps to create Access token:
  • select you app from Application drop down.
  • click on Get Token and select Get User Access Token.
  • select the permissions required and click Get Access Token.
  • To get Page Access token click on Get Token and select you Page from Page Access Tokens.
  • Now you can see your page name on the drop down list, click on that and select Request publish_pages.

 

step 3. Create an Object on Salesforce to save posts and their comments.

Create an object with fields to store posts, comments, Sentiment, Intent.

step 4. Create remote site setting on Salesforce.

Go to Remote Site Settings -> New Remote Site

enter site name, remote site URL as https://graph.facebook.com , check Active checkbox and Save.

step 5. Make a callout to Facebook to retrieve posts and comments.

In Einstein_Facebook class we are getting post and comments from Facebook, and extracting posts and comments from returned JSON and creating records.

 

[sourcecode language=”java”]
public class Einstein_Facebook {

public static void sendRequest(){

//getting accesstoken from custom lable.
String accessToken = Label.Facebook_Access_Token;
HttpRequest request = new HttpRequest();
request .setEndpoint(‘https://graph.facebook.com/v2.12/391648194596048?fields=posts{message,comments,type}&access_token=’+accessToken);
request .setMethod(‘GET’);
//Making request
Http http = new Http();
HTTPResponse response= http.send(request );
//getting post and comments in response.
String data=response.getBody();

//getting post and comments from JSON rceived in response.
List line=data.split(‘,’);
List posts=new List();
List postAndComments=new List();
for(String l:line){
posts.add(l.substringBetween(‘{“message”:”‘,'”‘));
string substring=l.substringBetween(‘”message”:”‘,'”‘);
if(substring!=null)
postAndComments.add(substring);
}
//creating a Map of posts and comments.
Map PostComments =new Map();
for(String p:posts){
if(p!=null){
List empty=new List();
PostComments.put(p,empty);
}
}
String key;
Listcomments=new List();
for(string messages : postAndComments){

//checking if the message exists in posts and adding as key.
if(messages!=null){
if(PostComments.containsKey(messages)){
key = messages ;
}

//else adding to comments to corresponding post.
else{
comments=PostComments.get(key);
comments.add(messages);
PostComments.put(key, comments);
}
}
}

//querying all the Posts and comments
List existingPosts = [SELECT id,Comments__c,Posts__c FROM Einstein_Facebook__c];
List listDelete = new List();
for(Einstein_Facebook__c Post:existingPosts){

//checking if post already exists and adding to a list.
if(PostComments.containsKey(Post.Posts__c)){
listDelete.add(Post);
}
}

//deleting the list.
delete listDelete;

List  PostCommentList=new List();
//Iterating through Map to create records.
for(string post : PostComments.keySet()){
for(string comments : PostComments.get(post)){
Einstein_Facebook__c Facebookcomment=new Einstein_Facebook__c();
Facebookcomment.Posts__c=post;
Facebookcomment.Comments__c=comments ;
PostCommentList.add(Facebookcomment);}
}

//Inserting List of  posts and comments.
insert PostCommentList;

}

}
[/sourcecode]

step 6. Write a trigger to get Intent and sentiment of post and comments.

Trigger to fire after insert on Facebook posts and comments:

[sourcecode language=”java”]

trigger EinsteinFB_Trigger on Einstein_Facebook__c (after insert) {    For(Einstein_Facebook__c post : Trigger.New)

{

String  postId = post.Id;

Einstein_Handler.getProbabilityforFB(postId);

}

}

[/sourcecode]

Handler for the trigger:

Here we are using EinsteinVision_Admin EinsteinVision_Sentiment classes to get Intent and Sentiment of posts and comments which we explained in detail in our previous blog on Einstein Intent and Einstein Sentiment.

[sourcecode language=”java”]
global class Einstein_Handler{

@future(callout=true)
Public static void getProbabilityforFB(String body){
Einstein_Facebook__c fd=[select Posts__c, Comments__c from Einstein_Facebook__c where id=:body];

String intentLabel = EinsteinVision_Admin.getPrediction(fd.Posts__c);
String sentimentLabel = EinsteinVision_Sentiment.findSentiment(fd.Comments__c);

fd.Feedback_Type__c=intentLabel;
fd.Sentiment__c=sentimentLabel;
update fd;
}

}
[/sourcecode]

This is a report to show analysis of Facebook post and comments.

facebook report

Einstein IntentEinstein LanguageFacebookSalesforceSentiment Analysis
141
Like this post
127 Posts
Team ABSYZ

Search Posts

Archives

Categories

Recent posts

Meet OmniStudio – Revolutionize Your Creative Work

Meet OmniStudio – Revolutionize Your Creative Work

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

  • Previous PostEinstein Intent Analysis Using Einstein Language on Salesforce Chatter
  • Next PostLightning Components As Flow Screens

Related Posts

TABLEAU CRM: Add Relative and Dynamic URLs in Link Widgets
Salesforce Einstein Salesforce Releases Tableau

TABLEAU CRM: Add Relative and Dynamic URLs in Link Widgets

PLATFORM EVENTS IN SALESFORCE
Integration Salesforce

PLATFORM EVENTS IN SALESFORCE

Integrate SharePoint with Salesforce using Microsoft Graph API
Apex Integration Salesforce

Integrate SharePoint with Salesforce using Microsoft Graph API

Tableau CRM: Add action buttons on Table without XMD
Salesforce Salesforce Einstein Tableau

Tableau CRM: Add action buttons on Table without XMD

2 Comments

  1. Jagadish Lutimath
    Reply
    26 March 2018

    Hi,

    I am getting Error: Compile Error: Unexpected token ‘List’. at line 17 column 10

    Is this code works just by copy and pasting?

    Reply
    • shruthimikkilineniabsyzcom
      Reply
      26 March 2018

      Please check if you are getting response in line 14, keep a debug statement and check.

      Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT