OpenHausIO / backend

HTTP API for the OpenHaus SmartHome/IoT solution
https://docs.open-haus.io
6 stars 2 forks source link

Add notification actions #461

Open mStirner opened 6 months ago

mStirner commented 6 months ago

Add actions to notifications (responses), like buttons/inputs.

Draft:

const Joi = require("joi");

module.exports = class Action {

    constructor(options, cb) {

        this.options = Object.assign({

        }, options);

        Object.defineProperty(this, "callback", {
            value: cb,
            enumerable: false,
            configurable: false,
            writable: false
        });

    }

    static schema() {
        return Joi.object({
            title: Joi.string().required(),
            type: Joi.string().valid("boolean", "string", "number"),
            display: Joi.string().valid("input", "button")
        });
    }

    static validate(data) {
        return Action.schema().validate(data);
    }

    apply(value) {
        this.callback(value);
    }

};

Comparable to gotify actions: https://gotify.net/docs/msgextras#androidaction