Introduction:
This is the second part of Open Connector Twilio Integration. In the
Part 1 of the series we discussed on :
- How to setup WhatsApp instance in Twilio.
- How to configure Twilio Open Connector.
In this blog, we will see how to Integrate Open Connectors with SAP Integration Suite - Cloud Integration IFlow to trigger WhatsApp messages in case of any message failures on the Tenant.
As this blog mainly focuses on the Open Connectors - Twilio functionality, I would not be explaining the OData API call IFlow which extracts the details of the message failures on the Integration Tenant.
Kindly comment on this blog, if you are interested to know about the OData API call IFlow.
Pre-requisities
- MessageProcessingLogs OData API IFlow
Using this OData API, one can extract the details of message failures for the defined time, the response is received in the XML format. In this blog lets assume that, this API is called every 15 mins to check on the failures. If there are any failures, the IFlow should call the Twilio Open Connector to trigger an alert message to the WhatsApp Account.
Open Connectors Twilio Integration Flow
After calling MessageProcessingLogs OData API and filtering out the few extra fields which are of no use to us, the final output looks as shown below.
Iflow 1
This XML message is the input feed coming from the Process Direct call to our OpenConnectors IFlow as shown below.
Iflow 2
The Idea is to convert XML into the flat text format, because sending a WhatsApp message in XML format is not appropiate, the Change format groovy will change the format of this message and remove duplicate values.
Groovy Script (Change Format):
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message)
{
def xml = message.getBody(java.lang.String) as String;
def xmlObj = new XmlSlurper().parseText(xml)
def btNumbers = xmlObj.MessageProcessingLog.collect{it.iFlowName}
def countMap = btNumbers.unique(false).collectEntries{btNumber-> [btNumber, btNumbers.count(btNumber)]}
message.setProperty("Output",countMap)
return message;
}
Lets assume the input is as below:
We can see a duplicate value in this xml input, this script will remove the duplicate after counting the duplicate values, finally it prints the count with that specific value.
Input:
<?xml version="1.0" encoding="UTF-8"?>
<MessageProcessingLogs>
<MessageProcessingLog>
<iFlowName>Packaged_Integration_-_ABC</iFlowName>
<Status>FAILED</Status>
</MessageProcessingLog>
<MessageProcessingLog>
<iFlowName>Packaged_Integration_-ABC</iFlowName>
<Status>FAILED</Status>
</MessageProcessingLog>
<MessageProcessingLog>
<iFlowName>Packaged_Integration_-_XYZ</iFlowName>
<Status>FAILED</Status>
</MessageProcessingLog>
</MessageProcessingLogs>
Output:
Now as a output, we have the Integration Flow which is failed along with the number of failures for that particular Integration Flow.
[Packaged_Integration_-_ABC:2,
Packaged_Integration_-_XYZ:1]
As the output is ready for the delivery, we will now pass this body to the OpenConnector API message body.
Content Modifier (set body):
Set Property "TO" and make it configurable so that you can easily change the recipient number.
Iflow 4
Iflow 5
Body:
{
"from": "whatsapp:+14155238886",
"message": "--- Failures on CPIS Production --- ${property.Output} --- End of Report ---",
"to": "whatsapp:${property.TO}"
}
Process Call - Call OpenConnectors:
Using a Process call, lets call Open Connectors adapter now.
Iflow 6
Content Modifier - Delete Headers:
An Header called "content-length" gets created by default which impacts the OpenConnectors call, the call fails when this header is present, Hence to aviod the failure this header needs to be deleted which is done at this step.
Iflow 7
Open Connectors Adapter Call:
In Connection Tab of OpenConnector adapter, do the configuration as shown below.
Iflow 8
Setting up Security Artifact for Open Connectors:
Open Monitor tab in CPI. Monitor—-> Manage Security Material —-> Add —–> User Credentials. and configure as shown below. Finally deploy the Credentials.
Iflow 9
How do we get the User Organization and Element details?
we can get these details from Open Connectors. Log on to Open connectors portal, go to your API docs, and you can get the details. The authorization token contains, User Organization and Element. (Exclude the comma and space while entering the values in user credentials)
We are set now, Deploy the Flow and wait for the message failure on the tenant so that we can get an alert on our WhatsApp Account.
Scenario:
There is failure in one of the Integration, this failure is captured by the ODATA API IFlow, after which the XML input is sent to the Open Connectors Twilio Integration Flow via Process Direct (as mentioned and explained above)
Message Monitoring
An Alert can be observed coming to the WhatsApp Account as shown in the snip below.
WhatsApp
Open Connectors comes with additional monitoring section called "Activity" where we can monitor the calls and debug in case of any failures.
Open Connectors Activity
This is really very helpful when we are away from our systems and of course on the weekends, Support Team has to support on the weekend or be on call, such setup will definietly ease support team's job to a larger extend.
Apart from this, in the day to day activities, such alerts on the phone can minimize the delay in taking care of the critical failures in turn increasing the productivity in the project.
Please feel free to add comments on this blog and let our SAP Tech Heads know what our Integration Suite suite can accomplish, I am sure there are many such cool features which we can build here.
I hope this was informative.
Thanks & Regards,
Punith Oswal