Logic Machine Forum
Sending notifications with SIGNL4 - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Sending notifications with SIGNL4 (/showthread.php?tid=4522)



Sending notifications with SIGNL4 - CarlS - 23.01.2023

SignL4 is a mobile alerting system.
They have a API, and have some examples at their homepage

Is it possible to use one of these snippets below to send notification from LM5?
The reason why I want to use this system is that I need a constant alert/sound/vibration on the phone until the user responds to the alarm

https://www.signl4.com/inbound-webhook-code-snippets/


RE: Sending notifications with SIGNL4 - admin - 23.01.2023

Try this. Result and/or errors can be seen in the Logs tab.

Code:
secret = '12345'
title = 'alert'
message = 'alert from LM'

http = require('socket.http')
json = require('json')
ltn12 = require('ltn12')

data = json.encode({
  Title = title,
  Message = message,
})

resp = {}
res, code = http.request({
  url = 'https://connect.signl4.com/webhook/' .. secret,
  method = 'POST',
  headers = {
    ['content-type'] = 'application/json',
    ['content-length'] = #data,
  },
  source = ltn12.source.string(data),
  sink = ltn12.sink.table(resp),
})

if res and code == 200 then
  resp = table.concat(tbl)

  log(resp)
else
  log(res, code)
end



RE: Sending notifications with SIGNL4 - CarlS - 23.01.2023

(23.01.2023, 11:37)admin Wrote: Try this. Result and/or errors can be seen in the Logs tab.

Code:
secret = '12345'
title = 'alert'
message = 'alert from LM'

http = require('socket.http')
json = require('json')
ltn12 = require('ltn12')

data = json.encode({
  Title = title,
  Message = message,
})

resp = {}
res, code = http.request({
  url = 'https://connect.signl4.com/webhook/' .. secret,
  method = 'POST',
  headers = {
    ['content-type'] = 'application/json',
    ['content-length'] = #data,
  },
  source = ltn12.source.string(data),
  sink = ltn12.sink.table(resp),
})

if res and code == 200 then
  resp = table.concat(tbl)

  log(resp)
else
  log(res, code)
end


I get res = 1 and code = 404

resp:
"code": 3004,
  "requestId": "b33c1f40-ecb1-4b4c-9a83-a4d15e1e2e8c",
  "details": "No matching event source found.",
  "message": "Error raising event."

When I pase the url+secret in chrome i get this message:
This XML file does not appear to have any style information associated with it. The document tree is shown below.

<ErrorResponseContentBase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Details>You need to POST JSON content to your webhook URL. Find more information at: https://www.signl4.com/developers/webhook/inbound/</Details>
<Message>GET not supported.</Message>
</ErrorResponseContentBase>


RE: Sending notifications with SIGNL4 - admin - 23.01.2023

The Lua code is more or less the same as other examples. Maybe some other fields have to be added to the JSON request. Contact SIGNL4 support.