Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Create break line in the message #16

Open
kanodoe opened this issue Dec 31, 2014 · 12 comments
Open

Create break line in the message #16

kanodoe opened this issue Dec 31, 2014 · 12 comments

Comments

@kanodoe
Copy link

kanodoe commented Dec 31, 2014

In a future release you could add the command to break a line in the message, in that way is possible to send a title leave one break line and then show the url.

Regards

@nolybom
Copy link

nolybom commented Dec 31, 2014

plus one for this. It gives you then a little bit more freedom to "style" the message.

@rvpatel
Copy link

rvpatel commented Jan 5, 2015

Not working

$_u.="Product Name:".$_productName."\n";
$_u.="Sku:".$_productSku."\n";

How to break line when i send message on whatsapp. i have try also %0A but not working.

see hear http://stackoverflow.com/questions/27780542/whatsapp-create-break-line-in-the-message

@ghost
Copy link

ghost commented Jan 7, 2015

@rvpatel The code you posted seems to be PHP, not JavaScript.

What exactly is not working? What are you trying to achieve?

@nolybom
Copy link

nolybom commented Jan 7, 2015

HTML:

data-text="text
more text
"

I think that's what he wants to achieve. Definitely what i want to achieve.

..in PHP

data-text="text_\n_more text_\n_"

@kriskbx
Copy link
Owner

kriskbx commented Jan 8, 2015

WhatsApp uses HTML internally to display the messages. (Source: https://github.com/venomous0x/WhatsAPI/blob/7099c1af303abbf9c2ea07801ffa88657ecd4665/src/protocol.class.php#L100-L151)
What we don't know, is how it handles the String passed by the url scheme. It does probably some sanitizing that strips line breaks and other not wanted/unsecure chars. So it's very likely that line breaks are not possible at all - at least without any source code from WA.

@Riscoded
Copy link

Any working demo??

@rafael-santos
Copy link

Hi there!

I just have a similar issue and found one solution that works for me.

In javascript I have my message with line breaks and line feed like this:

var whatsappMessage= "My title"+"\r\n\r\n"+"My description and link"

Sending that to Whatsapp won't work, you have to encodeURI first, as if it was for a mailto:

whatsappMessage = window.encodeURIComponent(whatsappMessage)

Sending encoded message as parameter like whatsapp://send?text=whatsappMessage now displays line breaks and returns on Whatsapp.

Mailto reference (5. Encoding): http://www.ietf.org/rfc/rfc2368

Tested on Android 6.0.1, Whatsapp 2.17.107

Hope it helps

@srmaikol
Copy link

srmaikol commented Jun 5, 2017

@rafael-santos , your solution is working for me too. You solved a three year old problem!
Thank you and ¡¡¡Bravo!!!

Tested on Whatsapp 2.17.213, Android 6.0

Miguel

@romit19
Copy link

romit19 commented Apr 8, 2018

@srmaikol you can also use https://www.url-encode-decode.com/ for line break.

@mikebeaton
Copy link

@rafael-santos 's solution works great - thank you!

Here I just wanted to point out to the devs (please someone say if there's a better place to send this) that if you send a message using api.whatsapp.com then the preview of the message which appears immediately DOESN'T show the new lines... but if you then click 'SEND' the composed message which appears in web.whatsapp.com DOES show them.

Example which displays this behaviour:

https://api.whatsapp.com/send?phone=447777333333&text=Message%0awith%0anewlines
(you'll have to enter a valid phone number instead of the dummy one to see the composed message page)

@guimacanoas
Copy link

guimacanoas commented Feb 19, 2019

Hi guys,

This is my first post in this type of community, sorry for anything about my English (fault of google translator). To this day I have only received from you, but I feel that I can help some of them really:

I have the same problem with Selenium. If this is useful for you too, you can resolve this problem by using something like CTRL + C / CTRL + V

Like this:

ClipboardOwner selection;
selection = new StringSelection("Message to copy paste");
driver.findElement(By.xpath("whatsapp message box xpath")).sendKeys(Keys.chord(Keys.CONTROL,"v"));

@mikebeaton
Copy link

mikebeaton commented Feb 19, 2019

The code running on api.whatsapp.com needs a minor change as below.

When you follow this link https://api.whatsapp.com/send?phone=447777333333&text=Message%0awith%0anewlines then the following HTML code is part of what is generated on the initial page that the user sees:

<div id="text-preview" class="block block--default block--sharepreview">
    <div id="text-block" class="block__body">Message
with
newlines</div>
</div>

The message is in there and has the newlines in it, but they are not displaying because of their context within an HTML div. It would simply need any %0a ('\n') characters to be converted to <br /> to make the preview show correctly:

<div id="text-preview" class="block block--default block--sharepreview">
    <div id="text-block" class="block__body">Message<br>
with<br>
newlines</div>
</div>

This works and looks fine, as you can easily check e.g. using Chrome developer tools.

This change would match what is intended and what already correctly appears after the user clicks to move on to the actual https://web.whatsapp.com page by pressing the 'SEND' button.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants