UNPKG

tibber-api

Version:

Node.js module for connecting to Tibber API and extract data from your connected homes, including realtime data from Tibber Pulse.

44 lines 1.68 kB
"use strict"; // Uncomment the following line to include tibber-api NPM package instead. // const TibberQuery = require("tibber-api").TibberQuery; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../src/index"); const http_1 = __importDefault(require("http")); const AppScreen_1 = require("../src/models/enums/AppScreen"); const hostname = '127.0.0.1'; const port = 3000; // Config object needed when instantiating TibberQuery const config = { active: true, apiEndpoint: { apiKey: '5K4MVS-OjfWhK_4yrjOlFe1F6kJXPVf7eQYggo8ebAE', // Demo token queryUrl: 'https://api.tibber.com/v1-beta/gql', }, }; // Instance of TibberQuery const tibberQuery = new index_1.TibberQuery(config); // your push config const message = 'TEST_MESSAGE'; const title = 'TEST_TITLE'; const screenToOpen = AppScreen_1.AppScreen.HOME; // Simple web server. const server = http_1.default.createServer(async (req, res) => { // Call the Tibber API and return the result. switch (req.url) { case '/push': const result = await tibberQuery.sendPushNotification(message, title, screenToOpen); res.statusCode = 200; res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(result)); console.log(JSON.stringify(result)); break; } }); // Start web server. server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); //# sourceMappingURL=push-notification.js.map