tgalal / yowsup

The WhatsApp lib
GNU General Public License v3.0
7.09k stars 2.23k forks source link

Send breakLine through yowsup-cli #539

Open Pedro-H-Fialho opened 9 years ago

Pedro-H-Fialho commented 9 years ago

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.

dedmen commented 9 years ago

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

evertonco commented 9 years ago

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

accessburn commented 9 years ago

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

manuelcarrizo commented 9 years ago

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

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

e0xify commented 8 years ago

thats not working anymore, any solution?

chris30o0 commented 8 years ago

Looking too

jackbit commented 7 years ago

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.

riskydigital commented 7 years ago

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")

azizasm commented 7 years ago

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"
riskydigital commented 7 years ago

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

davidheryanto commented 6 years ago

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")