@capybara-hq/plugin-telegram 0.0.0-stage → 0.1.0-rc.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.
@@ -0,0 +1,63 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "name": "telegram",
4
+ "version": "0.1.0-rc.1",
5
+ "publisher": "Capybara",
6
+ "description": {
7
+ "en": "Telegram (channel@1 bot over the Bot API: long polling or webhook, inline keyboard cards)",
8
+ "zh": "Telegram 机器人渠道(channel@1,Bot API:长轮询或 webhook,内联键盘卡片)"
9
+ },
10
+ "displayName": {
11
+ "zh": "Telegram",
12
+ "en": "Telegram"
13
+ },
14
+ "icon": "./icon.svg",
15
+ "homepage": "https://github.com/capybara-hq/plugins/tree/main/plugins/telegram#readme",
16
+ "extension": {
17
+ "entry": "./dist/index.mjs",
18
+ "manifest": {
19
+ "name": "telegram",
20
+ "version": "0.1.0-rc.1",
21
+ "sdk": "^0.1.0-rc.4",
22
+ "provides": [
23
+ "channel@1"
24
+ ],
25
+ "requires": [],
26
+ "optional": [],
27
+ "permissions": {
28
+ "network": [
29
+ "api.telegram.org"
30
+ ]
31
+ },
32
+ "config": {
33
+ "deployment": [
34
+ {
35
+ "path": "apiUrl",
36
+ "secret": false,
37
+ "hot": false
38
+ }
39
+ ],
40
+ "org": []
41
+ }
42
+ },
43
+ "configSchemas": {
44
+ "deployment": {
45
+ "type": "object",
46
+ "properties": {
47
+ "apiUrl": {
48
+ "default": "https://api.telegram.org",
49
+ "type": "string",
50
+ "format": "uri",
51
+ "x-ui": {
52
+ "label": {
53
+ "zh": "API 地址",
54
+ "en": "API URL"
55
+ }
56
+ },
57
+ "title": "API URL"
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Capybara
2
+ Copyright 2026 Meta-1 (Tianjin Yuanyilian Technology Co., Ltd.)
package/README.md CHANGED
@@ -1,3 +1,181 @@
1
- # Temporary Holding Version
1
+ # @capybara-hq/plugin-telegram
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The official Telegram plugin. It provides one capability:
4
+
5
+ - `channel@1` (bot): talk to Capybara agents in a private chat with a Telegram bot, or by mentioning the bot in a group.
6
+ Messages arrive by long polling (`getUpdates`, the default, no public URL needed) or by webhook (optional),
7
+ replies are sent with `sendMessage` and streamed by editing, and approval / question / connection / binding
8
+ cards are rendered as inline keyboards.
9
+
10
+ It does not provide login (`identity-source@1`) or a directory (`directory@1`); see [Out of scope](#out-of-scope).
11
+
12
+ Identity: `identities.source` = `telegram:global`, `external_id` = the Telegram user id (decimal). Telegram user ids are
13
+ global (one person has the same id for every bot), so one person is one identity across every Telegram bot of a deployment.
14
+
15
+ The Telegram docs cited here are the [Bot API reference](https://core.telegram.org/bots/api) (Bot API 10.3), consulted on 2026-11-08.
16
+
17
+ Verified live on 2026-11-08 against a real bot: verify, send, edit, a 5000-character split send and a card with an inline callback keyboard, in a private chat and in a basic group. Not covered live: a person clicking a card button, webhook mode and forum supergroups.
18
+
19
+ ## Create the bot
20
+
21
+ 1. In Telegram, open [@BotFather](https://t.me/BotFather) and send `/newbot`. Pick a display name and a username
22
+ (it must end in `bot`). BotFather replies with the bot token, such as `123456:ABC-DEF…`
23
+ ([Bot API: authorizing your bot](https://core.telegram.org/bots/api#authorizing-your-bot)). Treat it like a password.
24
+ 2. **Privacy mode** (`/setprivacy`): leave it **enabled** (the default). With it on, a bot in a group receives only
25
+ commands, mentions of the bot and replies to the bot's own messages, which is exactly what this plugin forwards
26
+ ([Bot API: `getMe`, `can_read_all_group_messages`](https://core.telegram.org/bots/api#getme)).
27
+ If you turn it off the bot receives every group message; the plugin still forwards only mentions and replies to
28
+ the bot, and `verify` logs a warning. Telegram applies a privacy change to a group only after the bot is removed from the group and added again.
29
+ 3. **Groups** (`/setjoingroups`): enable it if people should add the bot to groups, disable it for a private-only bot.
30
+ 4. **Topics in private chats**: leave the bot's topic mode off. It is not supported (see [Behavior](#behavior)); `verify` warns when it is on.
31
+ 5. In the Capybara org settings, enable the `telegram` plugin, then **create a new channel connection** under Channels:
32
+ pick Telegram as the plugin, fill in the bot token (`botToken`) and bind an agent. The token is stored in the secret
33
+ store and the API only returns "set".
34
+ 6. In Telegram, open the bot and press **Start** (see [Binding](#binding)). The first message gets a binding card; open its link to confirm the binding on the web page.
35
+
36
+ ## Binding
37
+
38
+ A person must bind their Telegram user to a Capybara account before the agent answers. The kernel sends the binding card
39
+ in the private chat only.
40
+
41
+ - **Press Start once.** A bot cannot message a user who never started it: Telegram answers 403 ("Forbidden: bot can't initiate conversation with a user"),
42
+ which the plugin maps to `target_gone`. So the first step for everyone is to open the bot and press **Start** (or send any message).
43
+ - **Start is a message.** Pressing Start sends `/start`, and the plugin forwards it like any other text: that is what gives a new
44
+ user the binding card. A user who is already bound and presses Start again (for example after clearing the chat) sends `/start` to the agent.
45
+ - **In a group**, an unbound person who mentions the bot gets a "bind in a private chat" reply instead of a card: open the bot, press Start, and bind there.
46
+ - **The `anonymous` unbound policy has no effect on Telegram.** A Telegram bot is reachable by anyone who finds it, so
47
+ anonymous guests would let the whole internet use an org's agent and model budget (maintainer decision). Every Telegram user is *external*
48
+ to the connection: `verify` returns the tenant `bot<bot id>` while every inbound sender's tenant is `global`, and the kernel never lets an external sender be an anonymous guest.
49
+ A connection set to `anonymous` therefore gives an unbound person the binding reply, not an agent run.
50
+
51
+ ## Channel connection config
52
+
53
+ Shown in the form with zh / en labels and help.
54
+
55
+ | Field | Label | Description |
56
+ |---|---|---|
57
+ | `botToken` | Bot token / 机器人令牌 | `<bot id>:<secret>` from @BotFather (secret) |
58
+ | `webhookSecret` | Webhook secret / Webhook 密钥 | Secret, 1-256 characters of `A-Z a-z 0-9 _ -`; only needed in [webhook mode](#webhook-mode-optional) (the `secret_token` you give `setWebhook`), leave empty for long polling |
59
+
60
+ ## Deployment-level config
61
+
62
+ | Field | Default | Description |
63
+ |---|---|---|
64
+ | `apiUrl` | `https://api.telegram.org` | Bot API root URL; change it only in tests or when going through a reverse proxy |
65
+
66
+ The deployment-level config lives under the kernel config `extensionConfig.telegram`. There is no org-level config.
67
+
68
+ ## Behavior
69
+
70
+ - **Private chats**: every text message goes to the kernel (`chatType: "dm"`, one conversation per user). Topic mode in
71
+ private chats (`has_topics_enabled`) is **not supported**: the kernel keys a private chat as one thread per user. `verify` warns when it is on; keep it off.
72
+ - **Groups and supergroups**: only messages that mention the bot (`@<username>`, a text mention, or a command addressed to the bot such as `/cmd@botname`)
73
+ and replies to one of the bot's messages (a reply to the bot counts as a mention, since people address a bot by replying to it). Other group messages are dropped.
74
+ - **Threads**: each mention that is not a reply starts its own conversation, and replies continue it. Telegram replies only point to their direct parent,
75
+ so the plugin records the thread of every message it sends into a group and of every inbound group message it forwards (kv, 30 days). A reply to a bot message older than that, or to an unknown message, starts a new conversation.
76
+ Replies are sent as replies to the thread's root message.
77
+ - **Forum supergroups behave like groups.** A forum topic is only where the messages live, never the conversation key (otherwise a topic would become one ever-growing conversation):
78
+ each mention starts a conversation and replies continue it. The plugin remembers the topic (`message_thread_id`, kv, 30 days) so replies land in the right topic. `/new` works only in private chats.
79
+ - **Ignored**: edited messages, channel posts, messages from bots, service messages (a group becoming a supergroup is logged; the old conversations in it then stop receiving replies), messages without text or caption.
80
+ A caption on media is taken as the text; the media itself is ignored.
81
+ - **Text**: the bot mention is removed, a leading `/` is kept exactly where the person typed it (`/cmd@botname` becomes `/cmd`; commands are the kernel's), and mentions of other people become readable `@name`.
82
+ The speaker's display name is first + last name from the update itself; there is no avatar (getting one needs two more calls and exposes a file URL that carries the token).
83
+ - **ids**: message id = `<chat id>:<message id>` (the chat id may be negative); the card-click `eventId` = the `callback_query.id`.
84
+ Messages with `message_id` 0 (ephemeral or scheduled) send no event: they have no stable id.
85
+ - **Format**: the model reply's Markdown is converted to Telegram HTML (`parse_mode: "HTML"`); everything else is escaped.
86
+ Link previews are off. Links are limited to http(s): `tg://` and other schemes stay plain text, so model text cannot produce `tg://user?id=…` mentions.
87
+ A raw `@username` in model text would notify people, so the converter puts a U+2060 WORD JOINER after the `@` outside code and links, and Telegram no longer parses it as a mention.
88
+ - **Limit and splitting**: one message holds at most 4096 characters after entity parsing
89
+ ([`sendMessage`, `text`](https://core.telegram.org/bots/api#sendmessage)); longer text is split into several messages and the last id is returned.
90
+ An edit that would need several messages reports `too_large` and the kernel sends a new message instead.
91
+ - **Streaming edits**: replies are sent and then edited ([`editMessageText`](https://core.telegram.org/bots/api#editmessagetext)); `minEditIntervalMs = 3000`.
92
+ Telegram's limit for a group is about 20 messages per minute ([Broadcasting to users, FAQ](https://core.telegram.org/bots/faq))
93
+ and edits count; a 429 is honored through `retry_after`. "message is not modified" on an edit counts as success.
94
+ [`sendMessageDraft`](https://core.telegram.org/bots/api#sendmessagedraft) is not used: it exists only in private chats, is a 30-second preview that must be followed by a real
95
+ `sendMessage`, and does not fit the kernel's send-then-edit model.
96
+ - **Idempotency**: the Bot API has no idempotent send, so `idempotencyKey` is ignored. A send whose response is lost and is retried can show the message twice; the alternative (never retrying) would lose messages.
97
+ - **Permission manifest**: `network: ["api.telegram.org"]`, shown only and not enforced.
98
+
99
+ ## Cards
100
+
101
+ Approval, question, connection and binding cards are the message text plus an **inline keyboard** ([`InlineKeyboardMarkup`](https://core.telegram.org/bots/api#inlinekeyboardmarkup)),
102
+ with button labels in the org's language. Link buttons are used only for http(s) URLs.
103
+
104
+ - **One message per card.** The kernel sends a card with a short line of text ("Your input is needed") and later updates it the same way, so
105
+ the text leads the card's own message (left out when it repeats the card's title) and the update edits that one message. A card message is
106
+ never split: over 4096 characters the text is cut first, then the card, each ending in "…". Text without a card is split as described above.
107
+ - **Rejected link buttons.** Telegram refuses some link-button URLs that work as links in text, such as `http://localhost:3000/...`
108
+ ("Wrong HTTP URL"; `127.0.0.1` and LAN addresses are accepted). When a send or edit is refused for that reason, the plugin sends it once more
109
+ without link buttons and puts the link into the card text; callback buttons stay.
110
+
111
+ - `callback_data` is limited to 64 bytes ([`InlineKeyboardButton`](https://core.telegram.org/bots/api#inlinekeyboardbutton)), too small for a card id, action, scope and answer.
112
+ Each button carries `cb:` plus a random 16-character token; the payload lives in kv for **30 days**, and any replica can decode it. A click whose token is missing, expired or malformed is answered and ignored.
113
+ After 30 days a card's buttons stop working; use the card's "open on web" link.
114
+ - A question card with a single single-choice field of at most 5 options shows one button per option. Any other question (several fields, a multi-select field, a field that allows "other", a non-enum field, or more than 5 options) is answered on the web: its card carries only the link.
115
+ - A decided or expired card is edited to its new state without its action buttons; only the "Open on web" link button stays.
116
+ - Every click is answered with `answerCallbackQuery` (no text) so the client's progress indicator stops. In long polling this happens after the kernel accepted the click.
117
+
118
+ ## Errors
119
+
120
+ | Telegram | `ChannelSendError` |
121
+ |---|---|
122
+ | 429 | retryable, waits `retry_after` |
123
+ | 5xx, network error, timeout | retryable |
124
+ | 401 Unauthorized | `auth` (not retryable) |
125
+ | 403 (bot blocked, kicked, can't initiate conversation) | `target_gone` |
126
+ | 400 chat not found, or the group migrated to a supergroup | `target_gone` |
127
+ | 400 message too long | `too_large` |
128
+ | other 400 | `rejected` |
129
+
130
+ The Bot API puts the token in the URL path (`/bot<token>/<method>`), so error messages and logs carry only the method, Telegram's `error_code` and its short description, never the URL.
131
+
132
+ ## Long polling (default)
133
+
134
+ `connect` calls `getUpdates` in a loop (25-second long poll, `allowed_updates=["message","callback_query"]`), held by one `gateway` replica per connection.
135
+
136
+ - The offset is confirmed only **after the kernel accepted** the update (`onEvent` resolved, or the update was ignored). If `onEvent` rejects, the loop backs off and fetches the same update again; Telegram keeps updates for 24 hours.
137
+ The confirmed offset is also kept in kv (7 days), so the replica that takes over after a failover resumes where the last one stopped (a repeat is safe: the kernel dedupes by message id).
138
+ - `connect` never changes webhook state behind your back. If a webhook is set for the bot, it fails with "A webhook is set for this Telegram bot; switch the connection to webhook mode or call deleteWebhook"
139
+ (check with [`getWebhookInfo`](https://core.telegram.org/bots/api#getwebhookinfo)).
140
+ - **409 Conflict** means another client is polling the same bot (another deployment, a script, a second connection with the same token). The connection fails with "another client is polling this bot" and the kernel records `last_error`. A 401 fails with "bot token rejected".
141
+ - Network errors back off exponentially with jitter (cap 30 seconds); 5 failures in a row end `connect` with an error, and the kernel records `last_error` and takes over.
142
+
143
+ ## Webhook mode (optional)
144
+
145
+ A connection can instead receive updates over HTTPS, when the deployment exposes a gateway replica and sets `channels.webhookBaseUrl` (see
146
+ [Deploying: webhook](https://github.com/capybara-hq/core/blob/main/docs/deploy/README.md#webhook-optional)). Switch the connection to webhook mode in the web app
147
+ (Channels → connection → Overview → Inbound mode); the connection page then shows its webhook URL. The plugin never calls `setWebhook` itself; you do, once:
148
+
149
+ 1. Choose a secret (1-256 characters of `A-Z a-z 0-9 _ -`) and put it into the connection's `webhookSecret`. Every request is checked against it
150
+ (the `X-Telegram-Bot-Api-Secret-Token` header, compared in constant time); without it every webhook request is refused with 401.
151
+ 2. Register the webhook ([`setWebhook`](https://core.telegram.org/bots/api#setwebhook)), with the `url` from the connection page:
152
+
153
+ ```bash
154
+ curl "https://api.telegram.org/bot<botToken>/setWebhook" \
155
+ --data-urlencode "url=<webhook URL from the connection page>" \
156
+ --data-urlencode "secret_token=<webhookSecret>" \
157
+ --data-urlencode 'allowed_updates=["message","callback_query"]'
158
+ ```
159
+
160
+ 3. To go back to long polling, call [`deleteWebhook`](https://core.telegram.org/bots/api#deletewebhook) (long polling refuses to start while a webhook is set) and switch the connection back to long polling.
161
+
162
+ Both modes parse updates the same way (same message and click ids), so the kernel's dedupe drops a redelivery that arrives across a mode switch. The kernel acks (200) only after it accepted the update; a non-2xx makes Telegram retry.
163
+
164
+ Trade-off: the webhook contract gives the plugin no hook after the kernel accepted the update, so a card click is answered with `answerCallbackQuery` **before** the event is handed over.
165
+ If the kernel then answers non-2xx and Telegram redelivers, the spinner has already stopped; the click itself is not lost and the redelivery is deduped.
166
+
167
+ ## Out of scope
168
+
169
+ - **Login (`identity-source@1`)**: Telegram login gives no email and its widget does not fit the kernel's redirect / callback flow; binding through the bot already links a Telegram user to an account (maintainer decision).
170
+ - **Directory (`directory@1`)**: the Bot API cannot list group members and Telegram has no organization concept (maintainer decision).
171
+ - **Media**: attachments, voice, stickers, polls, inline mode, business accounts and broadcast channels are not handled; media without a caption sends no event.
172
+ - **Proxy**: no proxy support for networks where `api.telegram.org` is unreachable (maintainer decision); `apiUrl` can point at a reverse proxy you run.
173
+
174
+ ## Icon
175
+
176
+ `icon.svg`: the Telegram logo (owner: Telegram), downloaded on 2026-11-09 from
177
+ https://telegram.org/tour/screenshots ("Download Telegram Logos", file `Logo.svg`). Telegram lets
178
+ its logos be used as long as people understand you're not representing Telegram officially. It is a
179
+ trademark of its owner, used only to identify the service this plugin connects to; the plugin is
180
+ not affiliated with or endorsed by the owner. The artwork is unchanged except for removing editor
181
+ metadata.