[ { "id": "dfca366fec3a6fb8", "type": "comment", "name": "KSeF → SMS every 2 h · read me / przeczytaj mnie", "info": "## KSeF → SMS every 2 hours (8:00–20:00)\n\n**every 2 h, 8–20** (afya-week-calendar) sends a tick every 2 hours between 8:00 and 20:00, every day.\n**KSeF – my company** reads this month's and last month's invoices from KSeF and texts every\n**new sales invoice** (revenue) and **new purchase invoice** (cost): amount, company, bank account, due date, KSeF number.\n\n* **new revenue? / new cost?** – pass on only a non-empty `payload.tekstPrzychody` / `payload.tekstKoszty`,\n* **SMS revenue / SMS cost** – put just the text in `msg.payload`,\n* **vault locked? / SMS vault** – after a Node-RED restart the vault is locked: the node does not ask KSeF and gives a text in `payload.tekstSejf` (once),\n* **SMS to phone** – builds the gateway URL (one function = one phone number; copy it for more people),\n* **SMS gateway** – HTTP request; the gateway token goes in the `X-SMS-Token` header,\n* invoice page: `http://:1880/afya/ksef` – set a page password or token in the KSeF node.\n\nTo set: company NIP and a page password in **KSeF – my company** (the vault is the only way), `NUMBER` and `GATEWAY` in **SMS to phone**,\nthe token in **SMS gateway**. Deploy, open the page and **create the vault**: paste a KSeF token with only\n*przeglądanie faktur* (recommended) and choose a vault password – it is asked for after every restart. The first check only remembers the invoices –\nSMS messages start with the second one. **test SMS** sends the newest invoices right away.\n\nNo afya-week-calendar? Use an *inject* node with cron `0 8-20/2 * * *`.\nOne check = 4 KSeF queries; KSeF allows 20 per hour.\n\n## Po polsku\n\nCo 2 godziny (8–20) węzeł **KSeF – my company** sprawdza faktury i wysyła SMS o każdej **nowej fakturze sprzedaży**\n(przychód) i **zakupu** (koszt). Ustaw: NIP firmy i hasło strony w węźle KSeF (sejf jest obowiązkowy), `NUMBER` i `GATEWAY` w funkcji **SMS to phone**,\ntoken w węźle **SMS gateway**. Wdróż, otwórz stronę i **utwórz sejf**: wklej token KSeF tylko z *przeglądaniem faktur*\n(zalecane) i ustaw hasło do sejfu – strona zapyta o nie po każdym restarcie (do tego czasu przychodzi 1 SMS).\nPierwsze sprawdzenie tylko zapamiętuje faktury – SMS-y przychodzą od drugiego. **test SMS** wysyła najnowsze faktury.", "x": 330, "y": 220, "wires": [] }, { "id": "343a818c49ef545c", "type": "afya-week-calendar", "name": "every 2 h, 8–20", "schedule": [ [ [ 480, 1200, 1 ] ], [ [ 480, 1200, 1 ] ], [ [ 480, 1200, 1 ] ], [ [ 480, 1200, 1 ] ], [ [ 480, 1200, 1 ] ], [ [ 480, 1200, 1 ] ], [ [ 480, 1200, 1 ] ] ], "snap": 15, "states": [ { "name": "OFF", "value": "", "vt": "num" }, { "name": "ON", "value": "", "vt": "num" } ], "timezone": "", "randomize": 0, "periodMode": "always", "periods": [], "outputType": "bool", "topic": "", "sendOnStart": true, "tick": true, "tickEvery": "2", "tickUnit": "h", "outputs": 2, "lang": "auto", "variableName": "", "scope": "global", "x": 270, "y": 320, "wires": [ [], [ "b710101872b64ea7" ] ] }, { "id": "57e5f1dba41f9495", "type": "inject", "name": "test SMS (msg.test)", "props": [ { "p": "57e5f1dba41f9495", "v": "true", "vt": "bool" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 290, "y": 380, "wires": [ [ "b710101872b64ea7" ] ] }, { "id": "b710101872b64ea7", "type": "afya-ksef", "name": "KSeF – my company", "lang": "auto", "srodowisko": "prod", "nip": "", "identyfikator": "certificateSubject", "kwoty": "brutto", "typDaty": "Issue", "poprzedni": true, "przychody": true, "szablonPrzychody": "", "koszty": true, "szablonKoszty": "", "zSuma": false, "bezPl": false, "przelewy": true, "kwotaPrzelewu": "brutto", "separator": ".", "formatPrzelewow": "nest-xml", "variableName": "", "scope": "global", "tytulStrony": "", "sciezka": "afya/ksef", "x": 530, "y": 320, "wires": [ [ "19fb7bfbfd154671", "e2f1ead64bc7200d", "6b2ffe6e05a9ef5d" ] ], "przypomnienieSejfu": "raz" }, { "id": "19fb7bfbfd154671", "type": "switch", "name": "new revenue?", "property": "payload.tekstPrzychody", "propertyType": "msg", "rules": [ { "t": "nempty" } ], "checkall": "true", "repair": false, "outputs": 1, "x": 760, "y": 260, "wires": [ [ "1cba534d7b20793a" ] ] }, { "id": "1cba534d7b20793a", "type": "change", "name": "SMS revenue", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.tekstPrzychody", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 950, "y": 260, "wires": [ [ "a1a8ca27eb456ade" ] ] }, { "id": "e2f1ead64bc7200d", "type": "switch", "name": "new cost?", "property": "payload.tekstKoszty", "propertyType": "msg", "rules": [ { "t": "nempty" } ], "checkall": "true", "repair": false, "outputs": 1, "x": 750, "y": 320, "wires": [ [ "3abf863da0ea00d2" ] ] }, { "id": "3abf863da0ea00d2", "type": "change", "name": "SMS cost", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.tekstKoszty", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 940, "y": 320, "wires": [ [ "a1a8ca27eb456ade" ] ] }, { "id": "6b2ffe6e05a9ef5d", "type": "switch", "name": "vault locked?", "property": "payload.tekstSejf", "propertyType": "msg", "rules": [ { "t": "nempty" } ], "checkall": "true", "repair": false, "outputs": 1, "x": 760, "y": 380, "wires": [ [ "b26d51322a9a4849" ] ] }, { "id": "b26d51322a9a4849", "type": "change", "name": "SMS vault", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.tekstSejf", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 950, "y": 380, "wires": [ [ "a1a8ca27eb456ade" ] ] }, { "id": "a1a8ca27eb456ade", "type": "function", "name": "SMS to phone", "func": "// One SMS to one phone. The text comes in msg.payload (from \"SMS revenue\" or \"SMS cost\").\nconst NUMBER = '48600000001'; // recipient: 48 + 9 digits\nconst GATEWAY = 'https://sms-gateway.example/send/'; // your SMS gateway\nconst text = typeof msg.payload === 'string' ? msg.payload : msg.payload && msg.payload.tekst;\nif (!text) return null; // never send an empty SMS or \"undefined\"\nmsg.method = 'GET';\nmsg.url = GATEWAY + NUMBER + '?text=' + encodeURIComponent(text);\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1130, "y": 260, "wires": [ [ "294c8d7038d68cd6" ] ] }, { "id": "294c8d7038d68cd6", "type": "http request", "name": "SMS gateway", "method": "GET", "ret": "txt", "paytoqs": "ignore", "url": "", "tls": "", "persist": false, "proxy": "", "insecureHTTPParser": false, "authType": "", "senderr": false, "headers": [ { "keyType": "other", "keyValue": "X-SMS-Token", "valueType": "other", "valueValue": "YOUR_TOKEN" } ], "x": 1270, "y": 320, "wires": [ [ "22b17eda90608b7e" ] ] }, { "id": "22b17eda90608b7e", "type": "debug", "name": "gateway reply", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1470, "y": 320, "wires": [] }, { "id": "02518042df1c0592", "type": "global-config", "env": [], "modules": { "node-red-contrib-afya-ksef": "1.4.3", "node-red-contrib-afya-week-calendar": "0.3.0" } } ]