My Oracle Support Banner

How to send multiline string in Twilio post request from Application Composer (Doc ID 2921047.1)

Last updated on JANUARY 13, 2023

Applies to:

Oracle Fusion CX Sales Cloud Service - Version 11.13.22.10.0 and later
Information in this document applies to any platform.

Goal

We have used Twilio third party service for SMS functionality.

In ApplicationComposer , we have registered Twilio rest API based on the below steps and used this WS to send SMS and message format is text format, so for line break we had used \n keyword but we are getting \\n in SMS  message instead of a new line:

1) Create a new "My first Twilio account" and get a new Account SID/AuthToken, URI  and MessagingServiceSid
2) Test in POSTMAN to get POST request/response JSON payload and use it in step 3
3) Register the WS with URI https://api.twilio.com/2010-04-01/Accounts/{{ACCOUNT_SID}}/Messages.json and name 「TwiliioSMS」
4) Create a global function and use the following groovy:
    def phonenumber = pn;
    def messageForMobile = msg;
    def response;
    def httpErrorResponse;
    def messagingServiceSid = "<messagingServiceSid> from step1";
    def conn = adf.webServices.TwiliioSMS;

    def headers = [:]
    def params = [:]

    headers.'Content-Type' = 'application/x-www-form-urlencoded'
    headers.'charset' = 'utf-8'
    conn.requestHTTPHeaders = headers

    def values = "&To="+phonenumber+'&Body='+messageForMobile+"&MessagingServiceSid=${messagingServiceSid}&";   //VERY IMPORTANT: need to add '&' at the end after MessagingServiceSid value
    params.d=values.trim();

    try{  
          response = conn.POST(params)    
          httpErrorResponse = response.statusCode;
  
    }catch(e){
       println(":::-->Response Error Message::: "+conn?.error_message+"HTTP Response Code:::" + conn?.statusCode + " :::httpErrorResponse:::"+ conn?.httpErrorResponse +":::TRY-CATCH-EXCEPTION:::" + e )
       httpErrorResponse = conn?.httpErrorResponse;
    }

    return httpErrorResponse;


 

Solution

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Goal
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.