SAP Cloud Workflow Meet #SMS Notifcation & Approval/Rejection
PS: Demo at the end of the blog
In my previous blog where we talked about SAP Cloud platform workflow approvals via email, I kept on thinking can we do it via SMS? What if the moment someone gets work item in his inbox can he also get an SMS from where he can approve or reject. This actually sets me in the direction to search for the possible options in order to make this happen.
Problem Statement
SAP Cloud Workflow notification and approval/rejection via SMS.
Technical Solution
We are using the same workflow as in our previous blog with a timer-based event to trigger approvals. We have added one service task which calls our PHP based script hosted on webserver. We have created this wrapper as service task did not provide any option to pass headers which are important to consume the Proximus Enco SMS API . This script serves two purposes.
- First purpose is to call Bitly API for shortening our URL as we don’t want the SMS to contain big URL’s, meaning the SMS API will fail as it has content restriction. You can create free account on Bitly to get the token which is used in this case.
$request = file_get_contents('php://input');
$json= json_decode($request);
// URL Shortener for Approve
$longURL= "http://<webservver link>/api/chat/MailApproval.php/".$json->taskid."/Approve";
$url = "https://api-ssl.bitly.com/v3/shorten?access_token=<bitly access token>&longUrl=".urlencode($longURL);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$respApprove = curl_exec($ch);
curl_close($ch);
// URL Shortener for Reject
$longURL= "http://<webservver link>/api/chat/MailApproval.php/".$json->taskid."/Reject";
$url = "https://api-ssl.bitly.com/v3/shorten?access_token=<bitly access token>&longUrl=".urlencode($longURL);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$respReject = curl_exec($ch);
curl_close($ch);
$respRejectJson = json_decode($respReject);
$respApproveJson = json_decode($respApprove);
- Secondly, we will consume SAP Cloud Platform Proximus Enco SMS API to send SMS to the concerned person.
// Send SMS API
$context = array();
$context["message"] = $json->message ." Approve-> ".$respApproveJson->data->url . ' Reject-> ' . $respRejectJson->data->url;
$ch1 = curl_init('https://sandbox.api.sap.com/proximusenco/sms/outboundmessages');
$request_headers = array();
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'APIKey: <API key from API hub>';
curl_setopt($ch1, CURLOPT_HTTPHEADER, $request_headers );
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch1, CURLOPT_VERBOSE, 1);
curl_setopt($ch1, CURLOPT_HEADER, 1);
$context["binary"] = false;
$context["destinations"] = [$json->destinations[0]];
curl_setopt($ch1, CURLOPT_POSTFIELDS,json_encode($context) );
$resp = curl_exec($ch1);
curl_close($ch1);
Demo
We can see in the demo an SMS is triggered within 1 minute of task creation and person can approve/reject by clicking the links.
Challenges Faced
- One of most important challenge which I faced was to pass the Header field via Service Task to the Proximus Enco SMS API . I requested for help on twitter to our experts Christian Loos and DJ Adams for the same. DJ Adams advised me to post on SAP Question and Answer so that if someone else has the same problem it will help them.
I agreed and while posting I decided to search in the same forum to see if I have missed anything in my previous searches. Luckily one of the Question had the same concern and it was mentioned that Header field support is not available as of now.So, my wrapper-based approach was correct one. Secondly don’t search only on google. Earlier google use to list down all results from SCN/SDN forums now I believe it is not. So learning here is apart from google search use exclusive search on SAP site.
- Second challenge was the length of the message and considering my long approve/reject URL’s I searched for URL shortener. Sadly, Google URL shortener service has been stopped from previous month so on further searching found Bitly service which worked flawlessly.
What Next
I have been trying my hands on Swift iOS for some time so hopefully a basic app might be up and running in some time:)
Feel free to provide your feedback open to all ears.
Complete PHP Script code can be downloaded from here.
Nice Nabheet Madan - definitely a business requirement in the marketplace so great that we all have a resource to refer to - thanks to your nice blog. Thanks!
Thanks Phil - Keep exploring keep sharing
Hi Nabheet,
Do you have a source code for workflow?
Thanks, Manju