Overflow Tap: speak Overflow's Dashboard API, as its own helper app does

The first cut guessed a write route on Overflow's public API, which documents
only reads for Tap. With the helper app's bundle in hand (Overflow ProPresenter
Integration 1.2.3, read 2026-10-11) the module now makes exactly the calls the
helper makes, against the Dashboard's own backend:

  POST /nonprofit-dashboard/authentication/login/jwt      a Dashboard sign-in → JWT
  GET  /nonprofit-dashboard/propresenter/nonprofits/{id}/keywords
                                                          the Keyword Mappings
  POST …/nonprofits/{id}/keywords?syncNonprofit=true      { keywords } = the switch

So the keyword → destination → Tap groups mapping stays where Overflow keeps
it (Dashboard › Integrations › ProPresenter › Keyword Mappings) and is read
from there: on start, every five minutes, on the tile's refresh button, and
from every trigger's answer. Admin config shrinks to the ProPresenter endpoint,
the Overflow Dashboard login (plus a Nonprofit ID only for an @overflow.co
staff login) and the alert switch; the API-key, Tap-groups, keyword-text and
match-mode fields are gone.

Behaviour follows the helper: both the presentation layer (/v1/status/slide)
and the announcement layer (/v1/announcement/slide_index + /active) are
watched; when a layer's set of matched keywords changes to a non-empty set it
is sent; matching is per word, case-insensitive, punctuation around the word
ignored. The session token is cached across re-inits for the same login so an
admin saving config repeatedly cannot trip Overflow's "too many attempts";
a 401 signs in again once; a refused sign-in is not retried within 20 s.

