Map message data

To complete our integration we need to map the messages between Salesforce and Twilio and vice versa. The inbound notification from Salesforce maps to the request of the synchronous call to Twilio, the response of Twilio is mapped to the create CaseComment callback, and a fault response from Twilio is mapped to the create FeedItem callback.

Map Salesforce notifications to Twilio requests

Let's create the request mapping. First, click the mapping icon, in the middle of the flow, and then on the plus sign to create a new mapping. This will be a little more complex than in the previous chapter. In this test, we are going to send the SMS message to our own phone.

Since we don't receive this phone number in our notification, we need to assign the value manually or retrieve it in a separate service call. In this first iteration, we manually assign the From and To phone number and concatenate some nodes of the notification to compose the body node of the SMS message.

In the mapping UI, click on the target's From node, which shows the Build Mappings screen, and lets us type the value itself instead of mapping a source node to it. Since we used the test credentials for setting up our connection, we enter the only valid phone number, for example, +15005550006:

Map Salesforce notifications to Twilio requests

Click Save and Close to return and do the same for the target's To node. Enter a phone number that you want to receive the message, that is, our own. This phone number should be a verified caller ID in Twilio, like we did in the Step 3 - add verified callers IDs section of our Twilio setup.

Click Save and Close to return and click on the target's Body node. Because we want to send the values of multiple nodes in our message, it is composed of three string labels and three source nodes: CaseNumber, Product__c, and Subject.

On the Build Mappings screen you find a sub-section called Mapping Components. Click on Mapping Components to open this section. Drag and drop the concat function, under Functions | Strings, to the target's Body node. This will add the function to the node:

Map Salesforce notifications to Twilio requests

Notice that we have two string value fields. In total we want six fields, but it's not possible to create the empty fields first, because the UI restricts this to two empty values, so we need to have a value first. To get access to the source nodes, open the Source section by clicking on it.

Map Salesforce notifications to Twilio requests

Tip

To only see a specific node, for example, Case, with its children, right-click on the node and select the Show as Top option.

Complete the following mapping:

Source / Text value

Target

Case #:

string1

CaseNumber

string2

To add the other four values we need to create a new sibling after the last value, right-click on the last field, CaseNumber, and select Insert Sibling After. This will add a new field that we can drag and drop a source node to or enter a text value in. We can complete the mapping for the next four fields using the following table:

Source/text value

Target

, Product:

string3

*Case / Product__c

string4

, Case Subject:

string5

*Case / Subject

string6

The mapping of the Body node should look like the following statement:

Map Salesforce notifications to Twilio requests

Click Save and Close to return to the mapping UI. We will now have mapped the To, From, and Body nodes of the target. The target message had many more nodes, but we can leave them unassigned:

Map Salesforce notifications to Twilio requests

Save the mapping and click on Exit Mapper.

Map Twilio's response to Salesforce's case comment

Next, we will create the response mapping of the synchronous response of Twilio and map it to the create a CaseComment request message to Salesforce. Click the mapping icon and create a new response mapping. When the mapping UI opens, it displays an error: can't display all available nodes for the target message. This is because it uses the same large object for receiving and updating CaseComments. Luckily for us, we only need to map three nodes. Define the mapping using the following table:

Source/text value

Target

The Case owner is notified about the escalation.

ContentBody

True (Boolean)

IsPublished

$SourceApplicationObject// Case/Id

ParentId

Tip

To set a Boolean value, click on the target node and open the Mapping Components. Search for Boolean and drag and drop the true or false function to the target statement.

Notice that we don't map any nodes from the response of the invoke to Twilio for our integration as it doesn't include any useful information:

Map Twilio's response to Salesforce's case comment

Tip

A list of nodes can be very long. You can detach the source or target to see the full list in a separate window. To know which nodes are mapped, use the filter option of the mapping UI to only show mapped fields.

Save the mapping and click on Exit Mapper.

Map Twilio's fault to Salesforce's feed comment

Finally, we will create the fault mapping of the fault response of Twilio and map it to the create FeedItem request message to Salesforce. Click the mapping icon and create a new fault mapping for APIInvocationError.

Notice that we only have access to the fault variable and not to our original request message. To create a FeedItem, we need a ParentId, for example, our profile feed. It's not that difficult to retrieve; just follow these steps:

  1. Open a new tab, log into Salesforce, and visit your profile page.
  2. Investigate the URL of the page; it will include the following pattern: /sObject/00558000001NCwhAAG/view.
  3. Copy the value after sObject, for example, 00558000001NCwhAAG
  4. Return to your mapping in ICS.

Now we can define the mapping using the following table:

Source/text value

Target

concat

SMS notification failed to send to case owner. Reason: fault/reason

Body

TextPost

Type

Value you collected in previous steps

ParentId

Tip

To find out more of what the Salesforce API can do, visit the following URL:

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_list.html

Save the mapping and click on Exit Mapper.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset