Using dockered bbernhard/signal-cli-rest-api in Node-RED

The project https://github.com/bbernhard/signal-cli-rest-api provides a docker container with signal-cli and a REST API. The REST API can be used from Node-RED.

Please be aware that signal-cli-rest-api is not perfect. Specifically, because it uses signal-cli it fires up java engine for every command and therefore the speed is sub par compared to nodered-contrib-signal-client. Similarly, I did not find a way to subscribe permanently to signal for incoming messages. I ended up sending a poll request for new messages every 5 seconds.

Since I used nodered-contrib-signal-client before, I built some facade around bbernhard/signal-cli-rest-api, because I did not want to change all my flows that use signal.

Here is my steps how to replace nodered-contrib-signal-client with signal-cli-rest-api.

  1. Setup docker with bbernhard/signal-cli-rest-api

    • If you want to be able to send attachments that are stored on a filesystem (as required for nodered-contrib-signal-client), define a volume to which Node-RED and the new container have access.

    • Assuming Node-RED runs in a container as well; in order for Node-RED to reach signal-cli-rest-api, you have to either add signal-cli-rest-api to the same stack as Node-RED, or you create it in another stack and let them use a shared network.

  2. Create your signal account within signal-cli-rest-api

    • Details about the API can be found here.

    • Either link an existing account with qrcodelink or

    • register a number from scratch. I used:

      a. curl -X 'POST' \\n 'http://signal-cli-rest-api:9880/v1/register/%2B491701234567' \\n -H 'accept: application/json' \\n -H 'Content-Type: application/json' \\n -d '{\n "captcha": "---fill captcha code here---",\n "use_voice": true\n}'

      b. curl -X 'POST' \\n 'http://signal-cli-rest-api:9880/v1/register/%2B491701234567/verify/---token from SMS or voice call---' \\n -H 'accept: application/json' \\n -H 'Content-Type: application/json' \\n -d '{\n "pin": "---enter PIN here---"\n}'

  3. Create flow in Node-RED to replace nodered-contrib-signal-client (see example below).

    Pasted Graphic 1 Pasted Graphic 2
