cs-icon.svg

Salesforce Einstein

The Salesforce Einstein Sidebar Extension analyzes the text content of your entry, and using Einstein’s Language APIs, infers the sentiment or intent behind the content and displays the findings on the sidebar of your entry page.

Einstein Language APIs are categorized into the following:

  • Einstein Sentiment: Analyzes data and classifies the sentiment into positive, negative, and neutral classes.
  • Einstein Intent: Identifies the intent of user data and categorizes it accordingly into user-defined labels.

In this step-by-step guide, we will see how to create the Salesforce Einstein Sidebar Extension in Contentstack. This widget extension makes use of the Einstein Sentiment APIs to infer the sentiments of your content. The steps are as follows:

  1. Generate Einstein Platform Services Account Private Key
  2. Configure Your Lambda function
  3. Deploy Lambda function
  4. Add "Salesforce Einstein" Sidebar Extension extension to your stack
  5. Use the extension
  1. Generate Einstein Platform Services Account Private Key

    In order to use this extension, you will need your Salesforce Einstein Platform Services Account Private key. This Private key will allow you to access the Einstein Language APIs.

    In case you don’t have an account, read the instructions given here to create one.

    On the activation page, download and save the private key (einstein_platform.pem). You can even copy and paste your private key into a text file and name it as per your need.

    You will need this private key file to authenticate the Einstein Language APIs in Step 2 while configuring the Lambda function of your extension in Contentstack.

  2. Configure Your Lambda function

    To protect sensitive information (such as API Key and URL) and avoid Cross-Origin Resource Sharing (CORS) issues, you can use Lambda function for this extension.

    The lambda function provided with the Extension code folder contains all the required files, however, you need to provide additional details such as your private key.

    Note: Refer Step 4 for the source code along with the lambda function of the Salesforce Einstein extension.

    To provide additional details to your lambda function, perform the steps given below:

    1. Navigate to your lambda function folder through a Terminal and install npm:
      npm install
      
      This downloads the required node modules within your lambda function.
    2. Open the private_key.json file within your lambda function folder and replace the existing content with the content of the private key that you extracted in Step 1.
    3. After that, zip your project file.

      Note: If you are using Linux, use the zip -r index.zip * command in your lambda code folder to zip it.

  3. Deploy Lambda function

    When creating your Lambda function in AWS Lambda, upload your project zip file. Select 8.10.0 as the Node.js version.

    In the Environment Variables section, enter the credentials against the variables as follows:

    ACCOUNT_ID = Your_Einstein_Platform_Account_ID
    

    Note: Please ensure that these are added exactly as shown above, else your lambda function will not work.

    Under the Configuration section of your lambda function, add an API Gateway trigger. You will get an API Gateway URL, like this, https://abcde1234.execute-api.us-east-1.amazonaws.com/default/contentstack-google-analytics-widget.

    Store this URL, as you will need this while configuring the extension in the next step.

    For additional security, you can configure an API Key for the API Gateway trigger and use this API Key when configuring your lambda function.

  4. Add "Salesforce Einstein" Sidebar Extension to your stack

    To add this Sidebar Extension to your stack, log in to your Contentstack account and perform the following steps:

    1. Go to your stack and click on the “Settings” icon on the left navigation panel.
    2. Click on Extensions. You can also use the shortcut keys “alt + X” for Windows OS users, and “option + X” for Mac OS users to access the extensions menu.
    3. Click on the + New Extension button on the top-right corner and select Create new
      Salesforce_Einstein_1_highlighted.jpg

    4. Select the extension type as Sidebar Extension.Salesforce_Einstein_2_highlighted.png
    5. You will be led to the Create New Extension details page where you need to enter details in the fields as given below:
      • Title: Provide a suitable title. For example, Salesforce Einstein.
      • Hosting method: Select Hosted on Contentstack. As soon as you do this, you will see the ‘Extension Source Code’ field below.
      • Extension Source Code: In this field, you need to enter the extension code. If Extensions are part of your plan, contact our Support team to get the code for the extension.
        The support team will provide you with the source code (src file). Copy the code from the index.html file located in the root folder and paste it in the "Extension source code" field.
      • Config Parameters: Enter the configuration details for the extension. Here, you need to mention the AWS API gateway URL for the lambda function (in the ‘url’ parameter) and (if enabled for secure access) the API key.
        {
            "url": "https://abcde1234.execute-api.
                us-east-1.amazonaws.com/default/
                salesforce-einstein-widget",
            "X-api-key": "SSS111Sss1ssSSsssS11s11SS11SS"
        }
        
        
      • Scope: You can choose to incorporate this Sidebar Extension in either All Content Types or Specific Content Types. Selecting the latter option displays a list of content types from which you can select the required ones.
    6. Click Save. This will create your Sidebar Extension.

    Now, let’s understand how to use this Sidebar Extension in your entries.

  5. Use the extension

    Once you have added your Sidebar Extension, you can use it in your entries of the selected content type(s). Let’s look at the steps involved in using the Sidebar Extension.

    1. Go to your stack and click on the “Entries” icon on the left navigation panel.

    2. Select the content type for which you have enabled the Sidebar Extension.

    3. Click on an entry. You will see the “Sidebar Extensions” icon on the right-hand side of the page.
    4. Click on it to expand the sidebar and select Salesforce Einstein from the drop-down menu
      Salesforce_Einstein_3_highlighted.jpg
      The selected Sidebar Extension expands on the sidebar.
    5. Under Select model, you will see the Einstein Sentiment option selected by default (screenshot in Step 5).
    6. Click on the Field dropdown and select the field that you want to analyze, in this case, Content.
    7. Click on Run. You will sentiment probability of the content as follows:Salesforce_Einstein_4_no_highlight.png

