ABSYZ ABSYZ

  • Home

    Welcome to ABSYZ

  • 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

Google Assistant Integration with Salesforce – Part 1

Home / Article & Blogs / Apex / Google Assistant Integration with Salesforce – Part 1

Google Assistant Integration with Salesforce – Part 1

By Pushmitha Babu inApex, Integration, REST, Salesforce

Everyone has come across Google Assistant which help people in communication that is a Google’s voice-controlled AI smart assistant. Google Assistant is integrated with Salesforce, to make communication easy and reduce the work. Here we do a simple integration with Salesforce to create, delete and fetch details of a particular record.

First, we should sign up Dialogflow.api with your Gmail account. Click on signup for free. You will be redirected to a page asking for the sign in with Google. Sign up with existing Gmail account and you can see the redirected page that logins into dialogflow.com. And create an agent (a project) for a custom development.

Four terminologies to know:

  1. Intent
  2. Entities
  3. Fulfillment
  4. Integrations

Intent:

Intent maps the user input commands with related actions for your app. Intent allows the users to specify what they wanted to do and figures out what activity matches what was said. Click on Intent that is on your left and click on create new Intent as shown below.

Absyz
Absyz

Entities:

Entities are used for extracting parameter values from the user inputs and any important data that you wanted to get from the user, you will create the corresponding entity. It is not necessary to create all possible concepts as entities, entities are created only for the actionable data that is needed. To create an Entity check the below images.

Absyz
Absyz

Fulfillment:

Fulfillment allows us to decide our responses to our conversations. It is a conversational interface between your application and the logic to fulfill the action. For example, we integrate with Salesforce and Google Assistant. We need to create a site from salesforce org as shown below (Site -Custom URL is used because we need to get a public access to the apex class from our org). Enter the domain URL in Fulfillment Webhook URL and append the URL with the rest resource name.

Absyz cloud
Absyz cloud

Integration:

Integration is to use Dialogflow’s Actions on Google integration to test your Dialogflow agent in the Actions on Google simulator. Click on Integration in the left menu and select Integration Settings. Enable Auto-Preview changes as the dialogflow will propagate changes to the Actions Console and Assistant Simulator automatically. Now you are all set to test your custom app.

Absyz
Absyz

We create an apex class with the annotation @RestResource in the class because we expose an apex class as a REST resource. If we use RestResource, that particular class should be defined as global. In the brackets, we provide the rest resource name. We are extracting the data from the JSON so you can get the key terms whether you want to insert, update or delete records.

[sourcecode language=”java”]
@RestResource(urlMapping=’/Dialogflow’)
global class restCall {
@HTTPPost
global static string createRecords(){
//response from Google Assistant as a JSON
String request = RestContext.request.requestBody.toString();
//deserialize the JSON
mapurl orp = (mapurl)JSON.deserialize(request, mapurl.class);
string str=orp.result.metadata.intentName;

//check whether it is an account
if((str.contains(‘New’)||(str.contains(‘Add’)) ||(str.contains(‘Create’))) &&(str.contains(‘Account’))){
account acc= new account();
acc.name=orp.result.parameters.Name;
acc.Phone=orp.result.parameters.phone;
acc.Email__c=orp.result.parameters.Email;
insert acc;
}
//check whether it is a contact
else if((str.contains(‘New’)||(str.contains(‘Add’)) ||(str.contains(‘Create’))) &&(str.contains(‘Contact’))){
contact con= new contact();
con.LastName = orp.result.parameters.Name;
con.Phone = orp.result.parameters.phone;
con.Email = orp.result.parameters.Email;
insert con;
}
String s= ‘Success’;
return s;
}
//wrapper to get the values from the JSON
global class mapurl{
global result result;
}
global class result{
global parameters parameters;
global metadata metadata;
global string resolvedQuery;
}
global class parameters{
global String Phone;
global String Name;
global String Email;
}
global class metadata{
global String intentName;
}
}
[/sourcecode]

On click of Test from Integration setting, it will redirect to a page called simulator. Google allows you to test in a browser without an actual google home device named Google Home Web Simulator. You have not yet named your custom App so initially, the command will be: “Talk to Test app”. The setup to create your application name and use the app live will be continued in our next blog.

DialogflowGoogle AssistantGoogle Assistant IntegrationIntegration with Google AssistantIntegration with SalesforceIntent creation in Dialogflow
40
Unlike this post
8 Posts
Pushmitha Babu

Search Posts

Archives

Categories

Recent posts

Service Cloud for customer delight

Service Cloud for customer delight

Salesforce Financial Services Cloud

Salesforce Financial Services Cloud

Salesforce Field Service Lightning

Salesforce Field Service Lightning

Connecting the dots with Customer 360

Connecting the dots with Customer 360

Customer delight with Commerce Cloud

Customer delight with Commerce Cloud

  • Previous PostHighlights of Winter'19 Release Notes: Part I
  • Next PostHighlights of Winter'19 Release Notes: Part II

Related Posts

REST API call from Einstein Analytics Dashboard
Apex REST Salesforce Salesforce Einstein Wave Analytics

REST API call from Einstein Analytics Dashboard

Create/Update Salesforce Picklist definitions using metadata API
Integration Metadata API Salesforce

Create/Update Salesforce Picklist definitions using metadata API

7 Comments

  1. Google Assistant Integration with Salesforce – Part 2 – ABSYZ
    Reply
    7 September 2018
    Reply
  2. Kishan Kumar
    Reply
    25 January 2019

    i am getting this error MalformedResponse Webhook error (206).
    can you help me ?

    Reply
  3. Rama
    Reply
    19 May 2019

    Awesome. Thanks for sharing

    Reply
  4. suraj bahale
    Reply
    23 May 2019

    Hello sir, I am having this error, will you please help me to resolve it,

    Webhook call failed. Error: Failed to parse webhook JSON response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $.

    Reply
  5. kumar
    Reply
    23 May 2019

    I try to create an account using “My test app” but I get the error as – “My test app isn’t responding right now. Try again soon.”

    Reply
  6. Upendra Dodia
    Reply
    27 November 2019

    Hey There,

    I would like to know the privacy model of our data if we integrate Google Assistance with Salesforce using dialogflow.api.

    Would appreciate your response.

    Regards

    Reply
  7. Becky Williams
    Reply
    16 April 2020

    what is the rest resource name here? can you elaborate?

    Reply

Leave a Reply (Cancel reply)

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

*
*

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

ABSYZ Software Consulting Pvt. Ltd.
USA: 49197 Wixom Tech Dr, Wixom, MI 48393, USA
M: +1.415.364.8055

India: 6th Floor, SS Techpark, PSR Prime, DLF Cyber City, Gachibowli, Hyderabad, Telangana – 500032
M: +91 79979 66174

Copyright ©2020 Absyz Inc. All Rights Reserved.

youngsoft
Copy