pi-durable-bot 0.6.0 → 0.7.0

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +33 -3
  2. package/dist/agent/resources.js +12 -1
  3. package/dist/agent/resources.js.map +1 -1
  4. package/dist/bot/bot.js +54 -5
  5. package/dist/bot/bot.js.map +1 -1
  6. package/dist/bot/prompt.js +13 -3
  7. package/dist/bot/prompt.js.map +1 -1
  8. package/dist/channels/discord/index.js +202 -20
  9. package/dist/channels/discord/index.js.map +1 -1
  10. package/dist/channels/slack/index.js +314 -16
  11. package/dist/channels/slack/index.js.map +1 -1
  12. package/dist/channels/telegram/index.js +21 -2
  13. package/dist/channels/telegram/index.js.map +1 -1
  14. package/dist/cli/agent.js +20 -1
  15. package/dist/cli/agent.js.map +1 -1
  16. package/dist/cli/commands.js +28 -4
  17. package/dist/cli/commands.js.map +1 -1
  18. package/dist/cli/mcp.js +27 -1
  19. package/dist/cli/mcp.js.map +1 -1
  20. package/dist/cli/pages.js +44 -0
  21. package/dist/cli/pages.js.map +1 -0
  22. package/dist/cli/service.js +107 -49
  23. package/dist/cli/service.js.map +1 -1
  24. package/dist/core/channel.js +4 -1
  25. package/dist/core/channel.js.map +1 -1
  26. package/dist/core/env-file.js +23 -6
  27. package/dist/core/env-file.js.map +1 -1
  28. package/dist/core/forms.js +16 -0
  29. package/dist/core/forms.js.map +1 -0
  30. package/dist/core/home.js +10 -2
  31. package/dist/core/home.js.map +1 -1
  32. package/dist/gateway/errors.js +3 -0
  33. package/dist/gateway/errors.js.map +1 -1
  34. package/dist/gateway/forms.js +99 -0
  35. package/dist/gateway/forms.js.map +1 -0
  36. package/dist/gateway/gateway.js +23 -1
  37. package/dist/gateway/gateway.js.map +1 -1
  38. package/dist/gateway/log.js +7 -5
  39. package/dist/gateway/log.js.map +1 -1
  40. package/dist/gateway/waker.js +23 -8
  41. package/dist/gateway/waker.js.map +1 -1
  42. package/dist/main.js +23 -4
  43. package/dist/main.js.map +1 -1
  44. package/dist/pages/cloudflared.js +149 -0
  45. package/dist/pages/cloudflared.js.map +1 -0
  46. package/dist/pages/files.js +244 -0
  47. package/dist/pages/files.js.map +1 -0
  48. package/dist/pages/host.js +268 -0
  49. package/dist/pages/host.js.map +1 -0
  50. package/dist/pages/secret-page.js +71 -0
  51. package/dist/pages/secret-page.js.map +1 -0
  52. package/dist/pages/server.js +305 -0
  53. package/dist/pages/server.js.map +1 -0
  54. package/dist/pages/settings.js +71 -0
  55. package/dist/pages/settings.js.map +1 -0
  56. package/dist/pages/store.js +492 -0
  57. package/dist/pages/store.js.map +1 -0
  58. package/dist/pages/tunnel.js +271 -0
  59. package/dist/pages/tunnel.js.map +1 -0
  60. package/docs/for-agents.md +10 -8
  61. package/kit/pots.css +473 -0
  62. package/kit/pots.js +627 -0
  63. package/package.json +4 -3
  64. package/{docs/channels/discord.md → skills/discord-channel/SKILL.md} +55 -2
  65. package/skills/pages/SKILL.md +242 -0
  66. package/skills/slack-channel/SKILL.md +126 -0
  67. package/skills/telegram-channel/SKILL.md +89 -0
  68. package/docs/channels/slack.md +0 -70
  69. package/docs/channels/telegram.md +0 -50
  70. /package/{docs/channels → skills/slack-channel}/slack-app-manifest.yaml +0 -0
@@ -1,4 +1,11 @@
1
- # Connect Discord
1
+ ---
2
+ name: discord-channel
3
+ description: Discord for a Pots bot. How to connect a Discord bot yourself (the application, its token, inviting it to a server, bot.json), send and edit messages, threads, call Discord's REST API, files and limits, and how to post buttons, menus and forms (components and modals), get clicks and mark a question answered. Use when you connect Discord, or need more in Discord than plain text.
4
+ ---
5
+
6
+ # Discord
7
+
8
+ ## Connect
2
9
 
3
10
  Written for a bot that connects itself; a person can follow it too. The bot connects to Discord's gateway, so the computer needs no public address.
4
11
 
@@ -38,7 +45,7 @@ A second Discord bot is a second channel entry with its own `id` (for example `d
38
45
 
39
46
  ## call
40
47
 
41
- The `call` tool, with the channel's `id` (`discord`), calls any endpoint of Discord's REST API (https://discord.com/developers/docs) with the bot token. The method is the HTTP method and the path. The params are the query for GET and DELETE, and the JSON body for the others. For example:
48
+ The `call` tool, with the channel's `id` (`discord`), calls any endpoint of Discord's REST API (https://docs.discord.com/developers) with the bot token. The method is the HTTP method and the path. The params are the query for GET and DELETE, and the JSON body for the others. For example:
42
49
 
43
50
  | method | params | does |
44
51
  |---|---|---|
@@ -51,6 +58,52 @@ The IDs are in the addresses (`discord:#<channel ID>/<message ID>`) and in the r
51
58
 
52
59
  When someone uses a command or a button of yours, you get an `interaction` event, and Discord is told that the answer comes later. Answer a command within 15 minutes, with the `application_id` and `token` from the event's raw data: method `PATCH /webhooks/<application_id>/<token>/messages/@original`, params `{"content": "…"}`.
53
60
 
61
+ ## Buttons, forms, tables and clicks
62
+
63
+ `send` posts text. For buttons and menus, post the message yourself with `call`: method `POST /channels/<channel ID>/messages` ([reference](https://docs.discord.com/developers/resources/message)) with `components` ([reference](https://docs.discord.com/developers/components/reference)). To reply to a message, add `"message_reference": {"message_id": "<message ID>"}`.
64
+
65
+ ```json
66
+ {
67
+ "content": "Where should I deploy release 4.2?",
68
+ "components": [
69
+ { "type": 1, "components": [
70
+ { "type": 2, "style": 1, "label": "Test", "custom_id": "deploy:test" },
71
+ { "type": 2, "style": 4, "label": "Production", "custom_id": "deploy:prod" }
72
+ ] }
73
+ ]
74
+ }
75
+ ```
76
+
77
+ - A message has at most 5 action rows (type 1). A row holds up to 5 buttons (type 2) or one select menu. Button styles: 1 primary, 2 secondary, 3 success, 4 danger, 5 link (a `url` and no `custom_id`; a click on it does not reach you).
78
+ - `custom_id` is 1 to 100 characters and unique in the message. You choose it, and it comes back with the click, so make it say what the click means.
79
+ - A button's `label` is at most 80 characters. A string select menu (type 3, alone in its row) has at most 25 `options`, each with a `label` and a `value` of at most 100 characters; `min_values` and `max_values` (up to 25) let people choose several.
80
+ - Discord's newer layout, with the message flag `IS_COMPONENTS_V2` (32768), adds text, sections, containers, images and separators, up to 40 components in a message, but such a message cannot have `content` or `embeds` ([guide](https://docs.discord.com/developers/components/using-message-components)).
81
+ - **Tables**: Discord's Markdown has no tables. Send a small table as a code block with aligned columns, and a large one as a page (the pages skill).
82
+ - When Discord refuses the components, the `call` error gives Discord's answer. Fix what it names and call again.
83
+
84
+ **When someone clicks.** Pots answers the click at once, within the 3 seconds Discord allows: it tells Discord that the message may change later, so the person sees no error. The click wakes you straight away, not through the judge and without waiting for more messages, as an `interaction` event. The platform sends Pots only the clicks on your own buttons, also on a message the log does not have, such as an ephemeral one. The wake says which button or menu (its `custom_id`, and the values chosen in a menu) and who clicked (their person address). Discord's whole interaction is the event's raw data in the log.
85
+
86
+ **Mark the question answered.** Anyone who can see the message can click, and a click is not an answer until you decide it counts. Whose click counts, and what it means, is your call, as with messages. When it counts, change your message with `call` `PATCH /channels/<channel ID>/messages/<message ID>`: a new `content`, and `components` with the buttons `"disabled": true`, or `[]` to take them away. Until you change it, the buttons stay, and a click days later still wakes you.
87
+
88
+ **Forms.** Discord opens a form (a modal) only as the first answer to a click, within 3 seconds, which is too soon for you, so you store the form first and Pots opens it:
89
+
90
+ 1. `pots form add <name> <JSON>`, or `-` to read the JSON from stdin: the `data` of a Discord modal ([reference](https://docs.discord.com/developers/interactions/receiving-and-responding)), with `custom_id`, `title` (at most 45 characters) and `components`: 1 to 5 [Label](https://docs.discord.com/developers/components/reference) components (type 18, `label` at most 45 characters), each holding one text input (type 4; `style` 1 for one line, 2 for several; up to 4000 characters), select menu, radio group, checkbox group or checkbox. Each one's `custom_id` names its value in the answer (Discord sends no labels back). Pots sets the modal's own `custom_id` to the button's, to find your message again, so yours is replaced. A name has letters, digits, `-` and `_`, at most 64 characters, and no `:`. Adding a name in use replaces that form.
91
+ 2. Post a button whose `custom_id` is `form:<name>`, or `form:<name>:<extra>`. `<extra>` comes back with the answer, so one form serves many messages, for example `form:bug-report:4.2`.
92
+ 3. Someone clicks, and Pots opens the form at once. The click itself does not wake you. When they submit the form, you are woken at once with the form's name, `<extra>`, the submitted values and who submitted it. If the form could not open (no form of that name is stored, it is not a Discord modal's data, or Discord refused it), the click wakes you with the reason. `pots form add` stores any JSON object; the form is checked only when it opens.
93
+
94
+ `pots form list` shows your forms, and `pots form remove <name>` removes one.
95
+
96
+ ```sh
97
+ pots form add bug-report - <<'EOF'
98
+ {"custom_id": "bug-report", "title": "Report a bug", "components": [
99
+ {"type": 18, "label": "What happened?", "component": {"type": 4, "custom_id": "what", "style": 2, "max_length": 1000}}]}
100
+ EOF
101
+ ```
102
+
103
+ **Link previews.** Discord shows a preview (an embed) of the links in a message. `send` does not turn this off. When you send a page link, and always a password page link (the pages skill), post it with `call` and the message flag `SUPPRESS_EMBEDS`, which is 4:
104
+
105
+ `call discord POST /channels/123/messages {"content": "The plan: https://…/p/…/", "flags": 4}`
106
+
54
107
  ## Limits
55
108
 
56
109
  - A message can have at most 2000 characters. A longer text is refused, not cut: send it in parts.
@@ -0,0 +1,242 @@
1
+ ---
2
+ name: pages
3
+ description: Web pages you write and send to people as a link. A display page shows what is too big for a chat message (a plan, a report, tables, charts); an answer page collects many answers at once (choices, text, comments on sections, approve or reject) and sends them back to you; the Pots password page takes a secret such as a token. Also how page links reach the internet (Cloudflare Quick Tunnel, Tailscale Funnel), website projects, and cleanup. Use when a chat message is too small for what you must show or ask, or when a person has to give you a secret.
4
+ ---
5
+
6
+ # Pages
7
+
8
+ A page is a web page you write: full HTML, with your own layout and scripts. Pots serves it on this computer and gives you a link that people open in their phone's or computer's browser. What they answer on it comes back to you as a wake.
9
+
10
+ ## Choose how to ask
11
+
12
+ A guide, not a rule; you decide.
13
+
14
+ | What you need | Use | Why |
15
+ |---|---|---|
16
+ | A simple question | Plain text in the chat | Works the same on every platform |
17
+ | One question with a few options, and the platform has a fitting element | Native buttons or menus: the slack-channel, discord-channel and telegram-channel skills | One tap answers it; the click names the person's account |
18
+ | Show something large: a plan, a report, a table, a chart | A display page | Long content does not fit a chat window |
19
+ | Many inputs at once: choices, text, a comment on each step, approve or reject | An answer page | One page, one submit |
20
+ | A secret: a password, a token, a key | The Pots password page (`pots page secret`) | The value goes straight to a file in the secrets folder, never into the chat, the log or your conversation |
21
+
22
+ Never ask for a secret in a chat message, and never write your own page for one. If someone pastes a secret into a chat, tell them that the chat keeps it, and suggest they replace it. In the terminal channel (`pots chat`), ask-secret works as before.
23
+
24
+ ## Three kinds of pages
25
+
26
+ | Kind | Example | Who writes it |
27
+ |---|---|---|
28
+ | Display page | A report, a plan, tables, charts. Only to read | You, freely. The kit's style saves time |
29
+ | Answer page | Feedback, choices, text, a comment on a section, approve or reject | You, with the kit's components, or fully your own. Change the style and layout as you like: the components are a start, not a limit |
30
+ | Password page | A token for an app | Pots. You choose only the text on it, the keys and the file |
31
+
32
+ ## Where pages live
33
+
34
+ Each page is a folder in your bot folder: `pages/<name>/`, with `index.html` and any other files it uses (images, scripts, data). Its name is the folder's name, such as `deploy-plan`. A page in `pages/keep/<name>/` is a kept page, named `keep/<name>`: cleanup never deletes it (see Cleanup).
35
+
36
+ Change the files at any time, in place. The link stays the same: people reload and see the new version. Do not replace the folder with a new one of the same name (for example by deleting and writing it again, or by moving another folder there): Pots then sees a different page, and every link of the old one stops working for good. To take a page off the internet, delete its folder, or unlink its links.
37
+
38
+ ## Links
39
+
40
+ ```sh
41
+ pots page link deploy-plan # one link that anyone who has it can use
42
+ pots page link deploy-plan --for slack:@U123 # a link made for one person
43
+ pots page unlink <link ID or URL> # the link stops working at once
44
+ pots page list # your pages, their links, when each was last opened and changed
45
+ ```
46
+
47
+ `pots page link` prints JSON: `{"link": "<link ID>", "url": "https://…/p/<token>/", "via": "public-url" or "quick-tunnel", "note": "…"}`. `note` comes with a Quick Tunnel and gives its facts (see below). Nobody can guess a link, but anyone who has it can open it, and a link can be forwarded.
48
+
49
+ - Make a link per person with `--for <person address>` when you want to know whose link an answer came through. Then say "someone used the link made for Alice", never "Alice answered": you know the link, not the person. To know for sure who answered, use a platform button: the platform names the account that clicked.
50
+ - Turn link previews off when you post a link (the channel skills say how). A platform's preview opens the link from its own servers.
51
+ - With a Quick Tunnel, the address changes each time the gateway starts, so links sent before stop working; `pots page link` again gives a new link to the same page.
52
+
53
+ ## Write a page quickly with the kit
54
+
55
+ Pots serves a kit for pages: `pots.css`, a clean look for phones and computers, light and dark, and `pots.js`, which sends a form's answers to Pots. Link them relative to the page's link, not its folder on disk: from a page's `index.html`, also in `keep/`, use `../../__pots/kit/`, and add one `../` for each subfolder of the page. A complete answer page:
56
+
57
+ ```html
58
+ <!doctype html>
59
+ <html lang="en">
60
+ <head>
61
+ <meta charset="utf-8">
62
+ <meta name="viewport" content="width=device-width, initial-scale=1">
63
+ <title>Deploy plan 4.2</title>
64
+ <link rel="stylesheet" href="../../__pots/kit/pots.css">
65
+ <script src="../../__pots/kit/pots.js" defer></script>
66
+ </head>
67
+ <body>
68
+ <main>
69
+ <h1>Deploy plan 4.2</h1>
70
+ <p class="pots-muted">Please answer by Friday.</p>
71
+ <form data-pots data-pots-done="Thanks, I have your answers.">
72
+ <fieldset data-pots-question="target">
73
+ <legend>Where should I deploy first?</legend>
74
+ <label><input type="radio" name="target" value="test" required> Test</label>
75
+ <label><input type="radio" name="target" value="prod"> Production</label>
76
+ </fieldset>
77
+
78
+ <fieldset data-pots-question="notify">
79
+ <legend>Who should I tell?</legend>
80
+ <label><input type="checkbox" value="support"> Support</label>
81
+ <label><input type="checkbox" value="sales"> Sales</label>
82
+ </fieldset>
83
+
84
+ <section data-pots-question="step-3">
85
+ <h2>3. Migrate the data</h2>
86
+ <p>Runs on the live database, with about 10 minutes of read-only mode.</p>
87
+ <div class="pots-approve">
88
+ <label><input type="radio" name="step-3" value="approve" required> Approve</label>
89
+ <label><input type="radio" name="step-3" value="reject"> Needs changes</label>
90
+ </div>
91
+ <details class="pots-comment"><summary>Comment</summary>
92
+ <textarea name="step-3-comment" data-pots-comment></textarea>
93
+ </details>
94
+ </section>
95
+
96
+ <label data-pots-question="window">When is a good time?
97
+ <input type="text" name="window" placeholder="Tuesday after 18:00">
98
+ </label>
99
+
100
+ <label data-pots-question="notes">Anything else?
101
+ <textarea name="notes"></textarea>
102
+ </label>
103
+
104
+ <button type="submit">Send answers</button>
105
+ </form>
106
+ </main>
107
+ </body>
108
+ </html>
109
+ ```
110
+
111
+ ### The components
112
+
113
+ All are normal form elements inside `<form data-pots>`; `pots.js` reads them when the form is submitted. Mark each question with `data-pots-question="<id>"` on the element around its fields: a `fieldset`, a `section`, a `label`, a `div`. IDs are yours; keep them short and unique on the page.
114
+
115
+ | Component | HTML | Its answer |
116
+ |---|---|---|
117
+ | Single choice | radio inputs with one `name` | `{"value": "test", "label": "Test"}`, or `null` when none is chosen |
118
+ | Multiple choice | checkbox inputs | `[{"value": "support", "label": "Support"}, …]`, maybe `[]` |
119
+ | Text, one line | `<input type="text">` (or `email`, `number`, `date` …) | the text |
120
+ | Text, several lines | `<textarea>` | the text |
121
+ | A comment on a section | a `<section>` with your content and a `<textarea data-pots-comment>`, best inside `<details class="pots-comment">` so it opens only when wanted | `"comment": "…"` next to the section's answer, only when written |
122
+ | Approve or reject | radio inputs with values `approve` and `reject` in `<div class="pots-approve">` | like a single choice; add a comment field for the reason |
123
+
124
+ - A `<select>` works too: like a single choice, and with `multiple` like a multiple choice. Fields of different kinds, or several text fields, in one question give an object with one value per field `name`. A field outside every question is a question of its own, named by its `name`.
125
+ - The question's text, which comes back with the answer, is `data-pots-text="…"` when you set it, else its first `data-pots-label` element, `legend` or heading, else the label's own text. A choice's label is the text of its `<label>`.
126
+ - `required` works as in any form: the browser asks for the field before it sends. Do not put a required field in a closed `<details>`.
127
+ - `data-pots-done="…"` on the form is the text shown after the answers are sent. `<p data-pots-status></p>` places the status line; without it, it goes after the submit button.
128
+ - After a successful send the form is disabled and says so; reloading the page gives an empty form, and sending again is a new answer.
129
+
130
+ How pots.js sends: it takes the page's version that Pots sent with the HTML file, in the response header `Server-Timing: pots-version;desc="<version>"`. When the browser does not give it, it reads the version from `__pots/info` of the link, once, on load; if that fails, it never sends the answers with a version read later, which could be a newer page's, but asks the person to reload the page, with their answers still on screen. On submit it posts `{"submission": "<ID>", "version": "<the version the person saw>", "answers": {…}}` to `__pots/submit`, with one submission ID for every try of the same submit. If the network fails, or Pots answers with a server error, it shows "trying again" and tries again, with longer waits up to 30 seconds, and at once when the phone is back online. Pots wakes you once per submission ID, also when only its reply got lost. A revoked link gets "This link no longer works". Answers are at most 64 KB.
131
+
132
+ ### Other classes and attributes
133
+
134
+ - Plain HTML already looks right: headings, lists, tables (they scroll sideways on a phone), code, quotes, images. Classes: `pots-card` (a box), `pots-note` (a highlighted note; with `pots-warn`, a warning), `pots-row` (boxes side by side that wrap on a phone), `pots-badge` (with `pots-good` or `pots-bad`), `pots-muted`, `pots-num` (a right-aligned table cell for numbers), `pots-secondary` (a quieter button).
135
+ - `<body data-pots-refresh="5">`: every 5 seconds the page asks Pots whether any of its files changed, and reloads when one did; when the person has started to fill a form, it shows "This page has changed" with a Reload button instead. Use it for progress pages. A Quick Tunnel cannot push to the browser (no Server-Sent Events), so pages poll.
136
+ - Text that other people wrote (comments, names, messages) must never become HTML: someone's `<script>` would run on the page. Write it into a JSON file next to the page and let the kit show it as text:
137
+ ```html
138
+ <div data-pots-source="comments.json">
139
+ <p>Updated <span data-pots-fill="updated"></span></p>
140
+ <ul data-pots-list="items"><li><b data-pots-fill="who"></b>: <span data-pots-fill="text"></span></li></ul>
141
+ </div>
142
+ ```
143
+ With `comments.json` = `{"updated": "10:02", "items": [{"who": "Alice", "text": "Looks good"}]}`, the first child of a `data-pots-list` repeats for each item. pots.js sets only `textContent`, never `innerHTML`. If you write such text into HTML yourself, escape `&`, `<`, `>` and `"`.
144
+ - `window.PotsKit.submit(answers)` sends answers your own script built, with the same version, submission ID and retries; it resolves `{ok: true}` or `{ok: false, status, message}`. `PotsKit.collect(form)` gives a kit form's answers without sending them. The kit's source is [../../kit/pots.js](../../kit/pots.js) and [../../kit/pots.css](../../kit/pots.css).
145
+
146
+ ### Fully custom pages
147
+
148
+ Write any HTML, CSS and JavaScript, with any libraries. To send answers without pots.js, post JSON to `__pots/submit` under the link's base (`/p/<token>/__pots/submit`): `{"submission": "<a random ID you make once and send again on every retry>", "version": "<the version of the page on screen: the pots-version Server-Timing entry of the page's load, in performance.getEntriesByType(\"navigation\")[0].serverTiming, or else GET __pots/info as soon as the page loads>", "answers": {…}}`, at most 64 KB. Pots answers `200 {"ok": true}`, also for a repeat of a submission ID, which does not wake you again; `400` for a bad body; `404` for a revoked or unknown link. Give each answer its question's text, as the kit does, so that you can judge an answer to an older version.
149
+
150
+ ## How answers come back
151
+
152
+ A submission wakes you at once, as a timed wake with this note:
153
+
154
+ ```
155
+ page answer: someone used link <link ID> (made for <person address | anyone>) on page <name> (version <version>): <answers as JSON>
156
+ ```
157
+
158
+ The answers of the example page look like this:
159
+
160
+ ```json
161
+ {"target": {"question": "Where should I deploy first?", "answer": {"value": "test", "label": "Test"}},
162
+ "notify": {"question": "Who should I tell?", "answer": [{"value": "support", "label": "Support"}]},
163
+ "step-3": {"question": "3. Migrate the data", "answer": {"value": "reject", "label": "Needs changes"}, "comment": "Try it on test first."},
164
+ "window": {"question": "When is a good time?", "answer": "Tuesday after 18:00"},
165
+ "notes": {"question": "Anything else?", "answer": ""}}
166
+ ```
167
+
168
+ - The version is the page as the person saw it. The version changes whenever any file of the page changes; `curl -s <link URL>__pots/info` gives the version now. When they differ, the person answered an older page: the question texts show what they saw, and you judge whether the answer still counts.
169
+ - An answer through a link made for Alice was sent by someone who had that link. Usually that is Alice; when it matters, ask her.
170
+ - Answers are in your log like other wakes. Tell the people what you did with them, in the chat where you sent the link.
171
+
172
+ ## The password page
173
+
174
+ ```sh
175
+ pots page secret --file slack.env --keys SLACK_APP_TOKEN,SLACK_BOT_TOKEN --text "Paste the two Slack tokens from step 5" --for slack:@U123
176
+ ```
177
+
178
+ It prints JSON: `{"link": "<link ID>", "url": "https://…/s/<token>", "expires": "<time>", "via": …, "note": …}`. The page is Pots' own; you choose only the text, the keys and the file. One person submits it once: the values go straight into that file in the secrets folder (`~/.pots/secrets/`), and the link stops working. A link that nobody submits stops working after 1 hour. Opening the page does not use it up, so a platform's link preview cannot either; still turn previews off.
179
+
180
+ You are woken with:
181
+
182
+ ```
183
+ secret page: someone used link <link ID> (made for <person address | anyone>) and wrote <KEY1>, <KEY2> to <file> in the secrets folder
184
+ ```
185
+
186
+ You never see the values; they are not in the log, the wake or a trace. Then use the file as after ask-secret, for example as `secrets` of a channel in bot.json. The file has the values exactly as they were typed, one `KEY=value` line each, so never `source` it or `.` it in a shell: a value can hold `$(…)`. To use one value in a command, read just that line, for example `"$(grep '^SLACK_BOT_TOKEN=' ~/.pots/secrets/slack.env | cut -d= -f2-)"`, and never print it. Send the link in a DM to that person when you can. With a Quick Tunnel, tell them every time that Cloudflare can see what they type into the page (see below), and offer Tailscale Funnel.
187
+
188
+ ## Where links point: a Quick Tunnel or your own address
189
+
190
+ Pots serves pages on this computer only (127.0.0.1, at `pagePort` in `~/.pots/settings.json`). The internet reaches them in one of two ways:
191
+
192
+ - `publicUrl` in `~/.pots/settings.json` is set (a Tailscale Funnel address, a domain, a reverse proxy): links use it, and no Quick Tunnel starts. `via` is `public-url`.
193
+ - `publicUrl` is not set: Pots starts a Cloudflare [Quick Tunnel](https://developers.cloudflare.com/tunnel/get-started/quick-tunnels/) at the first `pots page link` or `pots page secret`, and keeps it until the gateway stops. `via` is `quick-tunnel`. All bots of this computer share it.
194
+
195
+ What a Quick Tunnel means, from Cloudflare's docs and how it works:
196
+
197
+ - No account and no setup.
198
+ - The address (`https://<random words>.trycloudflare.com`) changes every time the gateway starts, so links sent before stop working.
199
+ - Cloudflare ends the HTTPS connection on its servers, so Cloudflare can see the pages and what people type into them.
200
+ - Cloudflare says Quick Tunnels are for testing and development, with no uptime guarantee; at most 200 requests at a time, and no Server-Sent Events.
201
+
202
+ **When to tell the person.** The first time you send a page link over a Quick Tunnel, tell the people you work with these facts in a sentence or two, and save in your memory that you did. For example: "This link goes through Cloudflare's free Quick Tunnel, which needs no account. Three things to know: the link changes when Pots restarts, Cloudflare can see the page, and Cloudflare says the service is for testing. For a fixed address that Cloudflare cannot read, I can set up Tailscale Funnel; you would sign in once." And every time you send a password page over a Quick Tunnel, say that Cloudflare can see what is typed into it.
203
+
204
+ ## Set up Tailscale Funnel with the person
205
+
206
+ [Tailscale Funnel](https://tailscale.com/docs/features/tailscale-funnel) gives this computer a fixed address, `https://<machine>.<tailnet>.ts.net`. Its relays do not decrypt the traffic: HTTPS ends on this computer. People who open a link need nothing installed. You do the work; the person signs in once.
207
+
208
+ 1. Ask the person first. Look at `~/.pots/settings.json`: if `publicUrl` is already set, links use it; change it only with the steps below.
209
+ 2. Install Tailscale if `tailscale version` fails: https://tailscale.com/download (on Linux: `curl -fsSL https://tailscale.com/install.sh | sh`). It needs administrator rights; when `sudo -n true` fails, give the person the command to run. On Linux, `tailscale` commands that change settings need `sudo`.
210
+ 3. If `tailscale status` says this computer is not signed in, run `tailscale up`. It prints a link: send it to the person, who opens it and signs in (Google, GitHub, Apple, Microsoft and others).
211
+ 4. See what is mapped already: `tailscale funnel status` and `tailscale serve status`. Tailscale is one per computer, shared by every user and every Pots on it, and Funnel listens only on ports 443, 8443 and 10000. On a computer that others use, take a port that is free, or a path under a port (`--set-path /<path>`), and never change, replace or `reset` a mapping you did not make.
212
+ 5. Map the page port (`pagePort` in `~/.pots/settings.json`): `tailscale funnel --bg <pagePort>` for port 443, or `tailscale funnel --bg --https=8443 <pagePort>`, or add `--set-path /<path>`. `--bg` keeps it after restarts. The first time, Tailscale prints a link to a page where the person approves Funnel for their tailnet: send it to them.
213
+ 6. The address can take up to 10 minutes to work the first time (DNS). Check it: `curl -sS https://<machine>.<tailnet>.ts.net[:<port>][/<path>]/__pots/kit/pots.css` must print the stylesheet. If it does not after 10 minutes, the mapping is wrong; do not use it.
214
+ 7. Ask the person before you set or change `publicUrl`: every link that any bot of this computer sent before stops working, because it points at the old address. Then write `"publicUrl": "https://<machine>.<tailnet>.ts.net[:<port>][/<path>]"` into `~/.pots/settings.json`, keeping `pagePort`. The next `pots page link` should say `"via": "public-url"`. Note the change and the date in the memory all bots share (`~/.pots/memory/`), so the other bots know why their old links stopped.
215
+ 8. Tell the person about [key expiry](https://tailscale.com/docs/features/access-control/key-expiry): Tailscale signs a computer out after 180 days by default, and then the links stop working until someone signs in again. They can turn it off for this computer in the Tailscale admin console (Machines, the menu of this machine, Disable key expiry). Key expiry is a security feature: with it off, a lost or stolen computer stays in their tailnet until they remove it. Let them choose.
216
+
217
+ Also tell them: the address shows the machine's name and the tailnet's name to everyone who gets a link; Funnel is in beta and has bandwidth limits.
218
+
219
+ ## Content-Security-Policy
220
+
221
+ Pots puts no browser restrictions on your pages, so they can use any outside script, font, image or service. For a page with private content that needs nothing from outside, add this to its `<head>`; then the page cannot load from or send to other hosts, also if text someone wrote slips into it as HTML. Keep scripts in files: it blocks inline `<script>`.
222
+
223
+ ```html
224
+ <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; base-uri 'none'; form-action 'self'">
225
+ ```
226
+
227
+ ## One browser origin
228
+
229
+ All pages of this computer, of every bot, are under one address, so the browser treats them as one site. A script on one page can read what another page keeps in the browser. So never keep private data in `localStorage`, `sessionStorage`, IndexedDB or cookies; the kit keeps nothing there.
230
+
231
+ ## Website projects
232
+
233
+ - A static site (pages, images, scripts, no server of its own) is a page.
234
+ - A site with a backend (a database, sign-in, its own API) is not a page: run its server on this computer like any project, and give it its own tunnel (`cloudflared tunnel --url http://localhost:<port>`; after Pots started a Quick Tunnel, `cloudflared` is on this computer, maybe in `~/.pots/bin/`) or a Funnel port or path of its own. Pots does not route to it.
235
+ - A site that should stay up needs a fixed address (Funnel or a domain) and belongs in `pages/keep/`.
236
+
237
+ ## Cleanup
238
+
239
+ - Pots deletes a page, with its links, when nobody opened it, you made no link to it and you did not change it for 30 days. Pages in `pages/keep/` are never deleted that way.
240
+ - A password page link expires 1 hour after you made it, unless it was used before.
241
+ - Deleting a bot deletes its pages and links.
242
+ - `pages/keep/` grows until you tidy it. Look through it now and then and ask the people whether old pages can go; a routine helps, for example `pots routine add tidy-pages --cron "0 10 1 * *" --note "Look through pages/keep/"`.
@@ -0,0 +1,126 @@
1
+ ---
2
+ name: slack-channel
3
+ description: Slack for a Pots bot. How to connect a Slack workspace yourself (the Slack app, its tokens, bot.json), send and edit messages, call Slack's Web API, files and limits, and how to post buttons, menus, tables and forms with Block Kit, get clicks and mark a question answered. Use when you connect Slack, or need more in Slack than plain text.
4
+ ---
5
+
6
+ # Slack
7
+
8
+ ## Connect
9
+
10
+ Written for a bot that connects itself; a person can follow it too. The app uses socket mode, so the computer needs no public address.
11
+
12
+ 1. Open https://api.slack.com/apps?new_app=1 in the browser on your screen. If Slack asks to sign in, ask the person to sign in there; they can take over the screen.
13
+ If this computer has no screen, ask the person how they want to do it (your instructions, under the screen, say what each way costs): a virtual desktop they can watch over VNC, a browser-only tool such as agent-browser, or steps 1 to 4 in the browser on their own computer while you guide them. In the last case, give them the manifest with your name already in it, and ask for the two tokens with ask-secret in the terminal channel (step 5).
14
+ 2. Choose **From a manifest**, pick the workspace, and paste [slack-app-manifest.yaml](slack-app-manifest.yaml). Change `name` and `display_name` to your own name first. Create the app.
15
+ 3. **Basic Information → App-Level Tokens → Generate Token and Scopes**: add the scope `connections:write` and generate. This is the app token (`xapp-…`).
16
+ 4. **Install App → Install to workspace → Allow**. Some workspaces need an admin to approve; then ask the person. Copy the **Bot User OAuth Token** (`xoxb-…`).
17
+ 5. Write both tokens to `slack.env` in the secrets folder (`~/.pots/secrets/`), readable only by this user:
18
+ ```sh
19
+ SLACK_APP_TOKEN=xapp-...
20
+ SLACK_BOT_TOKEN=xoxb-...
21
+ ```
22
+ Do not put tokens in a chat message, a log or any other file. When the person copied the tokens, ask for them in the terminal channel instead:
23
+ `call <terminal channel id> ask-secret {"text": "…", "file": "slack.env", "keys": ["SLACK_APP_TOKEN", "SLACK_BOT_TOKEN"]}`. `pots chat` writes them to this file without showing them to you.
24
+ 6. Add the channel to `channels` in your `bot.json`:
25
+ ```json
26
+ { "id": "slack", "type": "slack", "secrets": "~/.pots/secrets/slack.env" }
27
+ ```
28
+ It connects within a few seconds. `pots status` lists it; if it fails, the reason is in `bot.json.error`.
29
+ 7. You join only the places you are invited to. Ask the person to invite you to the right channels (`/invite @yourname`) or to send you a DM in Slack.
30
+
31
+ A second Slack workspace is a second channel entry with its own `id` (for example `slack-acme`) and its own env file.
32
+
33
+ ## Sending
34
+
35
+ - Your text is Markdown; Slack shows it formatted.
36
+ - Send to a place to post in it, and to a person to post in a DM with them.
37
+ - Send to a message to reply to it. On Slack a reply is always in a thread: the reply goes in the message's thread, or starts a thread under the message when it has none.
38
+ - Send to a thread (the address of its first message) to post in the thread.
39
+ - `<slack:@U123>` in your text mentions that person, and `<slack:#C123>` links that channel. A bare `@name` stays as written.
40
+ - Each send carries its send ID in the message's metadata, so Pots finds the message again after a crash and does not post it twice.
41
+
42
+ ## call
43
+
44
+ The `call` tool, with the channel's `id` (`slack`), calls any method of Slack's Web API (https://docs.slack.dev/reference/methods) with the bot token. The method is the method's name, and the params are its arguments. For example:
45
+
46
+ | method | params | does |
47
+ |---|---|---|
48
+ | `chat.update` | `{"channel": "C123", "ts": "1793080260.000100", "markdown_text": "fixed text"}` | edits your message |
49
+ | `conversations.history` | `{"channel": "C123", "limit": 20}` | reads the last 20 messages |
50
+ | `conversations.replies` | `{"channel": "C123", "ts": "1793080260.000100"}` | reads the thread of that message |
51
+ | `files.uploadV2` | `{"channel_id": "C123", "file": "/path/to/report.pdf", "filename": "report.pdf", "initial_comment": "the report"}` | posts a file: a `file` that is a local path is uploaded; add `thread_ts` to post it in a thread |
52
+
53
+ The IDs are in the addresses (`slack:#<channel ID>/<ts>`; a message's `ts` is its ID) and in the raw data in the log. The app has the scopes in [slack-app-manifest.yaml](slack-app-manifest.yaml); a method that needs another scope fails.
54
+
55
+ When someone uses a slash command or a button of the app, you get a `command` or `interaction` event, with Slack's data as its raw data.
56
+
57
+ ## Buttons, forms, tables and clicks
58
+
59
+ `send` posts Markdown text. For buttons, menus and tables, post the message yourself with `call` and Slack's [Block Kit](https://docs.slack.dev/block-kit/): method `chat.postMessage` ([reference](https://docs.slack.dev/reference/methods/chat.postMessage)), params `channel`, `blocks`, and a short `text`, which Slack shows in notifications. Add `thread_ts` to post in a thread. Leave out `markdown_text`: Slack does not take it with `blocks`. Put Markdown in a `markdown` block instead, with `**bold**`, as in `send`. Do not write text as `mrkdwn` in a `section` block: Slack's older mrkdwn does not make `*bold*` that touches Chinese, Japanese or Korean characters, and shows the asterisks.
60
+
61
+ ```json
62
+ {
63
+ "channel": "C123",
64
+ "text": "Where should I deploy release 4.2?",
65
+ "blocks": [
66
+ { "type": "markdown", "text": "Where should I deploy **release 4.2**?" },
67
+ { "type": "actions", "block_id": "deploy-42", "elements": [
68
+ { "type": "button", "action_id": "deploy:test", "value": "test", "text": { "type": "plain_text", "text": "Test" } },
69
+ { "type": "button", "action_id": "deploy:prod", "value": "prod", "style": "danger", "text": { "type": "plain_text", "text": "Production" } }
70
+ ] }
71
+ ]
72
+ }
73
+ ```
74
+
75
+ - **Buttons and menus** go in an `actions` block: [buttons](https://docs.slack.dev/reference/block-kit/block-elements/button-element), [select menus](https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element), [checkboxes](https://docs.slack.dev/reference/block-kit/block-elements/checkboxes-element), [radio buttons](https://docs.slack.dev/reference/block-kit/block-elements/radio-button-group-element), overflow menus and date pickers. You choose each `action_id` and `value`, and they come back with the click, so make them say what the click means.
76
+ - **Tables** are a [`table` block](https://docs.slack.dev/reference/block-kit/blocks/table-block): `rows` of cells of type `raw_text`, `raw_number` or `rich_text`. A table larger than the limits below goes in a page (the pages skill).
77
+ - **Limits that bite** ([all blocks](https://docs.slack.dev/reference/block-kit/blocks)): 50 blocks in a message. 25 elements in an `actions` block. A button's text at most 75 characters (Slack may cut it after about 30), its `value` at most 2000, its `action_id` at most 255 and unique in its block. A select menu at most 100 options; checkboxes and radio buttons at most 10; an option's `value` at most 150 characters. A `section` text at most 3000 characters, and all `markdown` blocks of a message together at most 12,000. A table at most 100 rows of 20 cells, and at most 10,000 characters in all the table cells of a message. A `block_id` is unique in its message; give a block a new one when you change the message.
78
+ - When Slack refuses the blocks, the `call` error gives Slack's answer. Fix what it names and call again.
79
+
80
+ **When someone clicks.** Pots acknowledges the click to Slack at once, within the 3 seconds Slack allows, so the person sees no error. The click wakes you straight away, not through the judge and without waiting for more messages, as an `interaction` event. The platform sends Pots only the clicks on your own buttons, also on a message the log does not have, such as an ephemeral one. The wake says which button (its `action_id`, `value` and text) and who clicked (their person address). Slack's whole payload is the event's raw data in the log.
81
+
82
+ **Mark the question answered.** Anyone who can see the message can click, and a click is not an answer until you decide it counts. Whose click counts, and what it means, is your call, as with messages. When it counts, change your message with `call` `chat.update` ([reference](https://docs.slack.dev/reference/methods/chat.update)): params `channel`, the `ts` of your message, and new `text` and `blocks`, for example the question and a line "✓ Test, chosen by <@U123>" in a `markdown` block, without the `actions` block. Until you change it, the buttons stay, and a click days later still wakes you.
83
+
84
+ **Forms.** Slack opens a form (a modal) only within 3 seconds of a click, which is too soon for you, so you store the form first and Pots opens it:
85
+
86
+ 1. `pots form add <name> <JSON>`, or `-` to read the JSON from stdin: a Slack [view](https://docs.slack.dev/reference/views/modal-views) of type `modal`, with a `title` (at most 24 characters), `submit`, and `blocks` (at most 100) with [`input` blocks](https://docs.slack.dev/reference/block-kit/blocks/input-block). Each input's `block_id` and `action_id` name its value in the answer. Pots sets `private_metadata` itself, to find your message again; if you set your own, it comes back in the answer as a `private_metadata:` line. A name has letters, digits, `-` and `_`, at most 64 characters, and no `:`. Adding a name in use replaces that form.
87
+ 2. Post a button whose `action_id` is `form:<name>`, or `form:<name>:<extra>`. `<extra>` comes back with the answer, so one form serves many messages, for example `form:release-notes:4.2`.
88
+ 3. Someone clicks, and Pots opens the form at once. The click itself does not wake you. When they submit the form, you are woken at once with the form's name, `<extra>`, the submitted values and who submitted it. Slack closes the form when it is submitted, so check the values in your answer, not inside the form. If the form could not open (no form of that name is stored, it is not a view of type `modal`, or Slack refused it), the click wakes you with the reason. `pots form add` stores any JSON object; the form is checked only when it opens.
89
+
90
+ `pots form list` shows your forms, and `pots form remove <name>` removes one.
91
+
92
+ ```sh
93
+ pots form add release-notes - <<'EOF'
94
+ {"type": "modal", "title": {"type": "plain_text", "text": "Release notes"},
95
+ "submit": {"type": "plain_text", "text": "Send"},
96
+ "blocks": [{"type": "input", "block_id": "notes", "label": {"type": "plain_text", "text": "What changed?"},
97
+ "element": {"type": "plain_text_input", "action_id": "text", "multiline": true}}]}
98
+ EOF
99
+ ```
100
+
101
+ **Link previews.** Slack previews the links in a message by default, and its servers open each link to do so. `send` does not turn this off. When you send a page link, and always a password page link (the pages skill), post it with `call` `chat.postMessage` and `"unfurl_links": false, "unfurl_media": false` ([unfurling](https://docs.slack.dev/messaging/unfurling-links-in-messages)):
102
+
103
+ `call slack chat.postMessage {"channel": "C123", "text": "The plan: https://…/p/…/", "unfurl_links": false, "unfurl_media": false}`
104
+
105
+ ## Files
106
+
107
+ The files of a message are saved for you, and the wake gives their paths. The message log keeps each file's `url_private`. Downloading it needs the bot token (scope `files:read`), so Pots downloads only from Slack's own hosts. To download a file again later, read the token from its line of the env file in the shell, so that it stays out of messages and logs, and send it in the `Authorization` header:
108
+
109
+ ```sh
110
+ curl -sS -o plan.png -H "Authorization: Bearer $(grep '^SLACK_BOT_TOKEN=' ~/.pots/secrets/slack.env | cut -d= -f2-)" "<url_private>"
111
+ ```
112
+
113
+ Never `source` the env file or `.` it in a shell, and never print the token: the file holds each value exactly as it was typed, and a value with `$(…)` in it would run as a command.
114
+
115
+ Do not add `-L`: Slack's docs ask you to handle redirects on purpose, so that the token goes to no other host. If you get a web page instead of the file, the app does not have the `files:read` scope.
116
+
117
+ To send a file, use `files.uploadV2` with `call` (above).
118
+
119
+ ## Limits
120
+
121
+ - Messages are in the log as Markdown: a link keeps its URL, and lists, code and emphasis stay.
122
+ - A message can have at most 12,000 characters: your text goes as Slack's `markdown_text`, which has that limit. A longer text is refused, not cut: send it in parts.
123
+ - Slack generally lets an app post 1 message per second in a channel.
124
+ - React with the emoji's name, with or without colons (`eyes`, `:white_check_mark:`), or with the emoji itself (👀), which Pots turns into its name.
125
+ - After a time when you were not running, you get the messages that came in each place you are in, and the new replies in the threads you know and in new threads. Edits, deletions and reactions from that time do not come; a message comes as it is now.
126
+ - You get a `join` when someone joins a channel you are in, with who invited them when someone did. The app does not subscribe to `member_left_channel`, so a person who leaves gives no `leave`.
@@ -0,0 +1,89 @@
1
+ ---
2
+ name: telegram-channel
3
+ description: Telegram for a Pots bot. How to connect a Telegram bot yourself (BotFather, its token, groups, bot.json), topics, files and limits, and how to post buttons under a message (inline keyboards), get clicks, mark a question answered, and send tables. Use when you connect Telegram, or need more in Telegram than plain text.
4
+ ---
5
+
6
+ # Telegram
7
+
8
+ ## Connect
9
+
10
+ Written for a bot that connects itself; a person can follow it too. The bot gets its messages by long polling, so the computer needs no public address.
11
+
12
+ 1. The person makes the Telegram bot in their own Telegram app. Only a Telegram account can make a bot, and you cannot use theirs. Ask them to open a chat with [@BotFather](https://t.me/BotFather), send `/newbot`, and give a name (what people see, for example your name) and a username that ends in `bot`. BotFather answers with the token (`123456789:AA…`).
13
+ 2. In the same chat, ask them to send `/setprivacy`, choose the bot, and choose **Disable**. Without this, you get only the group messages that mention you, reply to you or are commands. The change counts only in groups the bot joins after it: in a group the bot is already in, they remove it and add it again.
14
+ 3. Ask for the token with ask-secret in the terminal channel:
15
+ `call <terminal channel id> ask-secret {"text": "…", "file": "telegram.env", "keys": ["TELEGRAM_BOT_TOKEN"]}`.
16
+ `pots chat` writes it to `telegram.env` in the secrets folder (`~/.pots/secrets/`), readable only by this user, without showing it to you:
17
+ ```sh
18
+ TELEGRAM_BOT_TOKEN=123456789:AA...
19
+ ```
20
+ Do not put the token in a chat message, a log or any other file.
21
+ 4. Add the channel to `channels` in your `bot.json`:
22
+ ```json
23
+ { "id": "telegram", "type": "telegram", "secrets": "~/.pots/secrets/telegram.env" }
24
+ ```
25
+ It connects within a few seconds. `pots status` lists it; if it fails, the reason is in `bot.json.error`. Only one process can get a bot's messages: when another one uses the same token, the gateway's output says so.
26
+ 5. Ask the person to add you to their groups (the group's info → **Add members** → your username). To see reactions, you must be an admin of the group: Telegram sends reactions only to admins. To post in a Telegram channel, you must be an admin there.
27
+ 6. You can write to a person only after they started a chat with you: they open `https://t.me/<your username>` and press **Start**. Until then, a send to them fails.
28
+
29
+ In a group with topics, each topic is a thread. A reply to a message in a topic stays in that topic. If that message was deleted, the reply can fail; then send to the topic or the group instead.
30
+
31
+ Turning topics on makes a group a supergroup, which is a new chat with a new address. The log has a system event in each of the two chats that gives the other's address, and a send to the old address fails with an error that gives the new one.
32
+
33
+ A second Telegram bot is a second channel entry with its own `id` (for example `telegram-shop`) and its own env file.
34
+
35
+ ## call
36
+
37
+ The `call` tool, with the channel's `id` (`telegram`), calls any method of the Bot API (https://core.telegram.org/bots/api) with the bot token. The method is the method's name, and the params are its parameters. The chat ID is the number in a place address: `telegram:#-1001234567890`.
38
+
39
+ ## Buttons, forms, tables and clicks
40
+
41
+ **Tables** need nothing more: `send` posts a rich message, and a Markdown table in your text shows as a table, with at most 20 columns. In a chat that does not take rich messages, it shows as plain text; a large table goes in a page (the pages skill).
42
+
43
+ **Buttons** go under a message as an inline keyboard. Post the message yourself with `call`: `sendMessage` ([reference](https://core.telegram.org/bots/api#sendmessage)) with `reply_markup.inline_keyboard` ([reference](https://core.telegram.org/bots/api#inlinekeyboardmarkup)), a list of rows, each a list of buttons. For rich formatting, use `sendRichMessage` with `"rich_message": {"markdown": "…"}` and the same `reply_markup`. In a topic, add `message_thread_id`.
44
+
45
+ `call telegram sendMessage {"chat_id": -1001234567890, "text": "Where should I deploy release 4.2?", "reply_markup": {"inline_keyboard": [[{"text": "Test", "callback_data": "deploy:test"}, {"text": "Production", "callback_data": "deploy:prod", "style": "danger"}]]}}`
46
+
47
+ - `callback_data` is 1 to 64 **bytes**, not characters ([reference](https://core.telegram.org/bots/api#inlinekeyboardbutton)): a few words or an ID, never a long text, and fewer letters in a script that takes several bytes a letter. You choose it, and it comes back with the click, so make it say what the click means.
48
+ - `style` is `primary`, `success` or `danger`. A button with a `url` instead of `callback_data` opens the link, and its click does not reach you.
49
+ - A chat has no menus or check boxes: give one button per choice, or a page for many choices.
50
+ - When Telegram refuses the message, the `call` error gives Telegram's answer. Fix what it names and call again.
51
+
52
+ **When someone clicks.** Pots answers the click to Telegram itself (`answerCallbackQuery`) at once, so the button stops spinning. Do not call `answerCallbackQuery` yourself: the click is answered already. The click wakes you straight away, not through the judge and without waiting for more messages, as an `interaction` event. The platform sends Pots only the clicks on your own buttons, also on a message the log does not have. The wake says which button (its `callback_data`) and who clicked (their person address). Telegram's callback query is the event's raw data in the log.
53
+
54
+ **Mark the question answered.** Anyone in a group can press the buttons, and a click is not an answer until you decide it counts. Whose click counts, and what it means, is your call, as with messages. When it counts, change your message with `call`:
55
+
56
+ - `editMessageReplyMarkup` ([reference](https://core.telegram.org/bots/api#editmessagereplymarkup)) changes only the buttons, for example to one disabled button that shows the answer: `{"chat_id": -1001234567890, "message_id": 42, "reply_markup": {"inline_keyboard": [[{"text": "✓ Test, chosen by @alice", "disabled": {}}]]}}`.
57
+ - `editMessageText` ([reference](https://core.telegram.org/bots/api#editmessagetext)) changes the text, with `chat_id`, `message_id` and `text`, or `rich_message` for a rich message. Give `reply_markup` with the buttons the message should keep.
58
+
59
+ Until you change it, the buttons stay, and a click days later still wakes you.
60
+
61
+ **Forms.** Telegram has no forms. Ask one short question in text; for several inputs, write a page (the pages skill) and send its link.
62
+
63
+ **Link previews.** Telegram shows a preview of a link in a message. When you send a page link, and always a password page link (the pages skill), post it with `call` `sendMessage` and `"link_preview_options": {"is_disabled": true}` ([reference](https://core.telegram.org/bots/api#linkpreviewoptions)). `send` posts a rich message, which has no such option, so send these links with `call`:
64
+
65
+ `call telegram sendMessage {"chat_id": -1001234567890, "text": "The plan: https://…/p/…/", "link_preview_options": {"is_disabled": true}}`
66
+
67
+ ## Files
68
+
69
+ The files of a message are saved for you, and the wake gives their paths. The message log keeps each file's URL as `telegram-file:<file ID>`, without the token. To download a file again later:
70
+
71
+ 1. `call <channel id> getFile {"file_id": "<file ID>"}` gives its `file_path`.
72
+ 2. Download it from Telegram's file host with the token from its line of the env file, read in the shell, so that it stays out of messages and logs:
73
+ ```sh
74
+ curl -sS -o photo.jpg "https://api.telegram.org/file/bot$(grep '^TELEGRAM_BOT_TOKEN=' ~/.pots/secrets/telegram.env | cut -d= -f2-)/<file_path>"
75
+ ```
76
+ Never `source` the env file or `.` it in a shell, and never print the token: the file holds each value exactly as it was typed, and a value with `$(…)` in it would run as a command.
77
+ The link works for at least an hour. Telegram gives bots files of at most 20 MB.
78
+
79
+ To send a file, give its local path to `call`: `call <channel id> sendDocument {"chat_id": -1001234567890, "document": "/path/to/report.pdf"}` (also sendPhoto, sendVideo, sendMediaGroup and the others). The chat ID is the number in a place address: `telegram:#-1001234567890`.
80
+
81
+ ## Limits
82
+
83
+ - Your Markdown goes as a Telegram rich message, which shows headings, lists and tables. A message has at most 32768 characters of shown text. A longer text is refused, not cut: send it in parts.
84
+ - In a chat that does not take rich messages, the text goes as a plain message with simpler formatting, and then a message has at most 4096 characters. The send error says so; send the text in parts.
85
+ - The Bot API cannot read history. Messages that came while you were not running arrive when you connect again, but only from the last 24 hours.
86
+ - Telegram does not say when a message is deleted.
87
+ - Service messages, such as a pin, a new group name or a closed topic, are `system` events in the log, not messages; their text says what happened, and a pin is about the pinned message.
88
+ - If the computer stops between Telegram taking a message you sent and Pots recording it, the message can go out twice.
89
+ - You have at most one reaction on a message. A new one takes the place of the old one.