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.
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
:
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:
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.
Complete the following mapping:
Source / Text value |
Target |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
The mapping of the Body node should look like the following statement:
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:
Save the mapping and click on Exit Mapper.
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. |
|
|
|
|
|
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:
Save the mapping and click on Exit Mapper.
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:
/sObject/00558000001NCwhAAG/view
.sObject
, for example, 00558000001NCwhAAG
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 |
|
|
|
Value you collected in previous steps |
|
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.