tools/overflow-tap-mock.js now plays the Dashboard API (any email/password
signs in; --fail-switch, --expire=<s>, --login=<email>:<password>) and gives
the mock ProPresenter an announcement layer (--no-announcements for an older
one). Verified against it: sign-in, keyword load, triggers on both layers,
token expiry → re-login, 500 → NOT SWITCHED + alert + retries, wrong login →
the reason on the tile and in the health line, and recovery. keywords.selftest.js
pins the matching rule (8 cases).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Waters Church
2026-10-11 10:25:02 -04:00
co-authored by Claude Fable 5.1
parent 6b51044be6
commit 459d8b9c38
9 changed files with 738 additions and 622 deletions
+34 -73
View File
@@ -1,13 +1,13 @@
'use strict';
/**
* Self-test for keywords.js — the parsing and matching rules, pinned.
* Self-test for keywords.js — the matching rules, pinned.
*
* node modules/overflow-tap/keywords.selftest.js
*/
const assert = require('node:assert/strict');
const { parseKeywordLines, keywordMatches, matchKeyword, cleanNotes } = require('./keywords');
const { keywordMatches, matchKeywords, sameSet, cleanNotes } = require('./keywords');
let n = 0;
function test(name, fn) {
@@ -21,95 +21,56 @@ function test(name, fn) {
}
}
test('parses keyword = destination, with -> and → too', () => {
const m = parseKeywordLines('give = Give Online\nconnect -> Connect Card\nprayer → Prayer Request');
assert.deepEqual(m.map((x) => [x.keyword, x.destination, x.problem]), [
['give', 'Give Online', ''],
['connect', 'Connect Card', ''],
['prayer', 'Prayer Request', ''],
]);
test('a keyword fires as a word of the notes, whatever the case', () => {
assert.equal(keywordMatches('give', 'give'), true);
assert.equal(keywordMatches('Give', 'give'), true);
assert.equal(keywordMatches('please GIVE today', 'give'), true);
});
test('a trailing @ names the groups for that line', () => {
const [m] = parseKeywordLines('connect = Connect Card @ Lobby, Kids Wing');
assert.equal(m.destination, 'Connect Card');
assert.deepEqual(m.groups, ['Lobby', 'Kids Wing']);
test('surrounding punctuation is ignored, as the helper strips it', () => {
assert.equal(keywordMatches('give!', 'give'), true);
assert.equal(keywordMatches('#give now', 'give'), true);
assert.equal(keywordMatches('go to (give) now', 'give'), true);
assert.equal(keywordMatches('"give"', 'give'), true);
assert.equal(keywordMatches('give.', 'give'), true);
});
test('blank lines and # comments are skipped, line numbers kept', () => {
const m = parseKeywordLines('\n# giving\n\ngive = Give Online\n');
assert.equal(m.length, 1);
assert.equal(m[0].line, 4);
test('a keyword inside another word does not fire', () => {
assert.equal(keywordMatches('a sermon on forgiveness', 'give'), false);
assert.equal(keywordMatches('giveaway', 'give'), false);
assert.equal(keywordMatches('give_now', 'give'), false);
});
test('a line without a separator is a problem, not a crash', () => {
const [m] = parseKeywordLines('give');
assert.equal(m.keyword, 'give');
assert.match(m.problem, /No destination/);
});
test('missing keyword or destination is reported', () => {
const [a, b] = parseKeywordLines('= Give Online\ngive =');
assert.match(a.problem, /No keyword/);
assert.match(b.problem, /No destination/);
});
test('a repeated keyword is flagged and the first line wins', () => {
const m = parseKeywordLines('give = A\nGIVE = B');
assert.equal(m[0].problem, '');
assert.match(m[1].problem, /Repeated/);
assert.equal(matchKeyword('give', m).destination, 'A');
});
test('keywords and destinations may be phrases', () => {
const [m] = parseKeywordLines('next steps = Next Steps Card');
assert.equal(m.keyword, 'next steps');
assert.equal(keywordMatches('Please fill out your Next Steps card', 'next steps', 'word'), true);
});
test('whole word: give does not fire on forgiveness, does on "give!"', () => {
assert.equal(keywordMatches('a sermon on forgiveness', 'give', 'word'), false);
assert.equal(keywordMatches('give!', 'give', 'word'), true);
assert.equal(keywordMatches('Give', 'give', 'word'), true);
assert.equal(keywordMatches('#give now', 'give', 'word'), true);
assert.equal(keywordMatches('giveaway', 'give', 'word'), false);
assert.equal(keywordMatches('give_now', 'give', 'word'), false);
});
test('anywhere: plain substring, like the Overflow helper', () => {
assert.equal(keywordMatches('a sermon on forgiveness', 'give', 'anywhere'), true);
assert.equal(keywordMatches('nothing here', 'give', 'anywhere'), false);
});
test('line: the keyword on its own line only', () => {
assert.equal(keywordMatches('speaker note\ngive\nmore', 'give', 'line'), true);
assert.equal(keywordMatches('give now', 'give', 'line'), false);
assert.equal(keywordMatches(' Give ', 'give', 'line'), true);
test('a phrase keyword is bounded the same way', () => {
assert.equal(keywordMatches('Please fill out your Next Steps card', 'next steps'), true);
assert.equal(keywordMatches('nextsteps', 'next steps'), false);
});
test('regex characters in a keyword are literal', () => {
assert.equal(keywordMatches('go to (give) now', '(give)', 'word'), true);
assert.equal(keywordMatches('give.now', 'give.now', 'anywhere'), true);
assert.equal(keywordMatches('giveXnow', 'give.now', 'anywhere'), false);
assert.equal(keywordMatches('give.now', 'give.now'), true);
assert.equal(keywordMatches('giveXnow', 'give.now'), false);
});
test('empty notes never match; zero-width padding is ignored', () => {
assert.equal(keywordMatches('', 'give'), false);
assert.equal(keywordMatches('​', 'give', 'anywhere'), false);
assert.equal(keywordMatches('​', 'give'), false);
assert.equal(cleanNotes('​give'), 'give');
assert.equal(keywordMatches('​give', 'give', 'line'), true);
assert.equal(keywordMatches('​give', 'give'), true);
});
test('matchKeyword returns the first mapping in admin order', () => {
const m = parseKeywordLines('connect = Connect Card\ngive = Give Online');
assert.equal(matchKeyword('give and connect', m).keyword, 'connect');
assert.equal(matchKeyword('just worship', m), null);
assert.equal(matchKeyword('give', []), null);
test('matchKeywords returns every hit, in list order, once each', () => {
const list = ['connect', 'give', 'prayer', { keyword: 'Events' }];
assert.deepEqual(matchKeywords('give and connect, then events', list), ['connect', 'give', 'Events']);
assert.deepEqual(matchKeywords('just worship', list), []);
assert.deepEqual(matchKeywords('give', []), []);
assert.deepEqual(matchKeywords('give give', ['give', 'GIVE']), ['give']);
});
test('a mapping with a parse problem can still be the match (the caller decides)', () => {
const m = parseKeywordLines('baptism');
assert.equal(matchKeyword('baptism', m).problem.length > 0, true);
test('sameSet compares keyword lists regardless of order and case', () => {
assert.equal(sameSet(['give', 'connect'], ['Connect', 'give']), true);
assert.equal(sameSet(['give'], ['give', 'connect']), false);
assert.equal(sameSet([], []), true);
assert.equal(sameSet(['give'], []), false);
});
console.log(`${n} tests, exit ${process.exitCode || 0}`);