3

Designing Notification Strategy Using iPaaS

 1 year ago
source link: https://blogs.sap.com/2023/01/03/designing-notification-strategy-using-ipaas/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introduction

Notifications are very widely and commonly used now a days to send quick updates to the end users, customers, employees etc. In the e-commerce world, text messages are a common mode to send order updates to customers, retailers, shipping agencies.

In this blog, I am going to take a use case for notifications and design a decoupled and centralized notification service which can be leveraged across the enterprise.

As usual, let us break down the tasks which we are going to perform.

  1. Design Thinking – Define a problem and design a solution
  2. What is SAP Integration Suite and open connectors
  3. Pre-requisites before creating iFlow / REST API
  4. Create instance of TWILIO in Open Connectors
  5. Create Open Connector credentials.
  6. Design a REST API and integrate with TWILIO
  7. Test it with POSTMAN

Let us get started.

Task-1: Design Thinking

Let us define the problem and then design a solution.

I would like to show a design and then elaborate it.

Figure-1

Figure-1

In the above diagram,

  1. User places an order in Commerce Cloud.
  2. As per the defined business process, a retailer is assigned to the order to fulfill it.
  3. The retailer gets a text message for the new order.
  4. The user also gets a text message about the order confirmation details.
  5. The order is replicated to SAP S/4 HANA through SAP Integration iFlow.
  6. Once the retailer fulfills the order, an event is triggered in SAP S/4 HANA.
  7. Order updates are replicated back to Commerce Cloud through SAP Integration iFlow.
  8. Once order updates are received in Commerce, an text notification is triggered for the end user as well as retailer about completion.

There is nothing wrong in this design but there are some disadvantages which I have listed below:

  1. Include TWILIO library (JAR) in Commerce cloud platform to use the interfaces and send messages to the TWILIO API. To upgrade the JAR in future, this will need some effort, plus a deployment.
  2. Write the boiler plate code.
  3. Reusability – In large enterprises there are multiple applications in diverse languages which might need to send notifications to the end users. Every application/platform will have to independently integrate with TWILIO.

Let us look how we can negate the above disadvantages by using SAP Integration suite and open connectors. I will represent the solution design in the below diagram.

Figure-2

Figure-2

Let us take a detail look.

  1. Here, we have moved the responsibility of integration with TWILIO from Commerce cloud to Integration Suite.
  2. As the landscape already has integration between Commerce and Integration Suite available (as shown in Figure-1), we can reuse the same integration layer from Commerce platform.
  3. Use already available open connector for TWILIO in SAP Integration Suite which takes care of boiler plate code. No need to worry about any library update or patch.
  4. Expose REST API / iFlow from SAP Integration Suite.
  5. This API can also be used by other applications in the enterprise which require notifications to be sent.
  6. In case of failures (network errors), the iFlow can be re-triggered to send the message back to TWILIO.

With this, we have centralized as well as decoupled the notification strategy for the enterprise and created a scope for reusability in future with low code.

Task-2: What is SAP Integration Suite and Open Connectors?

SAP Integration Suite is a great iPaaS – Integration Platform as a Service. It offers a suite of cloud services enabling organizations and development teams to create production grade integration flows. This helps to connect heterogenous systems, interfaces, services, cloud based or on premise applications and data. It offers a low code capability by providing inbuilt transformers, mappers, content modifiers which one can drag and drop to create integrations between diverse interfaces in less time. It also offers support for adding custom logic using scripting languages like groovy.

SAP Open Connectors is a suite of 150+ connectors for integration with non SAP applications. For example – TWILIO, STRIPE etc.

SAP has great documentation about this topic here

Task-3: Pre-requisites before creating iFlow / REST API

To put a scope on this blog, I would request you to fulfill the below prerequisites before starting to build an iFlow.

  1. You have created an instance of Process Integration Runtime in your sub account
  2. You have necessary roles granted by the admin of the subaccount. (Following Principle of Least Privilege). This is required to design integration flows or to create REST apis.
  3. You have added below capabilities from the SAP Integration Suite Home Page
    1. Cloud Integrations
    2. API Management
    3. Open Connectors
    4. Integration Advisor
  4. You have access to the Open Connectors portal. This can be launched from inside the Integration Suite but you will need access granted by the admin of the subaccount.
  5. Create an trial account on TWILIO and get authentication id, authentication token and from phone number.

Once the above pre-requisites are performed, then you are all set.

Task-4: Create instance of TWILIO in Open Connectors

In this task, we will launch the open connectors portal and create a service instance of TWILIO.

  1. Open Discover Connectors from the capabilities section
    Figure-3
  2. Search for TWILIO in the connector catalog. Click on TWILIO SMS – Authenticate
    Screenshot-2022-12-27-at-11.00.52-AM.png
  3. Once you click authenticate, you will land on the screen where you will have to add and create an instance.
    1. Name – Give name for the instance
    2. Account SID – Your TWILIO SID
    3. Auth Token – Your TWILIO token
    4. Phone Number – Your TWILIO from phone number
  4. You will be able to see the new instance created under Instances.
  5. Click on the API Docs and you will be able to see all the APIs and test them right away. For the scope of this blog, our focus in the messages api
    Screenshot-2022-12-27-at-11.05.34-AM.png
  6. Expand the messages api. Copy the authorization string and paste it in a note pad. We will use this in the next task.

