@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.
Files changed (64) hide show
  1. package/README.md +111 -0
  2. package/dist/index.js +8263 -0
  3. package/dist/react/src/callback-registry.d.ts +11 -0
  4. package/dist/react/src/callback-registry.d.ts.map +1 -0
  5. package/dist/react/src/components.d.ts +396 -0
  6. package/dist/react/src/components.d.ts.map +1 -0
  7. package/dist/react/src/error-boundary.d.ts +19 -0
  8. package/dist/react/src/error-boundary.d.ts.map +1 -0
  9. package/dist/react/src/hooks.d.ts +37 -0
  10. package/dist/react/src/hooks.d.ts.map +1 -0
  11. package/dist/react/src/index.d.ts +11 -0
  12. package/dist/react/src/index.d.ts.map +1 -0
  13. package/dist/renderer/src/index.d.ts +5 -0
  14. package/dist/renderer/src/index.d.ts.map +1 -0
  15. package/dist/renderer/src/nodes.d.ts +23 -0
  16. package/dist/renderer/src/nodes.d.ts.map +1 -0
  17. package/dist/renderer/src/renderer.d.ts +9 -0
  18. package/dist/renderer/src/renderer.d.ts.map +1 -0
  19. package/dist/renderer/src/types.d.ts +36 -0
  20. package/dist/renderer/src/types.d.ts.map +1 -0
  21. package/dist/runtime/src/auth-session.d.ts +51 -0
  22. package/dist/runtime/src/auth-session.d.ts.map +1 -0
  23. package/dist/runtime/src/auth.d.ts +37 -0
  24. package/dist/runtime/src/auth.d.ts.map +1 -0
  25. package/dist/runtime/src/bot.d.ts +143 -0
  26. package/dist/runtime/src/bot.d.ts.map +1 -0
  27. package/dist/runtime/src/config.d.ts +38 -0
  28. package/dist/runtime/src/config.d.ts.map +1 -0
  29. package/dist/runtime/src/context.d.ts +74 -0
  30. package/dist/runtime/src/context.d.ts.map +1 -0
  31. package/dist/runtime/src/conversation.d.ts +310 -0
  32. package/dist/runtime/src/conversation.d.ts.map +1 -0
  33. package/dist/runtime/src/event-hooks.d.ts +49 -0
  34. package/dist/runtime/src/event-hooks.d.ts.map +1 -0
  35. package/dist/runtime/src/i18n.d.ts +55 -0
  36. package/dist/runtime/src/i18n.d.ts.map +1 -0
  37. package/dist/runtime/src/index.d.ts +28 -0
  38. package/dist/runtime/src/index.d.ts.map +1 -0
  39. package/dist/runtime/src/invoice.d.ts +120 -0
  40. package/dist/runtime/src/invoice.d.ts.map +1 -0
  41. package/dist/runtime/src/media-hooks.d.ts +178 -0
  42. package/dist/runtime/src/media-hooks.d.ts.map +1 -0
  43. package/dist/runtime/src/middleware.d.ts +26 -0
  44. package/dist/runtime/src/middleware.d.ts.map +1 -0
  45. package/dist/runtime/src/plugin.d.ts +32 -0
  46. package/dist/runtime/src/plugin.d.ts.map +1 -0
  47. package/dist/runtime/src/router.d.ts +168 -0
  48. package/dist/runtime/src/router.d.ts.map +1 -0
  49. package/dist/runtime/src/session.d.ts +20 -0
  50. package/dist/runtime/src/session.d.ts.map +1 -0
  51. package/dist/runtime/src/stream.d.ts +34 -0
  52. package/dist/runtime/src/stream.d.ts.map +1 -0
  53. package/dist/telegram/src/adapter.d.ts +83 -0
  54. package/dist/telegram/src/adapter.d.ts.map +1 -0
  55. package/dist/telegram/src/conversations.d.ts +175 -0
  56. package/dist/telegram/src/conversations.d.ts.map +1 -0
  57. package/dist/telegram/src/index.d.ts +8 -0
  58. package/dist/telegram/src/index.d.ts.map +1 -0
  59. package/dist/telegram/src/serialize.d.ts +80 -0
  60. package/dist/telegram/src/serialize.d.ts.map +1 -0
  61. package/dist/telegram/src/stream.d.ts +12 -0
  62. package/dist/telegram/src/stream.d.ts.map +1 -0
  63. package/package.json +38 -0
  64. 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)