pi-durable-bot 0.6.1 → 0.7.1
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/CHANGELOG.md +27 -2
- package/README.md +47 -21
- package/dist/agent/resources.js +12 -1
- package/dist/agent/resources.js.map +1 -1
- package/dist/bot/bot.js +54 -5
- package/dist/bot/bot.js.map +1 -1
- package/dist/bot/prompt.js +13 -3
- package/dist/bot/prompt.js.map +1 -1
- package/dist/channels/discord/index.js +202 -20
- package/dist/channels/discord/index.js.map +1 -1
- package/dist/channels/slack/index.js +314 -16
- package/dist/channels/slack/index.js.map +1 -1
- package/dist/channels/telegram/index.js +21 -2
- package/dist/channels/telegram/index.js.map +1 -1
- package/dist/cli/agent.js +20 -1
- package/dist/cli/agent.js.map +1 -1
- package/dist/cli/commands.js +28 -4
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/pages.js +44 -0
- package/dist/cli/pages.js.map +1 -0
- package/dist/core/channel.js +4 -1
- package/dist/core/channel.js.map +1 -1
- package/dist/core/env-file.js +23 -6
- package/dist/core/env-file.js.map +1 -1
- package/dist/core/forms.js +16 -0
- package/dist/core/forms.js.map +1 -0
- package/dist/gateway/errors.js +3 -0
- package/dist/gateway/errors.js.map +1 -1
- package/dist/gateway/forms.js +99 -0
- package/dist/gateway/forms.js.map +1 -0
- package/dist/gateway/gateway.js +23 -1
- package/dist/gateway/gateway.js.map +1 -1
- package/dist/gateway/log.js +7 -5
- package/dist/gateway/log.js.map +1 -1
- package/dist/gateway/waker.js +23 -8
- package/dist/gateway/waker.js.map +1 -1
- package/dist/main.js +7 -1
- package/dist/main.js.map +1 -1
- package/dist/pages/cloudflared.js +149 -0
- package/dist/pages/cloudflared.js.map +1 -0
- package/dist/pages/files.js +244 -0
- package/dist/pages/files.js.map +1 -0
- package/dist/pages/host.js +268 -0
- package/dist/pages/host.js.map +1 -0
- package/dist/pages/secret-page.js +71 -0
- package/dist/pages/secret-page.js.map +1 -0
- package/dist/pages/server.js +305 -0
- package/dist/pages/server.js.map +1 -0
- package/dist/pages/settings.js +71 -0
- package/dist/pages/settings.js.map +1 -0
- package/dist/pages/store.js +492 -0
- package/dist/pages/store.js.map +1 -0
- package/dist/pages/tunnel.js +271 -0
- package/dist/pages/tunnel.js.map +1 -0
- package/kit/pots.css +473 -0
- package/kit/pots.js +627 -0
- package/package.json +13 -3
- package/pi-package/skills/pots-setup/SKILL.md +15 -0
- package/{docs/channels/discord.md → skills/discord-channel/SKILL.md} +55 -2
- package/skills/pages/SKILL.md +242 -0
- package/skills/slack-channel/SKILL.md +126 -0
- package/skills/telegram-channel/SKILL.md +89 -0
- package/docs/channels/slack.md +0 -70
- package/docs/channels/telegram.md +0 -50
- /package/{docs/channels → skills/slack-channel}/slack-app-manifest.yaml +0 -0
package/docs/channels/slack.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Connect Slack
|
|
2
|
-
|
|
3
|
-
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.
|
|
4
|
-
|
|
5
|
-
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.
|
|
6
|
-
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).
|
|
7
|
-
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.
|
|
8
|
-
3. **Basic Information → App-Level Tokens → Generate Token and Scopes**: add the scope `connections:write` and generate. This is the app token (`xapp-…`).
|
|
9
|
-
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-…`).
|
|
10
|
-
5. Write both tokens to `slack.env` in the secrets folder (`~/.pots/secrets/`), readable only by this user:
|
|
11
|
-
```sh
|
|
12
|
-
SLACK_APP_TOKEN=xapp-...
|
|
13
|
-
SLACK_BOT_TOKEN=xoxb-...
|
|
14
|
-
```
|
|
15
|
-
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:
|
|
16
|
-
`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.
|
|
17
|
-
6. Add the channel to `channels` in your `bot.json`:
|
|
18
|
-
```json
|
|
19
|
-
{ "id": "slack", "type": "slack", "secrets": "~/.pots/secrets/slack.env" }
|
|
20
|
-
```
|
|
21
|
-
It connects within a few seconds. `pots status` lists it; if it fails, the reason is in `bot.json.error`.
|
|
22
|
-
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.
|
|
23
|
-
|
|
24
|
-
A second Slack workspace is a second channel entry with its own `id` (for example `slack-acme`) and its own env file.
|
|
25
|
-
|
|
26
|
-
## Sending
|
|
27
|
-
|
|
28
|
-
- Your text is Markdown; Slack shows it formatted.
|
|
29
|
-
- Send to a place to post in it, and to a person to post in a DM with them.
|
|
30
|
-
- 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.
|
|
31
|
-
- Send to a thread (the address of its first message) to post in the thread.
|
|
32
|
-
- `<slack:@U123>` in your text mentions that person, and `<slack:#C123>` links that channel. A bare `@name` stays as written.
|
|
33
|
-
- 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.
|
|
34
|
-
|
|
35
|
-
## call
|
|
36
|
-
|
|
37
|
-
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:
|
|
38
|
-
|
|
39
|
-
| method | params | does |
|
|
40
|
-
|---|---|---|
|
|
41
|
-
| `chat.update` | `{"channel": "C123", "ts": "1793080260.000100", "markdown_text": "fixed text"}` | edits your message |
|
|
42
|
-
| `conversations.history` | `{"channel": "C123", "limit": 20}` | reads the last 20 messages |
|
|
43
|
-
| `conversations.replies` | `{"channel": "C123", "ts": "1793080260.000100"}` | reads the thread of that message |
|
|
44
|
-
| `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 |
|
|
45
|
-
|
|
46
|
-
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.
|
|
47
|
-
|
|
48
|
-
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.
|
|
49
|
-
|
|
50
|
-
## Files
|
|
51
|
-
|
|
52
|
-
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 in the shell, so that it stays out of messages and logs, and send it in the `Authorization` header:
|
|
53
|
-
|
|
54
|
-
```sh
|
|
55
|
-
. ~/.pots/secrets/slack.env
|
|
56
|
-
curl -sS -o plan.png -H "Authorization: Bearer $SLACK_BOT_TOKEN" "<url_private>"
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
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.
|
|
60
|
-
|
|
61
|
-
To send a file, use `files.uploadV2` with `call` (above).
|
|
62
|
-
|
|
63
|
-
## Limits
|
|
64
|
-
|
|
65
|
-
- Messages are in the log as Markdown: a link keeps its URL, and lists, code and emphasis stay.
|
|
66
|
-
- 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.
|
|
67
|
-
- Slack generally lets an app post 1 message per second in a channel.
|
|
68
|
-
- 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.
|
|
69
|
-
- 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.
|
|
70
|
-
- 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`.
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# Connect Telegram
|
|
2
|
-
|
|
3
|
-
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.
|
|
4
|
-
|
|
5
|
-
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…`).
|
|
6
|
-
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.
|
|
7
|
-
3. Ask for the token with ask-secret in the terminal channel:
|
|
8
|
-
`call <terminal channel id> ask-secret {"text": "…", "file": "telegram.env", "keys": ["TELEGRAM_BOT_TOKEN"]}`.
|
|
9
|
-
`pots chat` writes it to `telegram.env` in the secrets folder (`~/.pots/secrets/`), readable only by this user, without showing it to you:
|
|
10
|
-
```sh
|
|
11
|
-
TELEGRAM_BOT_TOKEN=123456789:AA...
|
|
12
|
-
```
|
|
13
|
-
Do not put the token in a chat message, a log or any other file.
|
|
14
|
-
4. Add the channel to `channels` in your `bot.json`:
|
|
15
|
-
```json
|
|
16
|
-
{ "id": "telegram", "type": "telegram", "secrets": "~/.pots/secrets/telegram.env" }
|
|
17
|
-
```
|
|
18
|
-
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.
|
|
19
|
-
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.
|
|
20
|
-
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.
|
|
21
|
-
|
|
22
|
-
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.
|
|
23
|
-
|
|
24
|
-
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.
|
|
25
|
-
|
|
26
|
-
A second Telegram bot is a second channel entry with its own `id` (for example `telegram-shop`) and its own env file.
|
|
27
|
-
|
|
28
|
-
## Files
|
|
29
|
-
|
|
30
|
-
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:
|
|
31
|
-
|
|
32
|
-
1. `call <channel id> getFile {"file_id": "<file ID>"}` gives its `file_path`.
|
|
33
|
-
2. Download it from Telegram's file host with the token from the env file, read in the shell, so that it stays out of messages and logs:
|
|
34
|
-
```sh
|
|
35
|
-
. ~/.pots/secrets/telegram.env
|
|
36
|
-
curl -sS -o photo.jpg "https://api.telegram.org/file/bot$TELEGRAM_BOT_TOKEN/<file_path>"
|
|
37
|
-
```
|
|
38
|
-
The link works for at least an hour. Telegram gives bots files of at most 20 MB.
|
|
39
|
-
|
|
40
|
-
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`.
|
|
41
|
-
|
|
42
|
-
## Limits
|
|
43
|
-
|
|
44
|
-
- 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.
|
|
45
|
-
- 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.
|
|
46
|
-
- 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.
|
|
47
|
-
- Telegram does not say when a message is deleted.
|
|
48
|
-
- 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.
|
|
49
|
-
- If the computer stops between Telegram taking a message you sent and Pots recording it, the message can go out twice.
|
|
50
|
-
- You have at most one reaction on a message. A new one takes the place of the old one.
|
|
File without changes
|