Task-5: Create Open Connector Security Material

In this task we will create a credential parameter using the authorization string we got in the above task.

  1. Open SAP Integration Suite
  2. Go to Monitor – Integrations – Manage Security – Open Security Material widget.
  3. Create – User Credentials. Select OpenConnectors as the type.
    Screenshot-2022-12-27-at-11.13.39-AM.png
  4. Add name, description.
  5. Add User, Organization and Element from the Authorization string we got from Open Connectors TWILIO instance. Note – Be careful of spaces, special characters else this will throw error when actually connecting.

Task-6: Design a REST API and integrate with TWILIO

Pre-requisites – You have created an integration package where you will add an integration flow. I highly recommend going through a tutorial to quickly understand the basics of designing an iFlow here .

In this task, I will first show you the completely designed REST api and then explain the components of it. I created a REST API (User Registration Notification Integration Process) which sends notification to the user whenever a new user is created. Take a simple use case – when a user is created in SAP Commerce, this API will be invoked from Commerce to send welcome message. This can be extended for order notification messages. Below diagram shows the REST API with TWILIO integration.

Figure-3

Figure-3

The above integration flow consist of 3 main components

  1. Groovy script for validation of input message and creating JSON request as per TWILIO request
    /* Refer the link below to learn more about the use cases of script.
    https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html
    
    If you want to know more about the SCRIPT APIs, refer the link below
    https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */
    import com.sap.gateway.ip.core.customdev.util.Message;
    import java.util.HashMap;
    import groovy.json.JsonSlurper;
    import groovy.json.JsonOutput;
    import java.util.Objects;
    
    
    PHONE_REG_EX_PATTERN = "^\\+1\\d{10}";
    PHONE_NUMBER_EXCEPTION_MESSAGE = "Invalid phone number";
    EMPTY_NOTIFICATION_EXCEPTION_MESSAGE = "Invalid notification message";
    
    def Message processData(Message message) {
        
        def body = message.getBody(String.class);
        def slurper = new JsonSlurper();
        
        def requestBody = slurper.parseText(body);
        
        String toPhone = requestBody.data.toPhone;
        String alertMessage = requestBody.data.message;
        String fromPhone = requestBody.data.fromPhone;
        
        validatePhone(toPhone);
        validatePhone(fromPhone);
        if(Objects.isNull(alertMessage)) {
             throw new Exception(EMPTY_NOTIFICATION_EXCEPTION_MESSAGE);
        }
    
        def jsonRequest = JsonOutput.toJson([to: toPhone, message: alertMessage, from: fromPhone]);
        
        def messageLog = messageLogFactory.getMessageLog(message);
        messageLog.addAttachmentAsString("RequestPayload:", jsonRequest, "text/plain");
        
        message.setProperty("request",jsonRequest);
       
        return message;
    }
    
    def validatePhone(String phone) {
    
        if(Objects.isNull(phone) || (Objects.nonNull(phone) && !phone.matches(PHONE_REG_EX_PATTERN))) {
            throw new Exception(PHONE_NUMBER_EXCEPTION_MESSAGE + phone);
        }
    }
  2. Content Modifier – The main parts of this is the Message Header and Message Body as shown in the below screenshots
    Screenshot-2022-12-27-at-1.29.15-PM.png
    Screenshot-2022-12-27-at-1.29.26-PM.png
  3. Add a Open Connector between External call component (Request Reply) and TWILIO as shown in the integration flow. Open the Connections tab
    1. Base URI – This you will get from the API docs in the Open Connector instance API docs.
    2. Credentials Name – Select the security material which we created in task-5.
    3. Resource – The api name – messages
      2022-12-27_13-36-09.png
  4. That is it. Save and Deploy your REST API.
  5. Before we jump on to the next task, create a service key in the Process Integration Runtime instance and copy the OAuth credentials.

In this task, I have created directly a REST api. Another approach is to create an integration flow and then expose it as an API using API management capability.

Task-7: Test it with POSTMAN

  1. Get bearer token using OAuth.
  2. To get the base url of the REST api, go to Monitor – Integrations – Manage Integration Content – All – You will get the endpoint .
  3. Use the below json request
    {
        "data": {
            "toPhone":"+1XXXXXXXXXX",
            "message":"Welcome to SAP Integration Suite",
            "fromPhone":"+1XXXXXXXXXX"
        }
        
    }​
  4. Check your phone
    IMG_DF72FE0F7922-1.jpeg

Conclusion

Enterprise architecture often, if not always is full of constraints. When we start designing, integrating and collaborating with external systems, interfaces and teams, constraints start to pour in.

That is why I said previously, design-1 is not wrong. Most probably it is the outcome of some constraints.

Hope this blog has helped you, not just to understand and explore the capabilities of SAP Integration Suite but to trigger a thought process of how we can use softwares available at hand in the enterprise landscape to create reusable components with low code capabilities.

This is just a glimpse of wide set of capabilities offered by SAP Integration Suite. Stay curious! Keep learning!

To get more updates about this topic, please follow the below pages

Feel free to “like“, “Share“, “Add a Comment” and to get more updates about my next blogs follow me – Avinash Vaidya


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK