# Salesforce Integration

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/3DhU9h8zeRDiHpcvMBGX/ux%20indonesia%208mikJ83LmSQ%20unsplash.jpg)

We all know how much of an asset a smart and well-designed customer support chatbot can be.

Current usage statistics show that at least 70% of level-one customer questions can be handled without real human interaction.

More than 75% of adults today would prefer to exchange messages with a brand instead of waiting indefinitely in a phone queue.

If your support workflow is ready to make the jump, it is very likely that your current setup is holding you back. A chatbot can become a new source of information, but also a new application for your support team to monitor and manage.

<figure><img src="https://3974284760-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtZEstFBYh3uMutlup6ku%2Fuploads%2FFqHvfrsMeW6zzRg5bv9K%2FMyLink%20x%20salesforce.png?alt=media&#x26;token=737b31ab-8753-46d3-adb4-dc56b0105446" alt=""><figcaption></figcaption></figure>

In this article, we’ll look at how to integrate Salesforce, a widely used CRM platform that is also used for customer service and marketing automation.

We will deeply integrate MyLINK Connect into the Salesforce interface so that it becomes part of the workflow, rather than just another external tool.

## Getting Started

The first things we need for our integration are, of course, a MyLINK Connect account and a Salesforce account.

You can sign up for a MyLINK Connect account right away to build and preview the bot we’re creating in this post. When you’re happy with your build, you can then choose the upgrade path you prefer to make your chatbot public.

Since we’re going to integrate deeply with the Salesforce API, make sure that your Salesforce license allows external API access. If not, you can still sign up for a free developer account and complete the integration before choosing to fully upgrade.

## Salesforce Connected App

With our Salesforce account created, we need to retrieve the client ID and client secret values that we will use in our API integrations.

To do so, from our Salesforce console, we must click the Setup menu item that you can find in one of the top-right menus. This will open the general setup page.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/Cyz7N09BtyX22eIcDZQe/image.png)

From the Quick Find menu on the right, type *app* and then click on the App Manager item on the left menu.

This will display the Lightning Experience App Manager view. From there, we must click on “New Connected App”.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/1REb6u7Bu2TbgqNLM0KU/image%201.png)

You can give your app any name you prefer, as long as it is not already taken. Set the contact email you prefer and scroll down to the API section.

Fill the Callback URL field with any URL you prefer, since we won’t be using it, and set the scopes of your connected app to at least “Manage User data via APIs (API)”. Since this is a test and we’re going to play around with multiple things, we suggest that you also add “Full Access (full)” to the list.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/xoMkM5c46U5Q9D9vbNiP/image%202.png)

The general setup is done and we can now save our connected app configuration. You should be taken back to the list of connected apps. From there click on the “View” command for your app to access the newly created information.

In the API section of the details, you should find both the Consumer Key and Consumer Secret fields, which are, in turn, the client ID and client secret required for every API call. Copy both values somewhere handy and let’s continue to MyLINK Connect.

## Building our Support Bot

Instead of starting from scratch for our support bot, we will use a pre-made template and adapt it for our integration.

For our example, we will restore the free Advanced NLP Customer Care template into our account. You can find it in the Templates section inside MyLINK Connect.

All templates are free to preview and use, so we can just click on the “Use This” button to create a copy of the bot inside our account.

<figure><img src="https://3974284760-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtZEstFBYh3uMutlup6ku%2Fuploads%2F09mfY0WK4VOHEDUwzjqI%2Ftemplates.png?alt=media&#x26;token=2feeaebb-5e15-4812-98b0-2046b658e300" alt=""><figcaption></figcaption></figure>

This support bot is already trained to reply to simple questions about a sample company’s printer connectivity and general driver setup, and it is the perfect playground for our integration.

If you wish to delve deeper into the flow and logic used in this chatbot, you can head to [this blog post](https://docs.mylinkconnect.com/artificial-intelligence/nlp) explaining the AI setup, [or here](https://docs.mylinkconnect.com/basic-concepts/chatbot-details/chatbot-teams), where we talk about teams and escalation.

For our example, we are going to slightly change our fallback flow so that the bot will immediately ask the user if human interaction is preferred so that we head to the integration part right away.

Let’s suppose our bot has a conversation like this:

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/TUPdodjuFwmssovlTmCc/image%204.png)

Now, if our customer asks for a human operator, what we want to do is first hand over the conversation so that the MyLINK Connect bot engine will know not to interfere with it.

