Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

SMS and push notifications

Igor Ramadas edited this page Nov 22, 2019 · 5 revisions

Jarbunq can send notifications to smartphones and other devices by using 3rd party notification services. By default, it's pre-configured to use Pushover, but you could easily change the settings to use other services that support push notifications via REST APIs.

Enabling Pushover

If you don't have an account, head on to https://pushover.net and create one. Pushover will charge a one-time fee for the actual smartphone apps (usually 4.99 on Android). I think it's cheap and worth the price.

After creating your account, on the Pushover homepage, copy your "Your User Key" token displayed on the top right to your settings,private.json file, under the key notification.push.post.user.

Now go to the Apps & Plugins tab and then Create New Application / API Token. Name it Jarbunq (or whatever name you like), fill in the additional details (description, icon etc) and then click the "Create Application" button. Now on the application details page you should see the "API Token/Key" field with the app token. Copy is value to your settings.private.json file, key notification.push.post.token.

Finally set the notification.push.enabled setting to true.

In the end you should have something like this:

{
    "notification": {
        "push": {
            "enabled": true,
            "post": {
                "token": "MY-APP-TOKEN",
                "user": "MY-USER-TOKEN",
                "device": "device-name, or null"
            }
        }

    }
}

Custom notification handlers

Custom code can be easily integrated via the plugins.ts file on the /src folder. If it does not exist, you can create one. On this file you can listen to the toEmail and toPush notification events, and do whatever you need to call your custom notification service.

Sample plugins.ts for SMS notifications

export = () => {
    const logger = require("anyhow")
    const notifications = require("./notifications")
    const settings = require("setmeup").settings

    const toSMS = (options) => {
        let smsNumber = settings.sms.number // your custom phone number
        // Put some code here that will connect to your SMS API and send the notification
        // myCustomModule.sendSMS(options.subject, options.message)

        logger.info("Plugins.toSMS", options)
    }

    // Listen to email and push notification events.
    notifications.on("toEmail", toSMS)
    notifications.on("toPush", toSMS)
}