Adding New Line in SMS Body Wix - Twilio

Greetings to All,
I implemented sms messaging from this example: https://www.wix.com/velo/example/twilio-sms-integration without issues.

However, I want to send message fields on New Lines in the body of the message example.
Name
Phone
Email
Age

I tried

Message body = “ Name “/n” Phone “/r/n” Email “ %0a ” Age

But none of the above escape variations above works, even tried with “double quotes” & ‘single quotes’

I greatly appreciate any help on this…

Thanks in advance.
Nev:

Basic code:

import twilio from ‘twilio’

let phone = “954 XXX XXXX”
let body = “First Line /r/n Second Line /r/n Third Line”
const accountSID = “Hidden for post”
const authToken = " Hidden for post "
const twilioNumber = “+1951 XXX XXXX”

export async function sendSms () // (phone, body)
{
let client = new twilio(accountSID, authToken)
let message = await client.messages.create({
body: body, // Dynamic value from incoming parameters
from: twilioNumber, // Twilio number
to: phone, // Dynamic value from incoming parameters
})
.then((message) => console.log(message.body));
}

You need to use backslash not forward slash.
WRONG: /n
RIGHT: \n

Hello JD,

I tried various examples include using forward slash, back slash as well as the escape variations above, but nothing works to create a new line.

I just tried the following also without success.

message = “First Line \n Second Line \n Third Line”;

Any further assistance you can offer will be greatly appreciated.

Thanks again.
Nev

@arawakfoundation According to this official source “\n” is what you need.
You can also search Google for other solutions.

Hi JD,

Thanks again for your reply.

I am using a Premium website, I also created a free wix website and configured it to send sms via Twilio. Same problem. The page does send the sms, however I am not able to achieve getting a line break to work with “\n” which is the common line escape, or any of the variations above…

I am wondering if it is a limitation on wix side, or twilio’s.
I searched the web for almost 36 hours to see if I could find a fix before reaching out to you .

Thanks again,
Nev.

I don’t know.
It’s out of this forum scope. You may like to post a question in Twilio Community or Stackoverflow.

But first try:
Use backticks with actual line break like this:

const body = `line1
line2`;

Also try:

const body = `line1\n
line2`;

Hey JD,

You are a keeper!!!
Thanks Bunches, I really appreciate your help…

Both examples worked for me.

Thanks again,
Nev.

const body = ** line1 line2 ** ;

const body = ** line1\n line2 ** ;

Hi JD,
Its me again, I still require your assistance a bit further.

So if I send the following from my JSW page, the line breaks work no problems.

Line One \n Line Two \n Line Three \n Line Four \n Line Five \n Line Six \n Line Seven

However, if I send the same from my Code Page, then the line breaks stop working and everything is all in one again.

This is my intended implementation.

let body =
${ $w('#LineOne').value +"\n"+ $w('#LineTwo').value +"\n"+ $w('#LineThree').value +"\n"+ $w('#LineFour').value +"\n"+ $w('#LineFive').value +"\n"+ $w('#LineSix').value +"\n"+ $w('#Line Seven').value};

Thanks again.
I really appreciate you,
Nev

@arawakfoundation
Try:

let body = 
`${$w('#LineOne').value}\n
 ${$w('#LineTwo').value}\n
 ${$w('#LineThree').value}\n
 ${$w('#LineFour').value}\n
 ${$w('#LineFive').value}\n
 ${$w('#LineSix').value}\n
${$w('#Line Seven').value}`;

Hey JD,

That did it…
Nuff Nuff Big Ups!!!

Thanks again,
Nev