After that, we can create a case in Salesforce so that our support personnel can be engaged.

The first step is very easily solved by using the Set Operator Chat State Action of MyLINK Connect. This action, when executed in any part of the flow, will hand over the conversation to an operator.

Just note that when set on your flow [interactions](https://docs.mylinkconnect.com/basic-concepts/the-chatbot-designer/interactions_concepts), this action may appear differently if you do not have the [Pro-Team package](https://docs.mylinkconnect.com/basic-concepts/your-account/additional-packages) enabled.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/BXFJewv1Q96tZWNvHajd/image%205.png)

## Salesforce API Integration

With the client ID and client secret we just retrieved from our brand-new Salesforce Connected App, and with our chatbot ready, we can now move on to the actual API integration.

MyLINK Connect can integrate with any public API by using the [Call API Service Action](https://docs.mylinkconnect.com/actions-and-operations/integration/xenioo.bots.actions.base.callapiserviceaction), which you can find under the Integrations section of the Actions and Operations menu.

This action is extremely flexible and powerful, as it allows for any kind of external call.

To use the Salesforce API, we first need to create an API token. We will do it with our very first API action:

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/793xlJFaczyfoNGeTH36/image%206.png)

There are a couple of interesting things going on in this call. First of all, the Salesforce URL is your own, so make sure to use the base URL of your account.

The second part is the payload. The token creation API needs to be invoked with a form POST, and using MyLINK Connect, we accomplish this by selecting “From Encoded” mode. Also, the Salesforce API still needs a user in addition to the client ID and secret. You can provide your own administrative user or create a user that can generate an API token.

If this call succeeds, the result returned by the API will be stored by MyLINK Connect in the configured “salesforce\_token” variable. The resulting data is a full JSON model similar to this:

```json
{
     "access_token":"...DCadsfaqweSAKDSLklerdaoijwqeoif...",
     "expires":3600
}
```

We don’t need everything. We just need the access\_token value. Thanks to MyLINK Connect’s native support of [complex JSON models](https://docs.mylinkconnect.com/actions-and-operations/dynamic-parsing#json-objects), we can use our variable directly without resorting to any custom script: accessing the values of a JSON model is no different from accessing the value of a simple variable.

Now that we have our token, we can add another API action and call the Salesforce Cases endpoint to create a new support case. Inside the payload, this time, we are writing the full JSON model that the [Salesforce API](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_intro.htm) expects.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/SX0xnQbnqG2gIo4Z2rR4/image%209.png)

See how the token was used by simply referencing the model value? This can be done everywhere, in any MyLINK Connect action!

If we repeat the previous flow, choose to talk to a human, and head to our Cases section inside Salesforce, we will find the new case created with the data we just sent using our API.

The case can now be handled by the support team.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/08Beec6qMZdSgb0fp3l5/image%2010%201024x556.png)

If we stopped here, our example would already solve many scenarios…but it would be a little too limited.

The biggest missing piece in this integration is that our support team has no way of contacting the user back and interacting in a real chat.

What we need to do is add a **piece of the MyLINK Connect conversation directly inside Salesforce**. This way, our support team can chat directly with the customer who is having the issue in real time and be ready to answer any question without going back and forth with email and one-way messages.

## Exporting the current conversation

To allow our support team to get in touch with our customer in the very same conversation that created the case, we need an incredibly powerful feature of MyLINK Connect called the [Unique Conversation URL](https://docs.mylinkconnect.com/actions-and-operations/flow/create-conversation-url-action).

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/TlmZyXzd0XJ0vUB4Z6dA/image.png)

Using the [Conversation URL Action](https://docs.mylinkconnect.com/actions-and-operations/flow/create-conversation-url-action), MyLINK Connect can generate a unique URL pointing to that single conversation and make it accessible for a given time window.

The URL is built so that it can be shared as a view-only or even as a take-over view where a destination operator can interact with the user.

While the URL will display a web view of the conversation, the **real exchange happens from MyLINK Connect to the real customer channel.**

This means that our customers will receive the messages on the platform being used and that our operators do not need to engage on the same channel: our operators do not need to use a WhatsApp account or a Facebook account since they will just chat with users through MyLINK Connect seamlessly.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/iqo1FQDEsNkYufpfbWa2/image%2017.png)

## Extending the Salesforce Database

Generating the URL is very straightforward, but what we really need is a field where this information can be stored in Salesforce. To do so, we will need to customize the Cases table.

To edit our case table, we need to head back to the Setup section of Salesforce. This time, we’re going into the “Object Manager” menu that you can see at the top.

