Yowsup: Send breakLine through yowsup-cli

Created on 12 Jan 2015  ·  11Comments  ·  Source: tgalal/yowsup

Tried using n, /n, n on message but didn't work.

Any suggestion?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Examples enhancement

Most helpful comment

Need to use double slash \n in setBody. but in the cli demo just use one slash. example as below

edit file yowsup/layers/protocol_messages/protocolentities/message_text.py

def setBody(self, body):
    #self.body = body
    self.body = body.replace("\\n","\n")

sudo python setup.py install

./yowsup-cli demos -y -d -c whatsapp_config.txt
/L
/message send 6012XXXXX "Testing 123\nThis text printed in new line\n and this as well"

All 11 comments

Ive done it by replacing
def setBody(self, body):
self.body = body

with

def setBody(self, body):
self.body = body.replace("###","n")

in yowsup/layers/protocol_messages/protocolentities/message_text.py
so every ### in the message text will get replaced with n
i think it would also be prossible to do
.replace("n","n")
which replaced every n in the message text with a NewLine

thanks @dedmen. I fix using
def setBody(self, body):
self.body = body.replace("n","n")

No response when i change the file. i can make what ever i want.
setBody in "yowsup/layers/protocol_messages/protocolentities/message_text.py"

You don't need to modify yowsup's code. When sending a message, use:

mymessage.replace("n", "n")

thats not working anymore, any solution?

Looking too

My solution is not in setBody but in getBody :

# yowsup/layers/protocol_messages/protocolentities/message_text.py

def getBody(self):
    return self.body.replace("\n","\n")

The setBody will receive body as byte string if you replace then it will convert the object to str and it will be rejected.

I confirm that this dedmen code still works!

def setBody(self, body):
self.body = body.replace("###","n")

remove /usr/local/bin/yowsup-cli and recompile

#

not work,
self.body = body.replace("n","n")

Need to use double slash \n in setBody. but in the cli demo just use one slash. example as below

edit file yowsup/layers/protocol_messages/protocolentities/message_text.py

def setBody(self, body):
    #self.body = body
    self.body = body.replace("\\n","\n")

sudo python setup.py install

./yowsup-cli demos -y -d -c whatsapp_config.txt
/L
/message send 6012XXXXX "Testing 123\nThis text printed in new line\n and this as well"

@azizasm : it's works, thank you 👍✨

I encountered the same problem when using the cli on Bash.
I think the problem is Python argument parser will _escape_ the backslash passed in new line (n).
You can check a related Stackoverflow question:
https://stackoverflow.com/questions/34145686/handling-argparse-escaped-character-as-option

So an alternative solution, _without_ modifying the source code is to enclose the message in dollar sign and single quotes like so:
yowsup-cli demos --login [PHONE:PASSWORD] --send [DESTINATION] $'First Line\nSecond Line'

Notice that the message is enclosed in $'......', dollar sign then single quote. This will send a _literal_ new line character versus the default _escaped_ new line character.

A good fix may be to decode the string passed to the argument parser? Something like:
bytes(myStringWithEscapedNewLine, "utf-8").decode("unicode_escape")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qvs5010 picture qvs5010  ·  4Comments

abhiroock picture abhiroock  ·  5Comments

Realitaetsverlust picture Realitaetsverlust  ·  4Comments

bahtiarp picture bahtiarp  ·  4Comments

mannemvamsi picture mannemvamsi  ·  4Comments