@teactjs/telegram 0.1.0-alpha.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/README.md +111 -0
- package/dist/index.js +8263 -0
- package/dist/react/src/callback-registry.d.ts +11 -0
- package/dist/react/src/callback-registry.d.ts.map +1 -0
- package/dist/react/src/components.d.ts +396 -0
- package/dist/react/src/components.d.ts.map +1 -0
- package/dist/react/src/error-boundary.d.ts +19 -0
- package/dist/react/src/error-boundary.d.ts.map +1 -0
- package/dist/react/src/hooks.d.ts +37 -0
- package/dist/react/src/hooks.d.ts.map +1 -0
- package/dist/react/src/index.d.ts +11 -0
- package/dist/react/src/index.d.ts.map +1 -0
- package/dist/renderer/src/index.d.ts +5 -0
- package/dist/renderer/src/index.d.ts.map +1 -0
- package/dist/renderer/src/nodes.d.ts +23 -0
- package/dist/renderer/src/nodes.d.ts.map +1 -0
- package/dist/renderer/src/renderer.d.ts +9 -0
- package/dist/renderer/src/renderer.d.ts.map +1 -0
- package/dist/renderer/src/types.d.ts +36 -0
- package/dist/renderer/src/types.d.ts.map +1 -0
- package/dist/runtime/src/auth-session.d.ts +51 -0
- package/dist/runtime/src/auth-session.d.ts.map +1 -0
- package/dist/runtime/src/auth.d.ts +37 -0
- package/dist/runtime/src/auth.d.ts.map +1 -0
- package/dist/runtime/src/bot.d.ts +143 -0
- package/dist/runtime/src/bot.d.ts.map +1 -0
- package/dist/runtime/src/config.d.ts +38 -0
- package/dist/runtime/src/config.d.ts.map +1 -0
- package/dist/runtime/src/context.d.ts +74 -0
- package/dist/runtime/src/context.d.ts.map +1 -0
- package/dist/runtime/src/conversation.d.ts +310 -0
- package/dist/runtime/src/conversation.d.ts.map +1 -0
- package/dist/runtime/src/event-hooks.d.ts +49 -0
- package/dist/runtime/src/event-hooks.d.ts.map +1 -0
- package/dist/runtime/src/i18n.d.ts +55 -0
- package/dist/runtime/src/i18n.d.ts.map +1 -0
- package/dist/runtime/src/index.d.ts +28 -0
- package/dist/runtime/src/index.d.ts.map +1 -0
- package/dist/runtime/src/invoice.d.ts +120 -0
- package/dist/runtime/src/invoice.d.ts.map +1 -0
- package/dist/runtime/src/media-hooks.d.ts +178 -0
- package/dist/runtime/src/media-hooks.d.ts.map +1 -0
- package/dist/runtime/src/middleware.d.ts +26 -0
- package/dist/runtime/src/middleware.d.ts.map +1 -0
- package/dist/runtime/src/plugin.d.ts +32 -0
- package/dist/runtime/src/plugin.d.ts.map +1 -0
- package/dist/runtime/src/router.d.ts +168 -0
- package/dist/runtime/src/router.d.ts.map +1 -0
- package/dist/runtime/src/session.d.ts +20 -0
- package/dist/runtime/src/session.d.ts.map +1 -0
- package/dist/runtime/src/stream.d.ts +34 -0
- package/dist/runtime/src/stream.d.ts.map +1 -0
- package/dist/telegram/src/adapter.d.ts +83 -0
- package/dist/telegram/src/adapter.d.ts.map +1 -0
- package/dist/telegram/src/conversations.d.ts +175 -0
- package/dist/telegram/src/conversations.d.ts.map +1 -0
- package/dist/telegram/src/index.d.ts +8 -0
- package/dist/telegram/src/index.d.ts.map +1 -0
- package/dist/telegram/src/serialize.d.ts +80 -0
- package/dist/telegram/src/serialize.d.ts.map +1 -0
- package/dist/telegram/src/stream.d.ts +12 -0
- package/dist/telegram/src/stream.d.ts.map +1 -0
- package/package.json +38 -0
- package/src/index.ts +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# @teactjs/telegram
|
|
2
|
+
|
|
3
|
+
Telegram adapter for Teact, powered by [grammY](https://grammy.dev). Handles communication between the Teact runtime and the Telegram Bot API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @teactjs/telegram
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic Setup
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createBot } from "@teactjs/core";
|
|
15
|
+
import { TelegramAdapter } from "@teactjs/telegram";
|
|
16
|
+
|
|
17
|
+
const bot = createBot({
|
|
18
|
+
component: App,
|
|
19
|
+
adapter: new TelegramAdapter(),
|
|
20
|
+
token: process.env.BOT_TOKEN,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await bot.start();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Polling (Development)
|
|
27
|
+
|
|
28
|
+
The default mode. The adapter long-polls the Telegram API for updates.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
const bot = createBot({
|
|
32
|
+
component: App,
|
|
33
|
+
adapter: new TelegramAdapter(),
|
|
34
|
+
token: process.env.BOT_TOKEN,
|
|
35
|
+
mode: "polling",
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Webhook (Production)
|
|
40
|
+
|
|
41
|
+
For production, use webhooks. The adapter starts an HTTP server and registers the webhook URL with Telegram.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const bot = createBot({
|
|
45
|
+
component: App,
|
|
46
|
+
adapter: new TelegramAdapter(),
|
|
47
|
+
token: process.env.BOT_TOKEN,
|
|
48
|
+
mode: "webhook",
|
|
49
|
+
webhook: {
|
|
50
|
+
domain: "https://my-bot.example.com",
|
|
51
|
+
port: 3000, // default: 3000
|
|
52
|
+
path: "/webhook", // default: "/webhook"
|
|
53
|
+
secretToken: "s3cr3t", // optional, validates X-Telegram-Bot-Api-Secret-Token header
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Adapter API
|
|
59
|
+
|
|
60
|
+
The adapter implements the Teact adapter interface:
|
|
61
|
+
|
|
62
|
+
| Method | Description |
|
|
63
|
+
|--------|-------------|
|
|
64
|
+
| `connect({ token })` | Initializes the grammY bot instance |
|
|
65
|
+
| `listen({ polling?, webhook? })` | Starts polling or webhook server |
|
|
66
|
+
| `send(chatId, output)` | Serializes an `OutputNode` tree and sends it via Telegram |
|
|
67
|
+
| `edit(chatId, messageId, output)` | Edits an existing message |
|
|
68
|
+
| `clearButtons(chatId, messageId)` | Removes inline keyboard from a message |
|
|
69
|
+
| `setCommands(commands)` | Registers bot commands with Telegram |
|
|
70
|
+
| `use(...middlewares)` | Adds grammY middleware to the bot instance |
|
|
71
|
+
| `disconnect()` | Stops polling or webhook server |
|
|
72
|
+
| `getBot()` | Returns the underlying grammY `Bot` instance |
|
|
73
|
+
|
|
74
|
+
## Conversations Plugin
|
|
75
|
+
|
|
76
|
+
For imperative multi-step conversation flows:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { conversationsPlugin, defineConversation } from "@teactjs/telegram";
|
|
80
|
+
|
|
81
|
+
defineConversation("onboarding", async (convo) => {
|
|
82
|
+
const name = await convo.prompt("What's your name?");
|
|
83
|
+
await convo.send(`Welcome, ${name}!`);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const bot = createBot({
|
|
87
|
+
plugins: [conversationsPlugin()],
|
|
88
|
+
// ...
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The `Conversation` object provides: `prompt`, `send`, `wait`, `ask`, `stream`, `replyWith*` methods, `requestContact`, `requestLocation`, and access to `chatId`, `api`, `chat`, `raw`.
|
|
93
|
+
|
|
94
|
+
## Stream Plugin
|
|
95
|
+
|
|
96
|
+
Enables streaming text updates (used with `useStream` in the runtime):
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { streamPlugin } from "@teactjs/telegram";
|
|
100
|
+
|
|
101
|
+
const bot = createBot({
|
|
102
|
+
plugins: [streamPlugin()],
|
|
103
|
+
// ...
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## See Also
|
|
108
|
+
|
|
109
|
+
- [`@teactjs/core`](../core) for the barrel import
|
|
110
|
+
- [`@teactjs/runtime`](../runtime) for bot engine docs
|
|
111
|
+
- [grammY documentation](https://grammy.dev)
|