From there we scroll down to find the “Case” object we need to edit.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/C2qUj5HWmCz4cUgqgguP/image%2012.png)

In the menu that appears, click on “Fields & Relationships” and then on “New” to add a new field.

The name of the field is up to you. As long as it doesn’t already exist, it will be fine. For our example, since it is going to hold the MyLINK Connect Conversation URL, we’re going to call it “MyLINK Connect Url”. Since MyLINK Connect will create a fairly short URL, a text field with a length of 255 characters will be more than enough to hold all the data we need.

Once created, in the full fields list or in the field detail, take note of the Salesforce API field name. This is the real name of the field for Salesforce and it is the one we need to mention in our updates.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/iGiaOREqBb0lOuvqn13i/image%2013%201024x546.png)

Now that our case has been modified, all we need to do is make a small change to our flow in MyLINK Connect so that the URL is also sent to our case. The [Share Url action](https://docs.mylinkconnect.com/actions-and-operations/flow/create-conversation-url-action), when executed, will create a variable holding the unique URL value. We will send this to Salesforce.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/LxZIDa9srWlb6irdj8Xq/image%2014.png)

If we create a new case from MyLINK Connect and we go back to the detail page, we will find the shared URL set as expected.

Nice, but still not quite the type of integration we’re looking for. We cannot ask our operators to copy/paste the URL or anything like that. We do want the conversation to appear inside the Salesforce page.

## Creating a Salesforce Component

To bring MyLINK Connect inside Salesforce, we need to create a Lightning Component that can be hosted inside a Salesforce page. This may sound difficult, but it is actually fairly easy and, once done, it can be reused anywhere.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/YcEc3lHOjoQOhxAeoErl/image%2015%201024x647.png)

To create our component, open the Developer Console window from Salesforce. From the menu there, select “New” and then “Lightning Component”.

The component itself is built around a kind of HTML/XML notation that merges standard HTML with Salesforce objects. We don’t really need much complexity, since MyLINK Connect is doing all of the heavy lifting here. All we need from this component is access to the current case data and the MyLINK Connect URL field we just created.

Copy and Paste the component source below and your component is done:

```xml
<aura:component implements="force:appHostable,force:hasRecordId,flexipage:availableForAllPageTypes" >

    <aura:attribute name="record" type="Object"/>
    <aura:attribute name="simpleRecord" type="Object"/>
    <aura:attribute name="recordError" type="String"/>

    <force:recordData aura:id="recordLoader" fields="xenioo_url__c"
      recordId="{!v.recordId}" targetFields="{!v.simpleRecord}" targetError="{!v.recordError}"
    />

    <iframe style='width: 100%;min-height: 625px;border: none;border-radius:4px;' src='{!v.simpleRecord.xenioo_url__c}'></iframe>
</aura:component>
```

It looks complicated, but it is not. We’re just telling the component that we need the current record and that we’ll be reading the MyLINK Connect URL value. From there, we use the URL value to set the source for a simple iframe page. The iframe will display the MyLINK Connect conversation URL.

Once the component has been updated we can save everything and close the Developer Console.

## Changing the Case Page

If we head back to our case page, we can now add our MyLINK Connect Lightning Component to the page. To do so, we can just click on the Edit Page menu you can see in the top-right area. This action will activate the page editor.

You can place our MyLINK Connect Lightning Component wherever you like. In our example, we’re setting it in an additional tab in the details area. If everything we’ve done up until now is correct, our MyLINK Connect component will be available on the left side of the page, under the Custom Components section.

Drag the MyLINK Connect Lightning Component onto the page, wherever you like. Don’t worry if you see a sad emoji icon in the target spot. It is just MyLINK Connect telling you that there is no current URL for the conversation.

Once you are happy with how your custom page looks, activate it and save everything to go back to the real case detail.

All that is left to do now is click on the MyLINK Connect tab we’ve just created to access the component live.

![](https://content.gitbook.com/content/tZEstFBYh3uMutlup6ku/blobs/8in7JD86tZbv5Ec2orOW/image%2016.png)

And there it is! Our **MyLINK Connect conversation now runs seamlessly inside a Salesforce case page. From there, we can chat with our customers**, share files, and handle our support case.

## Wrapping Up

You can now integrate any MyLINK Connect chatbot and conversation inside Salesforce Cases. The Salesforce API lets you exchange data with just about everything, so now that you know the way, there are no limits to the depth of your integration!
