var Clay = require('@rebble/clay'); var clayConfig = require('./config'); var customClay = require('./customClay'); new Clay(clayConfig, customClay); Pebble.addEventListener("ready", function () { Pebble.sendAppMessage({ PKJS_READY: 1 }); }); Pebble.addEventListener("appmessage", function (dict) { if (dict.payload["PKJS_PAVLOK_ZAP"]) { const cfg = JSON.parse(localStorage.getItem('clay-settings')); callAPI(cfg.PKJS_PAVLOK_API_KEY, cfg.PKJS_PAVLOK_ZAP_INTENSITY); } }); function callAPI(apiKey, zap_intensity) { const data = JSON.stringify({ stimulus: { stimulusType: 'zap', stimulusValue: zap_intensity, reason: 'Trigalarm' } }); const xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.open('POST', 'https://api.pavlok.com/api/v5/stimulus/send'); xhr.setRequestHeader('accept', 'application/json'); xhr.setRequestHeader('content-type', 'application/json'); xhr.setRequestHeader('Authorization', 'Bearer ' + apiKey); xhr.send(data); }