Optional Step - Add Einstein Intent Model

In the above sections, we successfully added the Salesforce Einstein Sidebar Extension's Sentiment model that used the Einstein Sentiment APIs.

Now, to use the Einstein Intent API, you need to create a model that you need to first train in order for it to analyze your text and infer what the content intends to.

After creating your Salesforce Einstein Platform Services Account, the additional steps that you need to perform to create your Einstein Intent Model are as follows:

  1. Define Labels for Your Intent Model
  2. Generate Authorization Token
  3. Create Your Dataset
  4. Create Data Model
  5. Add Intent Model Configuration Details
  6. Use the Einstein Intent Model
  1. Define Labels for Your Intent Model

    In this step, you will define the labels for your intent model. The intent model will use these labels to categorize your data. For each label, you need to gather text data in a file as per your requirement.

    The Einstein Language APIs support data in these file formats: .csv (comma-separated values), .tsv (tab-separated values), and .json. So, the format of your text data file should be in these formats.

    For more information, refer the instructions given in the quick start guide.

  2. Generate Authorization Token

    Next, you need to generate the JSON Web Token (JWT) to access the Einstein Platform Services APIs. Open the Einstein Platform Services Token generation page, use the private key you downloaded after creating your account, and perform the steps mentioned in the Set Up Authorization page.

  3. Create Your Dataset

    Once you have gathered your data and generated the OAuth token, it’s time to create and host your dataset.

    To upload your dataset, run the POST API call: https://api.einstein.ai/v2/language/datasets/upload

    Add the following parameters and replace <TOKEN> with your JWT token and <PATH_OF_YOUR_DATA_FILE> with the path of the data file that you created above:

    ParametersValues
    Header
    • Authorization: Bearer <TOKEN>
    • Cache-Control: no-cache
    • Content-Type: multipart/form-data
    Body
    • type: text-intent
    • path: <PATH_OF_YOUR_DATA_FILE>

    Tip: You can try the call manually in any REST API client, such as Postman.

    This is the Einstein Intent API call that will create and host your dataset. For more information, refer the steps given here.

    In the response body of this call, you will find your Dataset ID. We will use this ID value to generate the Model ID in the next step.

  4. Create Data Model

    Next, you need to train your dataset and create a model. You will get the model ID that will be used to configure the extension.

    Run the POST API call: https://api.einstein.ai/v2/language/train

    Add the following parameters and replace <TOKEN> with your JWT token and <DATASET_ID> with the dataset ID retrieved in the above step:

    ParametersValues
    Header
    • Authorization: Bearer <TOKEN>
    • Cache-Control: no-cache
    • Content-Type: multipart/form-data
    Body
    • name: Your_Model_name
    • datasetId: <DATASET_ID>

    Tip: You can try the call manually in any REST API client, such as Postman.

    In the response body of this call, you will find your Model ID. We will use this value while configuring your extension in Step 8.

    For more information, refer the steps given here.

  5. Add Intent Model Configuration Details

    In the Salesforce Einstein Sidebar Extension details page, enter the Model ID of your Intent Model and the Model Name.

    {
        "intentModels": [
            {
                "modelId": "RRRR2CCCC2KKKKKKKK2CCCC",
                "modelName": "User-defined Model Name"
            },
            {},
        …]
    }
    

    Note: You can create multiple such models and add their model IDs in the configuration settings of your Salesforce Einstein Sidebar Extension.

  6. Use the Einstein Intent Model

    Once you have added your custom Einstein Intent Model, you can use it in your entries of the selected content type(s).

    Let’s look at the steps involved in using the Einstein Intent model in your entry page.

    1. Under Select model, select Einstein Intent.
    2. In the Select Intent Model dropdown, select the model that you created (e.g., Demo Model).
    3. In the Field drop-down, select the field (e.g., Content) of which you want to analyze the intent and click on Run.
    Once your extension is configured see the probability of the Sentiment and Intent Model’s labels that your content fits in.Salesforce_Einstein_5_no_highlight.gif
Was this article helpful?
^