[{"id":"18a109e5.acc0c6","type":"http request","z":"d59c2a5f.640508","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://signal-cli-rest-api:8080/v1/receive/%2B491701234567?timeout=1","tls":"","persist":false,"proxy":"","authType":"","x":330,"y":240,"wires":[["f774cb99.6b0fe8"]]},{"id":"103cfa70.73cf96","type":"inject","z":"d59c2a5f.640508","name":"receive","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":240,"wires":[["18a109e5.acc0c6"]]},{"id":"f774cb99.6b0fe8","type":"switch","z":"d59c2a5f.640508","name":"filter empty (no msg)","property":"payload","propertyType":"msg","rules":[{"t":"nempty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":560,"y":240,"wires":[["ca8c602c.38cab","19b8ce49.673d92"],["19b8ce49.673d92"]]},{"id":"ca8c602c.38cab","type":"split","z":"d59c2a5f.640508","name":"split multiple msg","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":790,"y":240,"wires":[["87f270aa.057c3"]]},{"id":"19b8ce49.673d92","type":"debug","z":"d59c2a5f.640508","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":740,"y":180,"wires":[]},{"id":"87f270aa.057c3","type":"change","z":"d59c2a5f.640508","name":"erase all but envelope","rules":[{"t":"move","p":"payload.envelope","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":300,"wires":[["ca9a5d56.d1155","5092079b.209798"]]},{"id":"e625caf0.f85058","type":"change","z":"d59c2a5f.640508","name":"convert to nodered-contrib-signal-client","rules":[{"t":"move","p":"payload.dataMessage.message","pt":"msg","to":"payload.content","tot":"msg"},{"t":"move","p":"payload.source","pt":"msg","to":"payload.senderNumber","tot":"msg"},{"t":"set","p":"payload.receiverNumber","pt":"msg","to":"signal_account","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":400,"wires":[["407cb04.df0e75"]]},{"id":"ca9a5d56.d1155","type":"switch","z":"d59c2a5f.640508","name":"filter for msg with text","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"dataMessage","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":240,"y":400,"wires":[["56898e0f.4365d"],[]]},{"id":"407cb04.df0e75","type":"link out","z":"d59c2a5f.640508","name":"send signal msg to my original flows","links":["3dfa287b.cdf5f8"],"x":955,"y":400,"wires":[]},{"id":"5092079b.209798","type":"debug","z":"d59c2a5f.640508","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.dataMessage.message","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":300,"wires":[]},{"id":"a1715ef8.bff5e","type":"comment","z":"d59c2a5f.640508","name":"This is the receiving part","info":"","x":190,"y":160,"wires":[]},{"id":"7ff46239.4a91ec","type":"http request","z":"d59c2a5f.640508","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"http://signal-cli-rest-api:8080/v2/send","tls":"","persist":false,"proxy":"","authType":"","x":1050,"y":940,"wires":[["c8660f3b.b0483"]]},{"id":"2a2e10c8.1371f","type":"inject","z":"d59c2a5f.640508","name":"send test msg","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":760,"wires":[["b8cad2b5.4cade"]]},{"id":"c8660f3b.b0483","type":"debug","z":"d59c2a5f.640508","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":940,"wires":[]},{"id":"b8cad2b5.4cade","type":"change","z":"d59c2a5f.640508","name":"fill test msg","rules":[{"t":"set","p":"payload.message","pt":"msg","to":"test msg 123","tot":"str"},{"t":"set","p":"payload.number","pt":"msg","to":"+491701234567","tot":"str"},{"t":"set","p":"payload.recipients","pt":"msg","to":"[\"+49receiver\"]","tot":"jsonata"},{"t":"set","p":"payload.timestamp","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":760,"wires":[["7ff46239.4a91ec"]]},{"id":"fda7d776.bc1928","type":"link in","z":"d59c2a5f.640508","name":"in: send classical signal to signal-cli","links":[],"x":55,"y":820,"wires":[["2a57420.5f005be"]]},{"id":"a6155f88.d0f2f","type":"change","z":"d59c2a5f.640508","name":"convert to signal-cli","rules":[{"t":"move","p":"payload.content","pt":"msg","to":"payload.message","tot":"msg"},{"t":"set","p":"payload.number","pt":"msg","to":"signal_account","tot":"msg"},{"t":"set","p":"payload.recipients","pt":"msg","to":"[msg.payload.receiverNumber]\t","tot":"jsonata"},{"t":"delete","p":"payload.receiverNumber","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":820,"wires":[["7ff46239.4a91ec"]]},{"id":"1c055fac.a0734","type":"change","z":"d59c2a5f.640508","name":"convert to signal-cli","rules":[{"t":"move","p":"payload","pt":"msg","to":"base64_attachments","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{\t\"message\": $.content != null ? $.content : $.command,\t\"number\" : $.signal_account\t}\t","tot":"jsonata"},{"t":"set","p":"payload.recipients","pt":"msg","to":"[msg.receiverNumber]\t","tot":"jsonata"},{"t":"set","p":"payload.base64_attachments","pt":"msg","to":"base64_attachments","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":1080,"wires":[["7ff46239.4a91ec"]]},{"id":"35eb98a8.b24a18","type":"switch","z":"d59c2a5f.640508","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"attachments","vt":"str"},{"t":"hask","v":"content","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":3,"x":350,"y":820,"wires":[["24263647.6ca2da"],["a6155f88.d0f2f"],[]]},{"id":"23e9a581.2b046a","type":"file in","z":"d59c2a5f.640508","name":"load attachment","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":480,"y":1000,"wires":[["4ec3ab76.cfdc14"]]},{"id":"4ec3ab76.cfdc14","type":"base64","z":"d59c2a5f.640508","name":"","action":"str","property":"payload","x":680,"y":1000,"wires":[["83a31fab.8e7f8"]]},{"id":"8c00f893.cf30b8","type":"split","z":"d59c2a5f.640508","name":"split for list of attachments","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":520,"y":920,"wires":[["2be8d181.2b34ee"]]},{"id":"24263647.6ca2da","type":"change","z":"d59c2a5f.640508","name":"","rules":[{"t":"set","p":"receiverNumber","pt":"msg","to":"payload.receiverNumber","tot":"msg"},{"t":"set","p":"content","pt":"msg","to":"payload.message","tot":"msg"},{"t":"move","p":"payload.attachments","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"filename","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":920,"wires":[["8c00f893.cf30b8"]]},{"id":"83a31fab.8e7f8","type":"join","z":"d59c2a5f.640508","name":"join all attachments into list","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":520,"y":1080,"wires":[["1c055fac.a0734"]]},{"id":"2be8d181.2b34ee","type":"change","z":"d59c2a5f.640508","name":"move filename","rules":[{"t":"move","p":"payload","pt":"msg","to":"filename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":1000,"wires":[["23e9a581.2b046a"]]},{"id":"ea055ecb.d1895","type":"comment","z":"d59c2a5f.640508","name":"This is the sending part","info":"","x":140,"y":700,"wires":[]},{"id":"2a57420.5f005be","type":"change","z":"d59c2a5f.640508","name":"set account #","rules":[{"t":"set","p":"signal_account","pt":"msg","to":"+491701234567","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":180,"y":820,"wires":[["35eb98a8.b24a18"]]},{"id":"56898e0f.4365d","type":"change","z":"d59c2a5f.640508","name":"set account #","rules":[{"t":"set","p":"signal_account","pt":"msg","to":"+491701234567","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":400,"wires":[["e625caf0.f85058"]]}]

Flow Info

Created 2 years, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x9)
  • comment (x2)
  • debug (x3)
  • file in (x1)
  • http request (x2)
  • inject (x2)
  • join (x1)
  • link in (x1)
  • link out (x1)
  • split (x2)
  • switch (x3)
Other

Tags

  • signal
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option