-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] add NTFY support to enhance notifications options #90
Comments
Feel free to make a PR with this implemented. |
I've been trying to get it working, but no luck on my end. My goal is to add NTFY support, which is basically the same as discord webhook, but notifications can go directly to NTFY (web/app/etc) vs., Discord. It's here: https://www.npmjs.com/package/ntfy. Apprise itself is a bigger job, but would enable notifications to any service, but personally my own use is just NTFY which should be easier. |
I'm working on this FR now (since it's mine, just haven't had time to revisit in a while). This will let users optionally receive push notifications via NTFY (optionally) - https://github.com/binwiederhier/ntfy. My ideal use of this is to push 2FA and passwordless codes out via notification. And, to send a summary however webhook currently sends info (log, error, etc.) |
Update: starting a test branch with push notification support, notifications use NTFY with only output logs that match key words of 'completed' (e.g., all tasks completed), '2fa', and any warn or error. I'll have that up as a test branch shortly. Webhook support is untouched. My goal with push notifications is:
ToDo:
|
Experimental support pushed to: https://github.com/mgrimace/Microsoft-Rewards-Script/tree/1.5 Working:
Next:
Please anyone is welcome and encouraged to test and suggestions/review requested. |
Oddly enough, whether I use With the snippet from Logger.ts: // Send to NTFY only for specific logs
if (type === 'warn' || type === 'error' ||
message.toLowerCase().includes('completed tasks for') ||
message.toLowerCase().includes('press the number') ||
message.includes('2FA')) {
Ntfy(cleanStr);
} |
Maybe the process exited first. Try awaiting ntfy |
Thanks, I’ll take a look at that. Since I am getting some ‘completed’ but not all (and all the warns/errors) I’m thinking it’s my rough Ntfy.ts. My guess is that I need to properly format the title/content and I might be hitting a character limit if it’s coming through as a ‘title’ only or something like that. Basically, I need to spend some time in the NTFY docs: https://docs.ntfy.sh/publish/#__tabbed_1_4 I am getting notifications though, which is a start! |
Ok, I solved it! I was trying to use webhook like the existing discord functionality, but I swapped Ntfy.ts to use Curl instead and it's working much better and sending things. Fixed titles, body, priority, and emoji icons. I'll tidy up my debugging, and everything then push an update to my branch for further testing |
update pushed to my test branch with everything working as expected now. Logger.ts has a block added specific to NTFY. Since they're push notfications, we only want key notices:
Other keyword based entries are welcome/encouraged. Logger also sends the type (log, warn, or error) to Ntfy.ts, which prioritizes the notification (warn/error = high, log = default) and associates a particular emoji for the notification (e.g., alert emoji for errors). Again, testing, review, contributions welcome/encouraged. I've added/removed a lot of debugging lines, and I'm pretty sure I pushed just the necessary changes but who knows. |
I would try sticking with Axios, as not all systems—especially some Windows environments—have cURL installed, and Axios may be more efficient |
Yeah, I just wasn’t able to get it working consistently using the existing axios webhook vs., a direct curl despite all my efforts. I don’t know enough about Axios, but if it’s possible to convert/send a curl style request through Axios (vs., webhook) that would be idea. If you have advice/suggestions how to do this, please take a look at my Ntfy.ts. Its above my skills, but I’ll work on it. I was trying to piggyback on the current Axios/webhook, but for whatever reason some messages wouldn’t send while others would. The issue appears to be in formatting or structuring the message properly to send this way. All of that to say, NTFY works well now with CURL. And, it doesn’t impact the functioning of the existing webhook/discord if people prefer that method + Axios for more detailed logs. The benefit of NTFY is a quick self-hosted push notification, especially to receive 2FA codes and confirmation of runs, but it isn’t required in any way for the script to function (for me, just a quick text that says ‘it ran’ or ‘something didn’t finish, run it again’). I’ll test for a bit, see what I can do about Axios - review/PRs welcome! |
Ok, testing an update to attempt to use Axios instead of curl for better support (e.g., windows). Update: I cannot get it to send via axios vs., curl. I'll tidy up what I've got, add a note to the readme, and send over a PR for review. It's a definitely an option for folks, and it won't break any existing functionality (e.g., webhook as an alternative with more fulsome logs and no need for curl). |
AariaX@7fc399f just simple await |
You're amazing thanks so much! Your solution is much tidier, and I didn't know how to pull the pieces together myself to get it working. What do you think of the key words? They could use some tuning - I get the same as your screenshot but for two accounts = 4 notifications (e.g., completed for 'all' and for 'email', which seems redundant). I worked through the logs and picked out things I thought would be useful, but could use some other eyes on it. The icon/emoji can also be changed in Ntfy.sh - 'trophy' looks good for the [logs] as well. Edit: adding keywords |
Yeah completed for all is not helpful with clusters unless we can actually get it to log correctly |
Yeah, the challenge has been getting the right keywords to filter everything marked [LOG]. An alternative might be to mark some entries (like started, 2fa, completed) as [STATUS] or something if possible, then just send the entire category as notifications instead of using keywords. That might help with localization/different languages perhaps? How do you want to move forward with PRs and such? I plan to add some instructions to the readme and revise the keywords in the short term - would you like to use your fork as the base? |
I actually had a prototype for log filtering, which was a config option with the option to exclude functions. example |
Feel free to go ahead with your fork. I don’t plan to dedicate much time to this. |
On it, testing your fixes, and some improvements for keywords then I'll push those changes to my test branch. Once I get some basic instructions in, I think it'll be ready for a PR back to main for review. Longer term goals would be that conditional logging, and generating notifications based on type vs keyword, but this should work fine in the short-term Edit: using test branch: https://github.com/mgrimace/Microsoft-Rewards-Script/tree/ntfy |
Added instructions
|
'Completed tasks for account email' was not showing up in my logs, I had to also add await log('main', 'MAIN-WORKER', `Completed tasks for account ${account.email}`, 'log', 'green')
}
await log(this.isMobile, 'MAIN-PRIMARY', 'Completed tasks for ALL accounts', 'log', 'green')
process.exit()
} |
I do not get 'the script collected xxx points today' log item. Created a separate issue #226 so it's not buried here. I did add keyword 'the script collected' to Logger.ts so it can be sent as a push notification if the point summary can be fixed in the logs. |
For simplicity, I closed PR #227, and I'm working fresh from the new 1.5 release for NTFY support. I've added back in all the recent (working) changes to my branch: https://github.com/mgrimace/Microsoft-Rewards-Script/tree/ntfy I'll double check that everything is still working as expected then re-open a tidier PR |
Updating FR for enhanced notifications
Apprise is a flexible notification service that allows for not only Discord notifications, but basically notifications to pretty well any service. This would mean that you wouldn't have to implement individual notification services for folks, and people could use their preferred notification method.
Use-case:
The text was updated successfully, but these errors were encountered: