create-heresay 0.2.17 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-heresay",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "Set up your own Heresay: in-app feedback that every report gets a hearing. Creates a Firebase project in your Google account and deploys the dashboard, API and SDK to it.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/release/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.17
1
+ 0.2.18
@@ -125,7 +125,7 @@ export async function notificationSettings(p, req, deps, body) {
125
125
  if (!TELEGRAM_TOKEN.test(token))
126
126
  return json(400, { error: 'That doesn’t look like a bot token. BotFather sends one like 123456789:AAH…' });
127
127
  const now = deps.now(), start = Math.floor(now / 60_000) * 60_000;
128
- if (!await deps.store.hit(`notification-lookup:telegram:${start}`, 12, start + 60_000)) {
128
+ if (!await deps.store.hit(`notification-lookup:telegram:${start}`, 30, start + 60_000)) {
129
129
  return json(429, { error: 'Wait a minute before looking again.' });
130
130
  }
131
131
  if (!deps.telegramLookup)
@@ -1,3 +1,3 @@
1
1
  /** The Heresay release. Bumped by the release script; the CLI and /v1/health report it. */
2
- export const VERSION = '0.2.17';
2
+ export const VERSION = '0.2.18';
3
3
  //# sourceMappingURL=version.js.map
@@ -389,6 +389,14 @@ a.platform:hover { border-color:var(--acc); box-shadow:0 0 0 3px var(--mist); }
389
389
  .setup-body { margin:6px 0 0 34px; }
390
390
  .setup-body > .row.tight { margin-top:10px; }
391
391
  .setup-body label { margin-top:14px; }
392
+ .guide { margin:6px 0 0; padding-left:20px; display:flex; flex-direction:column; gap:10px; }
393
+ .guide li { padding-left:4px; }
394
+ .guide li::marker { font-weight:700; color:var(--deep); }
395
+ .tg-step2 .seg { margin:8px 0 4px; }
396
+ .tg-step2 .wait { margin-top:16px; }
397
+ .tg-step2 .chat-list { margin-top:12px; }
398
+ .chosen-line { margin:12px 0 0; font-weight:600; }
399
+ .bot-line p { margin:8px 0 0; }
392
400
  .chat-finder:empty { display:none; }
393
401
  .chat-finder { margin-top:12px; }
394
402
  .chat-finder p { margin:0 0 8px; }
@@ -1726,59 +1726,22 @@
1726
1726
  var save = el('button', { class: 'btn primary', type: 'submit', text: 'Save ' + title });
1727
1727
  var test = el('button', { class: 'btn', type: 'button', text: 'Send test notification' });
1728
1728
  var remove = el('button', { class: 'btn ghost', type: 'button', text: 'Disconnect' });
1729
- // Telegram only: find the chat for them, from the chats that have messaged the bot.
1730
- var find = el('button', { class: 'btn primary', type: 'button', text: 'Find my chats' });
1731
- var found = el('div', { class: 'chat-finder', 'aria-live': 'polite' });
1732
- var botLinks = el('div', { class: 'row tight', hidden: true });
1733
- find.onclick = function () {
1734
- found.textContent = '';
1735
- var undo = busyButton(find, 'Looking…');
1736
- api('POST', '/notifications/telegram/lookup', { token: token.value.trim() }).then(function (b) {
1737
- var bot = b.bot.username;
1738
- botLinks.textContent = '';
1739
- if (bot) {
1740
- botLinks.appendChild(el('a', { class: 'btn', href: 'https://t.me/' + encodeURIComponent(bot), target: '_blank', rel: 'noopener noreferrer', text: 'Open @' + bot + ' ↗' }));
1741
- botLinks.appendChild(el('a', { class: 'btn ghost', href: 'https://t.me/' + encodeURIComponent(bot) + '?startgroup=heresay', target: '_blank', rel: 'noopener noreferrer', text: 'Add it to a group ↗' }));
1742
- botLinks.hidden = false;
1743
- }
1744
- found.appendChild(el('p', { class: 'ok-msg' }, [el('b', { text: '✓ ' + (b.bot.name || 'Your bot') + (bot ? ' (@' + bot + ')' : '') }), document.createTextNode(' is ready.')]));
1745
- if (!b.chats.length) {
1746
- found.appendChild(el('p', { class: 'hint', text: 'No chats yet. Open the bot and press Start, or add it to a group and send a message, then press Find my chats again. Telegram only shows the last day.' }));
1747
- return;
1748
- }
1749
- var KIND = { private: 'You', group: 'Group', supergroup: 'Group', channel: 'Channel' };
1750
- var list = el('div', { class: 'chat-list', role: 'radiogroup', 'aria-label': 'Send alerts to' });
1751
- b.chats.forEach(function (c) {
1752
- var radio = el('input', { type: 'radio', name: 'telegram_chat', value: c.id, checked: address.value === c.id });
1753
- radio.onchange = function () {
1754
- address.value = c.id;
1755
- enabled.checked = true;
1756
- form.dispatchEvent(new Event('input'));
1757
- feedback('Chat chosen. Save to start sending alerts there.');
1758
- };
1759
- list.appendChild(el('label', { class: 'chat-choice' }, [radio, el('span', {}, [el('b', { text: c.title }), el('span', { class: 'mute', text: KIND[c.kind] + ' · ' + c.id })])]));
1760
- });
1761
- found.appendChild(list);
1762
- if (b.chats.length === 1 && !address.value) list.querySelector('input').click();
1763
- }).catch(function (x) { found.appendChild(el('p', { class: 'err', role: 'alert', text: x.message })); }).finally(undo);
1764
- };
1729
+ var tg = telegram ? telegramGuide() : null;
1765
1730
  var form = el('form', { class: 'form notification-form' }, telegram ? [
1766
1731
  el('label', { class: 'notification-choice' }, [enabled, el('b', { text: 'Enable ' + title + ' notifications' })]),
1767
1732
  setupStep(1, 'Make a bot', [
1768
- el('p', { class: 'hint' }, ['In Telegram, open BotFather and send ', el('code', { text: '/newbot' }),
1769
- '. Give it any name, then a username that ends in “bot”. BotFather replies with a token: copy it and paste it here.']),
1770
- el('div', { class: 'row tight' }, [el('a', { class: 'btn', href: 'https://t.me/BotFather', target: '_blank', rel: 'noopener noreferrer', text: 'Open BotFather ↗' })]),
1771
- el('label', {}, ['Bot token', token]), tokenHint,
1733
+ el('ol', { class: 'guide' }, [
1734
+ el('li', {}, [el('a', { class: 'btn', href: 'https://t.me/BotFather', target: '_blank', rel: 'noopener noreferrer', text: 'Open BotFather in Telegram ↗' })]),
1735
+ el('li', {}, ['Send ', el('code', { text: '/newbot' }), '. It asks for a name (anything, like “Acme alerts”), then a username that ends in “bot” (like acme_alerts_bot).']),
1736
+ el('li', {}, ['It replies with a long token that looks like ', el('code', { text: '123456789:AAH…' }), '. Copy it and paste it here.']),
1737
+ ]),
1738
+ el('label', {}, ['Bot token', token]), tokenHint, tg.botLine,
1772
1739
  ]),
1773
- setupStep(2, 'Choose where alerts go', [
1774
- el('p', { class: 'hint', text: 'Say hello to your bot so it knows the chat: press Start in a chat with it, or add it to a group and send any message there. For a channel, add it as an administrator and post once.' }),
1775
- botLinks,
1776
- el('div', { class: 'row tight' }, [find]),
1777
- found,
1778
- el('label', {}, ['Chat ID or channel username', address]),
1779
- el('p', { class: 'hint', text: 'Filled in when you pick a chat above. You can also type one, like -1001234567890 or @yourchannel.' }),
1740
+ setupStep(2, 'Choose where alerts go', [tg.step2]),
1741
+ setupStep(3, 'Save and test', [
1742
+ el('p', { class: 'hint', text: 'Save, then send a test. It arrives from your bot in a few seconds.' }),
1743
+ el('div', { class: 'row tight' }, [save, test, remove]), message,
1780
1744
  ]),
1781
- setupStep(3, 'Save and test', [el('div', { class: 'row tight' }, [save, test, remove]), message]),
1782
1745
  ] : [
1783
1746
  el('label', { class: 'notification-choice' }, [enabled, el('b', { text: 'Enable ' + title + ' notifications' })]),
1784
1747
  el('label', {}, ['Webhook token', token]), tokenHint,
@@ -1786,6 +1749,126 @@
1786
1749
  el('p', { class: 'hint' }, ['In Cliq, open Bots & Tools → Webhook Tokens and generate a token. Use the bot or channel message endpoint from Get Webhook URL, without the ?zapikey part. Use your region’s Cliq domain. ', el('a', { href: 'https://www.zoho.com/cliq/help/platform/webhook-tokens.html', target: '_blank', rel: 'noopener noreferrer', text: 'Cliq setup guide' })]),
1787
1750
  el('div', { class: 'row' }, [save, test, remove]), message,
1788
1751
  ]);
1752
+ /**
1753
+ * Telegram has no screen that shows a chat ID, so we never ask for one up front. Once the
1754
+ * token checks out, the person picks who gets alerts, follows two or three taps, and this
1755
+ * page watches the bot until their chat turns up, then chooses it.
1756
+ */
1757
+ function telegramGuide() {
1758
+ var g = { botLine: el('div', { class: 'bot-line', 'aria-live': 'polite' }), step2: el('div', { class: 'tg-step2' }) };
1759
+ var bot = null, kind = 'private', chats = [], timer = null, until = 0, checking = null;
1760
+ var KIND = { private: 'Private chat', group: 'Group', supergroup: 'Group', channel: 'Channel' };
1761
+ var wait = el('div', { class: 'wait', role: 'status' });
1762
+ var list = el('div', { class: 'chat-list', role: 'radiogroup', 'aria-label': 'Send alerts to' });
1763
+ var chosen = el('p', { class: 'ok-msg chosen-line' });
1764
+ var manual = el('details', { class: 'where', open: !!saved.chat_id }, [
1765
+ el('summary', { text: 'Enter a chat ID yourself' }),
1766
+ el('label', {}, ['Chat ID or channel username', address]),
1767
+ el('p', { class: 'hint', text: 'Only if you already know it, like -1001234567890 or @yourchannel. Picking a chat above fills this in.' }),
1768
+ ]);
1769
+ var tabs = el('div', { class: 'seg', role: 'tablist', 'aria-label': 'Who gets alerts' });
1770
+ var how = el('ol', { class: 'guide' });
1771
+ var again = el('button', { class: 'btn', type: 'button', text: 'Look again', onclick: function () { watch(); } });
1772
+
1773
+ function link(href, text) { return el('a', { class: 'btn', href: href, target: '_blank', rel: 'noopener noreferrer', text: text }); }
1774
+ function drawHow() {
1775
+ var at = '@' + bot.username, url = 'https://t.me/' + encodeURIComponent(bot.username);
1776
+ how.textContent = '';
1777
+ (kind === 'private' ? [
1778
+ [link(url, 'Open ' + at + ' in Telegram ↗')],
1779
+ ['Tap ', el('b', { text: 'Start' }), ' at the bottom of the chat. No Start button? Send it any message, like “hi”.'],
1780
+ ['Come back to this page. It finds the chat by itself.'],
1781
+ ] : kind === 'group' ? [
1782
+ [link(url + '?startgroup=heresay', 'Add ' + at + ' to a group ↗')],
1783
+ ['Telegram asks which group. Pick it and confirm.'],
1784
+ ['Come back to this page. It finds the group by itself. If it doesn’t, send ', el('code', { text: '/start' + at }), ' in the group.'],
1785
+ ] : [
1786
+ ['In Telegram, open your channel and tap its name, then ', el('b', { text: 'Administrators' }), ' → ', el('b', { text: 'Add Admin' }), '.'],
1787
+ ['Search for ', el('b', { text: at }), ', add it, and leave ', el('b', { text: 'Post Messages' }), ' on.'],
1788
+ ['Post anything in the channel, then come back to this page. It finds the channel by itself.'],
1789
+ ]).forEach(function (kids) { how.appendChild(el('li', {}, kids)); });
1790
+ }
1791
+ function drawTabs() {
1792
+ tabs.textContent = '';
1793
+ [['private', 'Just me'], ['group', 'A group'], ['channel', 'A channel']].forEach(function (t) {
1794
+ tabs.appendChild(el('button', { type: 'button', role: 'tab', 'aria-selected': String(kind === t[0]), text: t[1], onclick: function () {
1795
+ kind = t[0]; drawTabs(); drawHow(); drawChats(); watch();
1796
+ } }));
1797
+ });
1798
+ }
1799
+ function sameKind(c) { return kind === 'group' ? c.kind === 'group' || c.kind === 'supergroup' : c.kind === kind; }
1800
+ function pick(c) {
1801
+ address.value = c.id;
1802
+ enabled.checked = true;
1803
+ form.dispatchEvent(new Event('input'));
1804
+ stop();
1805
+ drawChats();
1806
+ feedback('Chat chosen. Save to start sending alerts there.');
1807
+ }
1808
+ function drawChats() {
1809
+ list.textContent = '';
1810
+ var hit = chats.filter(function (c) { return c.id === address.value; })[0];
1811
+ chosen.hidden = !address.value;
1812
+ chosen.textContent = hit ? '✓ Alerts will go to ' + hit.title + ' (' + KIND[hit.kind].toLowerCase() + ').'
1813
+ : address.value ? '✓ Alerts go to chat ' + address.value + '. Pick another below to change it.' : '';
1814
+ chats.forEach(function (c) {
1815
+ var radio = el('input', { type: 'radio', name: 'telegram_chat', value: c.id, checked: address.value === c.id });
1816
+ radio.onchange = function () { pick(c); };
1817
+ list.appendChild(el('label', { class: 'chat-choice' }, [radio, el('span', {}, [el('b', { text: c.title }), el('span', { class: 'mute', text: KIND[c.kind] })])]));
1818
+ });
1819
+ list.hidden = !chats.length;
1820
+ }
1821
+ function drawWait(state) {
1822
+ wait.textContent = '';
1823
+ wait.className = 'wait' + (state === 'idle' ? ' ok idle' : '');
1824
+ if (state === 'waiting') wait.appendChild(document.createTextNode('Waiting for ' + (kind === 'private' ? 'your message to' : kind === 'group' ? 'a group with' : 'a channel with') + ' @' + bot.username + '…'));
1825
+ else if (state === 'idle') { wait.appendChild(document.createTextNode('Nothing yet. Follow the steps above, then')); wait.appendChild(again); }
1826
+ wait.hidden = state === 'none';
1827
+ }
1828
+ function stop() { clearTimeout(timer); timer = null; if (bot) drawWait(address.value ? 'none' : 'idle'); }
1829
+ function watch() {
1830
+ clearTimeout(timer);
1831
+ until = Date.now() + 5 * 60 * 1000;
1832
+ drawWait('waiting');
1833
+ poll();
1834
+ }
1835
+ function poll() {
1836
+ if (!form.isConnected) return;
1837
+ lookup(true).then(function () {
1838
+ var match = chats.filter(sameKind)[0];
1839
+ if (match && !address.value) return pick(match); // never replace a chat they already chose
1840
+ if (match) return stop();
1841
+ if (Date.now() > until) return stop();
1842
+ timer = setTimeout(poll, 6000);
1843
+ }).catch(stop);
1844
+ }
1845
+ function lookup(quiet) {
1846
+ return api('POST', '/notifications/telegram/lookup', { token: token.value.trim() }).then(function (b) {
1847
+ var fresh = !bot || bot.username !== b.bot.username;
1848
+ bot = b.bot; chats = b.chats;
1849
+ g.botLine.textContent = '';
1850
+ g.botLine.appendChild(el('p', { class: 'ok-msg' }, [el('b', { text: '✓ Token works. ' }), document.createTextNode('Your bot is ' + (bot.name || 'ready') + ' (@' + bot.username + ').')]));
1851
+ if (fresh) { g.step2.textContent = ''; drawTabs(); drawHow(); [el('p', { class: 'hint', text: 'Who should get the alerts?' }), tabs, how, wait, list, chosen, manual].forEach(function (n) { g.step2.appendChild(n); }); }
1852
+ drawChats();
1853
+ }).catch(function (x) {
1854
+ if (quiet && bot) return;
1855
+ g.botLine.textContent = '';
1856
+ g.botLine.appendChild(el('p', { class: 'err', role: 'alert', text: x.message }));
1857
+ throw x;
1858
+ });
1859
+ }
1860
+ function check() {
1861
+ clearTimeout(checking);
1862
+ checking = setTimeout(function () {
1863
+ lookup().then(function () { if (!address.value) watch(); else stop(); }).catch(function () {});
1864
+ }, 400);
1865
+ }
1866
+ g.step2.appendChild(el('p', { class: 'hint', text: 'Paste your bot token above first. Then this step shows exactly what to tap.' }));
1867
+ g.step2.appendChild(manual);
1868
+ token.addEventListener('input', function () { if (/^\d+:[A-Za-z0-9_-]{20,}$/.test(token.value.trim())) check(); });
1869
+ if (saved.configured) check();
1870
+ return g;
1871
+ }
1789
1872
  function refresh() {
1790
1873
  token.placeholder = saved.configured ? 'Leave blank to keep the saved token' : 'Paste your token';
1791
1874
  tokenHint.textContent = saved.configured ? 'A token is saved. Paste a new one to replace it.' : 'Your token is saved on the server and is never displayed here.';