Smart Plugs:Smart Plugs are custom scripts that help you customize your inbox page according to your needs. Smart Plugs are nothing but custom integrations that are used to pull data out of your systems, CRMs, or any other third party applications using the user's data (like email, phone etc). This extracted information is available to you without taking the steps to get it from users. A smart plug will look like this to an agent:


To create a smart plug:

  • Go to Settings -> Smart Plugs




  • Click the + Add Smart Plug from the top right corner of the screen
  • A dialog box pops up with the title, description and custom script fields




  • Enter a Title and Description for the Smart Plug
  • Write your smart plug script in the Custom Script box
  • Click Update


Note : To edit or delete a Smart Plug, hover over the Smart Plug and you’ll see options appear on the right side.
 
The Smart Plug Script:
When a conversation is selected in the inbox page, the Smart Plugs which are enabled in the settings page are executed in order, in the context of the selected conversation.


The Smart Plugs are loaded in a separate pane on the right side. This will allow you to provide contextual information to the agent about the current conversation.

Placeholders:


The following values are available for use in your Smart Plug script.
  1. {{user.email}} - Email of the current user
  2. {{user.phone}} - Phone number of the current user
  3. {{user.id}} - User Identifier provided from your app
  4. {{user.tag.key_of_usermeta}} - User meta value for the key provided in small snake case from your app. For example, if you send journey_id from your app, you can get the value for the same as {{user.tag.journey_id}} in the smart plug.
These placeholders are populated at runtime when the script runs. 
Note of caution: If no appropriate value is found for the placeholders, it will be replaced with an empty string.

     

Ajax Requests: 

Ajax requests to third-party sites cannot be made directly from the extensions since browsers reject requests not originating from the same domains (CORS). In order to get around , we provide a proxy to send such request.

Here is a skeleton proxy request. 

      
 $.ajax({
        method: "POST",
        url: "/app/extension_proxy",
        processData: false,
        data: JSON.stringify({
           url: "THIRD_PARTY_URL_HERE",
           method : "PUT",
           headers : {
              Authorization : "Basic AUTH_KEY_HERE",
              "Content-Type": "application/json"
           },
           formParameters : {},
           rawBody : '{"requestName" : "Sample PUT rquest","email":"{{user.email}}","phone":"{{user.phone}}"}'
        })
      })
 

   

SAMPLE SCRIPT

<script>
  var makeRequest = function() {
    jQuery.ajax({
      method: "POST",
      url: "/app/extension_proxy",
      processData: false,
      data: JSON.stringify({
        header: { "Authorization": "Basic " + btoa('API KEY' + ":" + 'X') },
        url: "https://domian.freshdesk.com/api/v2/tickets/2",
        method : "GET"
      }),
      success: function(data) {
        console.log(data);
      },
    });
  };
  makeRequest();
</script>   


The body should be a JSON string containing the following.


url
The URL of the API
method
HTTP method for the API Call
headers

Optional headers to be passed to the API

formParameters

Use this for submitting form data with a POST request

rawBody

Raw string data for use with POST request


Note: processData needs to be set to false to prevent the data to be treated as form parameters.