Sending alerts and notifications through the API
Closed this issue · 4 comments
OS
Raspbian GNU/Linux 11 (bullseye)
NodeJS Version
20.8.0
MagicMirror² Version
2.25.0
Remote Control Version
2.3.8
Did you try using just Remote Control alone with MM?
- I have and the error still happening
Description
I'm trying to display messages to the MagicMirror (notifications or alerts) by doing a curl request and calling MMM-Remote-Control's API, but I can't make it work.
I tried various ways:
1st test:
curl -X GET http://MagicMirrorIPAddress:8080/remote?action=SHOW_ALERT&type=notification&title=TestTitle&message=TestMessage&timer=30?apiKey=_mysuperAPIKeyNumber_
2nd test:
curl -X POST http://MagicMirrorIPAddress:8080/api/module/alert/showalert \ -H 'Authorization: apiKey _mysuperAPIKeyNumber_' \ -H 'content-type: application/json' \ -d '{ "title": "Hello World!", "message": "Alert Successfully Shown!", "timer": 2000 }'
I'm probably doing things wrong, but could you please provide some guidance on the correct way to do this ?
Thank you.
Expected behavior
Alert or notification being displayed on MagicMirror
Current behavior
1st test:
It pops an alert on the Magic mirror which only shows "NOTE" as a title and "Attention!" as the message no matter what we put as a title and message.
2nd test:
Nothing displays on the screen. Error displayed on the logs
Possible solution
No response
Steps to reproduce
Open a CLI and try to do a curl with the provided commands
Log
[12.10.2023 18:20.29.621] [ERROR] TypeError: Cannot read properties of undefined (reading 'showalert')
at Class.answerModuleApi (/MagicMirror/modules/MMM-Remote-Control/API/api.js:411:36)
at /MagicMirror/modules/MMM-Remote-Control/API/api.js:278:22
at Layer.handle [as handle_request] (/MagicMirror/node_modules/express/lib/router/layer.js:95:5)
at next (/MagicMirror/node_modules/express/lib/router/route.js:144:13)
at next (/MagicMirror/node_modules/express/lib/router/route.js:140:7)
at Route.dispatch (/MagicMirror/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/MagicMirror/node_modules/express/lib/router/layer.js:95:5)
at /MagicMirror/node_modules/express/lib/router/index.js:284:15
at param (/MagicMirror/node_modules/express/lib/router/index.js:365:14)
at param (/MagicMirror/node_modules/express/lib/router/index.js:376:14)
at param (/MagicMirror/node_modules/express/lib/router/index.js:376:14)
at param (/MagicMirror/node_modules/express/lib/router/index.js:376:14)
at Function.process_params (/MagicMirror/node_modules/express/lib/router/index.js:421:3)
at next (/MagicMirror/node_modules/express/lib/router/index.js:280:10)
at /MagicMirror/modules/MMM-Remote-Control/API/api.js:151:13
at Layer.handle [as handle_request] (/MagicMirror/node_modules/express/lib/router/layer.js:95:5)
config.js
{
module: 'MMM-Remote-Control',
position: 'bottom_left',
config: {
secureEndpoints: true,
apiKey: '_mysuperAPIKeyNumber_',
showModuleApiMenu: true,
}
},
Additional info
Using the "Alert" page from the remote module sends proper alert and notification with the correct message.
In your first test, [...]&message=TestMessage&timer=30?apiKey=[...]
it's incorrect. In URLs you can only place one ?
, you should replace it with [...]&message=TestMessage&timer=30&apiKey=[...]
Also, this is not a valid issue, as this works as expected. If you're unsure about something, please use the discussions link instead.
Cheers!
I'm sorry but, for test number 2, I just followed what's explain here : https://github.com/Jopyth/MMM-Remote-Control/blob/master/API/README.md#overview
I believe therefore that the it doesn't work as explained, and if I made a mistake, could you please point out which one ?
Thank you ;-)
I've tried with the CURL below, and the alert was shown instantly.
curl -X POST \
'http://localhost:8080/api/module/alert/showalert' \
--header 'Content-Type: application/json' \
--header 'Authorization: apiKey 123' \
--data-raw '{
"title": "Hello World!",
"message": "Alert Successfully Shown!",
"timer": 2000
}'
Check if there's any issues with your Alert module installation.
If you could please share the config.js
complete file, It'll be useful to debug.
On my end, everything seems to work as expected.
Hi Ezequiel,
I have reinstalled everything from scratch, and now it works as expected, you can close this issue.
Thanks for your help and your time :)
K.