salman0ansari / whatsapp-api-nodejs

RESTful WhatsApp API with Multiple Device Support
GNU General Public License v3.0
1.27k stars 606 forks source link

how send \n in message? #737

Closed foryasbot closed 1 year ago

foryasbot commented 1 year ago

how send newline in message? i try \n or
not work.

caiogrigoleto commented 1 year ago

Hi @foryasbot !!

how are you sending your code? Can you post the example here? I use \n in my PHP projects. If you want to post it here so I can take a look, I'd appreciate it!

caiogrigoleto commented 1 year ago

because sometimes it depends on how you convert the message you are sending, if it is an array and you already handle the "line break" it ignores the \n.

but send your example here for us to look at!

foryasbot commented 1 year ago

because sometimes it depends on how you convert the message you are sending, if it is an array and you already handle the "line break" it ignores the \n.

but send your example here for us to look at!

hi bro, i send messgae using curl like this: curl --location --request POST 'localhost:3333/message/text?key=mykey' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'id=myTargetPhonenumber' \ --data-urlencode 'message=hi \n how are you'

caiogrigoleto commented 1 year ago

Try using these examples formatted in JSON, test both examples if one doesn't work.

Ex1:

curl --location --request POST 'localhost:3333/message/text?key=mykey'
--header 'Content-Type: application/json'
--data '{ "id" : "myTargetPhonenumber", "message" : "hi \nhow are you"  }'

Ex2:

curl --location --request POST 'localhost:3333/message/text?key=mykey'
--header 'Content-Type: application/json'
--data ' {\"id\" : \"myTargetPhonenumber\", \"message\" : \"hi \nhow are you\"  } '

Note: The \" I'm using has the same principle as \n. So if example 1 doesn't work, try example 2. Which is the method I use in my projects.

And also follow my example here if you want to implement or take advantage of something!!

image

I hope it helped you!

salman0ansari commented 1 year ago

Learn about "escape characters" https://en.wikipedia.org/wiki/Escape_character

foryasbot commented 1 year ago

thank you bro, its work!