Any way to send text with newlines with signal-cli? #653
Answered
by
exquo
garryadkins
asked this question in
Q&A
-
I'd like to be able to send messages with newline characters in them. The formatting would make them easier to read. Is there any way to do this? Passing \n doesn't seem to work. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
exquo
Jun 28, 2021
Replies: 3 comments 2 replies
-
If typing a message on the command line, press
In
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
AsamK
-
I got this to work in Linux by passing ~ to the script and in python
changing that to a carriage return. It works perfectly for me now on a
Raspberry Pi. I could NOT seem to pass it a newline, it just always sent
\n no matter how I massaged it. That's why I used ~ instead.
Not sure what language you're using but here's teh relevant code I use in
python.
#Now we split on ~ so we can create newline chars in string.
#For some reason we can't seem to parse \n properly
# incoming_msg[0] is the text of the message.
#Here we split it and recombine to add newlines if they exist.
message_text_raw=str(incoming_msg[0]).split('~')
for i in message_text_raw:
message_text_w_newline= message_text_w_newline + "\n" + i
# Add a newline and the current date and time
#message_text_w_newline= message_text_w_newline +
"\n\n**********\nSent:\n" + datetime.now().strftime('%H:%M:%S\n%m-%d-%Y')
message_text_w_newline= message_text_w_newline +
"\n\n**********\nSent:\n" + datetime.now().strftime('%m-%d-%Y\n%H:%M:%S')
incoming_msg[0]=message_text_w_newline
Hope this helps.
…On Fri, Aug 13, 2021 at 2:52 PM Kweazll ***@***.***> wrote:
Any help on doing this on Windows?
Do not seem to get it to work with the above in a powershell nor cmd.
A '^' to simulate the Enter press inside an un-closed quote won't work
either, nor do the options in #105
<#105>.
The '\n' is simply sent in plain text within the message, or "Failed to
send message: No valid characters found." is returned.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#653 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUUVBX3H3J7NVTJL4AM7P23T4VZXHANCNFSM47NNAUOA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
--
Garry Adkins
****************************************************
https://www.linkedin.com/in/garryadkins/
***@***.***
251-487-1803 (c)
|
Beta Was this translation helpful? Give feedback.
1 reply
-
I am receiving the message from a MQTT broker.
The incoming_message is an object with several different things like topic,
payload, qos and retain flags. payload is the actual message I'm
interested in.
The incoming message is a comma delimited list of things, so I split it
into an array based on the comma: It is cast to a str (see the code below)
message_text_raw contains a long string with ~ chars instead of newlines.
They are converted to \n and placed into the string
message_text_w_newline. This is what I pass to signal_cli
Here's the example code:
#Incoming message should have *"message to send", phone1, phone2, *etc.
#We split this message into a list so we can append to the signal_msg
above
incoming_msg=*str*(msg.payload).split(',')
#Now we split on ~ so we can create newline chars in string.
#For some reason we can't seem to parse \n properly
*# incoming_msg[0] is the text of the message.*
#Here we split it and recombine to add newlines if they exist.
message_text_raw=str(incoming_msg[0]).split('~')
for i in message_text_raw:
message_text_w_newline= message_text_w_newline + "\n" + i
I run the signal command line (again this is unix, not sure if this will
work in windows)
# Run as a subprocess so we can fork and continue
subprocess.Popen(signal_msg)
signal_msg just has the command line parms to signal_cli
#This is a test message known to work. (signal sender ends with 6666
and the recipient ends with 7777)
# This just sends the message "test"
#signal_msg = ["/usr/local/bin/signal-cli", "-u","+12225556666",
"send", "-m", "test", "+12225557777"]
You would obviously replace "test" with the string that you create.
Here's what one of the messages sent by this method looks like:
Door Battery Report
Kitchen: 100%
Front: 65%
Pool: 6%
2nd Guest: 73%
**********
Sent:
08-14-2021
17:59:59
And the received message looks like this before parsing:
topic/signal_message=Door Battery Report~~Kitchen: 100%:~Front: 65%~Pool:
6%~2nd Guest:73%,+12225557777
This string is parsed and replaced ~ with \n as you can see in the message
above.
Door Battery Report~~Kitchen: 100%:~Front: 65%~Pool: 6%~2nd Guest:73%
…On Sun, Aug 15, 2021 at 1:51 PM Kweazll ***@***.***> wrote:
Thanks for the swift reply.
Yes using python as well.
That still does not do the job though...
What is the incoming_msg datatype and how are you sending the message? I
only receive the message before the newline character, so in the below
example i receive: This is
I am calling:
from datetime import datetime
now = datetime.now() # current date and time
incoming_msg = 'Alsopartofthetest'
message_text_raw=str(incoming_msg).split('~')
message_text_w_newline = str('This is \n a test')
for i in message_text_raw:
message_text_w_newline= message_text_w_newline + "\n" + i
# Add a newline and the current date and time
message_text_w_newline= message_text_w_newline + "\n\n**********\nSent:\n"
+ now.strftime('%m-%d-%Y\n%H:%M:%S')
incoming_msg=message_text_w_newline
I then call some functions to compile the command (" ".join etc.) and
print the command:
cli_arg = signal-cli -u +xxxxxxxx send +xxxxxxxx -m "This is
a test
Also
part
of
the
test
------------------------------
Sent:
08-15-2021
20:45:51"
feedback = subprocess.Popen(cli_arg,shell=True, stdout=subprocess.PIPE)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#653 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUUVBX5DD3OPKKM5IJGHKHTT5AEE3ANCNFSM47NNAUOA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
--
Garry Adkins
****************************************************
https://www.linkedin.com/in/garryadkins/
***@***.***
251-487-1803 (c)
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If typing a message on the command line, press
Enter
inside an un-closed quote:In
bash
it's also possible to put\n
chars inside the$'string'
s: