1

I'm using telethon python3 library and I'm a bit stuck on this issue:

client = TelegramClient(session, api_id, api_hash).start()
client.send_message(recipient, string_message)

I try to split the message into multiple lines but I'm not able to find what char (or combination of chars) should be used for that. (for example **text** will make text, __text__ will make text, etc)

Obviously \n is not working. I found some ideas about inserting the chr(10) as new line mark in the string_message but I had no success with it.

tethis
  • 11
  • 3
  • \n\n? What does \n do? (Do you have a quoting error with the \) – 2e0byo Nov 01 '21 at 22:03
  • Actually I guess is more like a python interpretation of the string passed as argument in `client.send_message(str(sys.argv[1]), sys.argv[2])`. If i use it directly in the code with a hardcoded string like `client.send_message(str(sys.argv[1]), "line1\nline2")` it will send the message as expected, with two lines. – tethis Nov 02 '21 at 06:23
  • I got the expected result after reading `https://stackoverflow.com/questions/65005261/passing-a-string-with-spaces-and-newlines-as-command-line-argument-python` and using my own `delimiter` in the passed string (sys.argv) and replacing the delimiter in the code at runtime with `\n` just prior to passing the variable to telethon client. – tethis Nov 02 '21 at 06:33
  • 1
    @tethis welcome to StackOverflow. If you solved the problem, you can also answer your own question and marked it as accepted. – Lonami Nov 02 '21 at 14:08

1 Answers1

0

(answering my own question here): I got the expected result after reading https://stackoverflow.com/questions/65005261/passing-a-string-with-spaces-and-newlines-as-command-line-argument-python and using my own delimiter in the passed string (sys.argv) and replacing the delimiter in the code at runtime with \n just prior to passing the variable to telethon client.

  • In my initial question I was passing the message as argument to a python script and inside the script the content of sys.argv was again cast/converted to string (str(sys.argv[x])) and most probably this was breaking the \n formatting*
tethis
  • 11
  • 3