TheNetsky / Microsoft-Rewards-Script

Automated Microsoft Rewards script, using TypeScript, Cheerio and Playwright.
133 stars 33 forks source link

[Feature Request] add apprise support to enhance notifications options #90

Open mgrimace opened 3 months ago

mgrimace commented 3 months ago

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.

A sample Webhook.ts could look like:

import axios from 'axios'
import Apprise from 'apprise';
import { loadConfig } from './Load'

export async function Webhook(content: string) {
    const webhook = loadConfig().webhook

    if (!webhook.enabled || webhook.url.length < 10) return

    const request = {
        method: 'POST',
        url: webhook.url,
        headers: {
            'Content-Type': 'application/json'
        },
        data: {
            'content': content
        }
    };

    // Send webhook
    await axios(request).catch(() => {});

    // Send Apprise notification if enabled
    if (config.apprise.enabled && config.apprise.url.length > 0) {
        const apprise = new Apprise();
        apprise.add(config.apprise.url);
        apprise.notify('Notification sent!');
    }
}

With a sample config like:

{
    "baseURL": "https://rewards.bing.com",
    "sessionPath": "sessions",
    "headless": true,
    "runOnZeroPoints": false,
    "clusters": 2,
    "saveFingerprint": false,
    "workers": {
        "doDailySet": true,
        "doMorePromotions": true,
        "doPunchCards": true,
        "doDesktopSearch": true,
        "doMobileSearch": true
    },
    "searchSettings": {
        "useGeoLocaleQueries": true,
        "scrollRandomResults": true,
        "clickRandomResults": true,
        "searchDelay": {
            "min": 180000,
            "max": 270000
        },
        "retryMobileSearch": true
    },
    "webhook": {
        "enabled": false,
        "url": ""
    },
    "apprise": {
        "enabled": true,
        "url": "apprise://"    
    }
}

Notifications follow the format: https://github.com/caronc/apprise?tab=readme-ov-file#supported-notifications for example, Discord would be: discord://webhook_id/webhook_token

I'm not making a PR because I fundamentally don't understand Node.js nor how to install apprise as a dependency within the actual script itself to enable this functionality. I'm reading up where I can, and in the meantime I'm hoping it would be relatively straightforward to implement, and would enable a lot more flexibility with notifications/logging, etc. I fully recognize the original author may have zero need for this, and I'm hoping anyone else knowledgeable could contribute.

TheNetsky commented 3 months ago

Feel free to make a PR with this implemented.

mgrimace commented 2 months ago

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.