Trigger SMS Using the Twilio Connector
So far, you’ve gathered the opportunity, product, and order information. Your next step is to send an SMS with the details to notify the customer. For testing purposes, use your own phone number to send the SMS. To do this, format the message and pass it on to the Twilio connector in the format it prefers.
- Open the Transform card to the left of the Twilio connector.
- In the left side (Input section), click the next to payload, and set the Data Type to Order Tracking.
- Set the data type for OppDetails to Salesforce Opportunity.
- On the right side (Output payload section), double-click the To field and add your phone number with the country prefix (for example, a US phone number would look like 16667778888)
- Double-click the From field and use the phone number you obtained when you signed up for Twilio.
- Drag the OrderID field from Input to the Body field in the Output payload section.
- In the bottom bar, switch to the Script mode to see the Transformation script. MuleSoft uses a powerful data transformation language called DataWeave. The script tab contains autogenerated DataWeave code. Replace the
Body: payload.OrderIDwith this code:
Body: "Order for " ++ vars.OppDetails.Name ++ " has been placed. Details: " ++ "OrderID: " ++ payload.OrderID as String ++ ", Tracking: " ++ payload.TrackingNo ++ ", ETA:" ++ payload.ETA as Date
In the preview, notice a message is constructed with dynamic variables, and also converting the ETA from a timestamp (2019-01-25T00:00:00.000Z) to date (2019-01-25). With DataWeave, you transform your data between formats like XML, JSON, CSV, and so on, and perform lookups and functions within your data.
Now you’re all set to send SMS notifications when orders are placed. NTO customers do not have to call the sales rep to check on their orders. However, if someone does call, you want to make sure that the sales rep has the OrderID. In the next section, you use the Salesforce connector to update the opportunity record with the OrderID.
We won’t check any of your setup. Click Verify Step to go to the next step in the project.