@leitwerk-dev/telegram 0.1.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.
- package/README.md +145 -0
- package/dist/LICENSE +13 -0
- package/dist/actions.d.ts +9 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +32 -0
- package/dist/actions.js.map +1 -0
- package/dist/bridge.d.ts +132 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +2032 -0
- package/dist/bridge.js.map +1 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +70 -0
- package/dist/config.js.map +1 -0
- package/dist/fake-telegram-client.d.ts +82 -0
- package/dist/fake-telegram-client.d.ts.map +1 -0
- package/dist/fake-telegram-client.js +107 -0
- package/dist/fake-telegram-client.js.map +1 -0
- package/dist/form-session.d.ts +143 -0
- package/dist/form-session.d.ts.map +1 -0
- package/dist/form-session.js +218 -0
- package/dist/form-session.js.map +1 -0
- package/dist/grammy-telegram-client.d.ts +131 -0
- package/dist/grammy-telegram-client.d.ts.map +1 -0
- package/dist/grammy-telegram-client.js +151 -0
- package/dist/grammy-telegram-client.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/launch-session.d.ts +103 -0
- package/dist/launch-session.d.ts.map +1 -0
- package/dist/launch-session.js +435 -0
- package/dist/launch-session.js.map +1 -0
- package/dist/markdown-html.d.ts +29 -0
- package/dist/markdown-html.d.ts.map +1 -0
- package/dist/markdown-html.js +259 -0
- package/dist/markdown-html.js.map +1 -0
- package/dist/mermaid-image.d.ts +2 -0
- package/dist/mermaid-image.d.ts.map +1 -0
- package/dist/mermaid-image.js +99 -0
- package/dist/mermaid-image.js.map +1 -0
- package/dist/process-feed.d.ts +58 -0
- package/dist/process-feed.d.ts.map +1 -0
- package/dist/process-feed.js +165 -0
- package/dist/process-feed.js.map +1 -0
- package/dist/process-thread-store.d.ts +18 -0
- package/dist/process-thread-store.d.ts.map +1 -0
- package/dist/process-thread-store.js +74 -0
- package/dist/process-thread-store.js.map +1 -0
- package/dist/topic-title.d.ts +7 -0
- package/dist/topic-title.d.ts.map +1 -0
- package/dist/topic-title.js +29 -0
- package/dist/topic-title.js.map +1 -0
- package/dist/types.d.ts +118 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
- package/src/actions.ts +41 -0
- package/src/bridge.ts +2870 -0
- package/src/config.ts +108 -0
- package/src/fake-telegram-client.ts +167 -0
- package/src/form-session.ts +359 -0
- package/src/grammy-telegram-client.ts +292 -0
- package/src/index.ts +68 -0
- package/src/launch-session.ts +620 -0
- package/src/markdown-html.ts +297 -0
- package/src/mermaid-image.ts +99 -0
- package/src/process-feed.ts +237 -0
- package/src/process-thread-store.ts +98 -0
- package/src/topic-title.ts +35 -0
- package/src/types.ts +138 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Telegram extension
|
|
2
|
+
|
|
3
|
+
Server-side extension that exposes leitwerk processes through a Telegram bot.
|
|
4
|
+
|
|
5
|
+
## Phase 1 behavior
|
|
6
|
+
|
|
7
|
+
- One bot per leitwerk instance.
|
|
8
|
+
- One private Telegram supergroup with forum topics enabled.
|
|
9
|
+
- One forum topic per process; completed and aborted process topics are closed.
|
|
10
|
+
- Operators can create a new forum topic, see launch help from the bot, send `/launch`, fill out launcher fields in Telegram, and have that topic become the process topic.
|
|
11
|
+
- Condensed process feed: process creation, submitted action summaries, turn starts, turn outcome/leaf results, lifecycle changes, errors, and action prompts.
|
|
12
|
+
- User actions through inline buttons and short form prompts. Optional action form fields include a `Skip` button.
|
|
13
|
+
- Free-text messages in a process topic are queued to that process.
|
|
14
|
+
- Retry recovery controls appear only when the process has a failed turn record; Continue appears only for failed LLM turns with saved continuation recovery context. Close a process topic to abort its process.
|
|
15
|
+
- Reasoning details, raw Pi diagnostics, usage, and costs are intentionally hidden.
|
|
16
|
+
|
|
17
|
+
## Telegram setup
|
|
18
|
+
|
|
19
|
+
Do these steps in Telegram before enabling the leitwerk extension:
|
|
20
|
+
|
|
21
|
+
1. Open `@BotFather`, run `/newbot`, choose a name and username, and copy the bot token.
|
|
22
|
+
2. Keep the token private. Prefer `bot_token_env` for shared config; use `bot_token` only when you intentionally want the token in `leitwerk.yaml`.
|
|
23
|
+
3. Create a private group for leitwerk notifications. Telegram forum topics require a supergroup; enable **Topics** in the group settings so it becomes a forum-enabled supergroup.
|
|
24
|
+
4. Add the bot to the group.
|
|
25
|
+
5. Promote the bot to admin with permission to:
|
|
26
|
+
- send messages,
|
|
27
|
+
- create topics,
|
|
28
|
+
- edit/manage topics.
|
|
29
|
+
6. Send a test message in the group after adding the bot. This makes the chat visible in Bot API updates while you collect the group chat id.
|
|
30
|
+
7. Get your Telegram user id and the group chat id before enabling the extension. The bot enforces the allowlist from startup and does not provide an unauthenticated ID-discovery command.
|
|
31
|
+
|
|
32
|
+
### Finding Telegram IDs
|
|
33
|
+
|
|
34
|
+
Common options:
|
|
35
|
+
|
|
36
|
+
- Send a direct message to a trusted Telegram ID helper bot (for example `@userinfobot`) to learn your numeric user id.
|
|
37
|
+
- To find the private supergroup chat id, temporarily add your leitwerk bot to the group, send a message in the group, then inspect Bot API updates while the leitwerk is not polling:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Use the `message.chat.id` value for `delivery.forum_chat_id`; supergroup ids typically start with `-100`.
|
|
44
|
+
|
|
45
|
+
Remove any temporary helper bots after setup and keep the bot token private.
|
|
46
|
+
|
|
47
|
+
## Leitwerk setup
|
|
48
|
+
|
|
49
|
+
1. Add the extension path to `extension_loading.sources`.
|
|
50
|
+
2. Provide the bot token through either:
|
|
51
|
+
- `bot_token_env`, with the token stored in an environment variable, for example:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
export TELEGRAM_BOT_TOKEN="123456:bot-token"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- `bot_token`, with the token written directly in `leitwerk.yaml`.
|
|
58
|
+
|
|
59
|
+
3. Add your numeric Telegram user ids to `allow_user_ids`.
|
|
60
|
+
4. Set `delivery.forum_chat_id` to the private forum-enabled supergroup id.
|
|
61
|
+
5. Restart the leitwerk so the server extension loader starts the bot.
|
|
62
|
+
6. Create or launch a process; the bot should create a forum topic for that process.
|
|
63
|
+
|
|
64
|
+
If startup fails with an invalid Telegram config error, verify that the token is configured, the token environment variable is visible to the leitwerk process when using `bot_token_env`, the allowlist is non-empty, and the forum chat id is set.
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
Load this extension explicitly through `extension_loading.sources`, then configure it under `extensions.telegram`:
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
extension_loading:
|
|
72
|
+
sources:
|
|
73
|
+
- ./extensions/telegram
|
|
74
|
+
|
|
75
|
+
extensions:
|
|
76
|
+
telegram:
|
|
77
|
+
enabled: true
|
|
78
|
+
bot_token_env: TELEGRAM_BOT_TOKEN
|
|
79
|
+
# bot_token: "123456:bot-token" # Optional inline YAML fallback when bot_token_env is unset.
|
|
80
|
+
allow_user_ids:
|
|
81
|
+
- 123456789
|
|
82
|
+
delivery:
|
|
83
|
+
forum_chat_id: "-1001234567890"
|
|
84
|
+
markdown:
|
|
85
|
+
max_chars: 3900
|
|
86
|
+
topic_title_template: "{title} · {shortId}"
|
|
87
|
+
# Optional: opt out of per-action model selection
|
|
88
|
+
# action_model_selection:
|
|
89
|
+
# enabled: false
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Prefer `bot_token_env` over a literal `bot_token` for shared config. If both are set, the environment variable value is used when present; otherwise the literal `bot_token` is used as a fallback.
|
|
93
|
+
|
|
94
|
+
## Commands
|
|
95
|
+
|
|
96
|
+
In an unmapped forum topic:
|
|
97
|
+
|
|
98
|
+
- `/launch` — choose from available launchers and start a launch wizard.
|
|
99
|
+
- `/launch <launcherId>` — start a known launcher directly.
|
|
100
|
+
- `/launchers` — list launcher ids and descriptions.
|
|
101
|
+
- `/cancel` — cancel the pending launch draft.
|
|
102
|
+
- `/help` — show launch help.
|
|
103
|
+
|
|
104
|
+
In a process topic:
|
|
105
|
+
|
|
106
|
+
- `/actions` — show current actions and recovery controls.
|
|
107
|
+
- `/status` — show compact process status.
|
|
108
|
+
- `/cancel` — cancel a pending action/continue prompt.
|
|
109
|
+
- `/skip` — skip the current optional action form field or continue with the default recovery prompt when available.
|
|
110
|
+
- `/help` — show topic help.
|
|
111
|
+
|
|
112
|
+
Close a mapped process topic to abort that process. The bot closes topics automatically when processes complete or abort.
|
|
113
|
+
|
|
114
|
+
Launch wizard prompts use Telegram-native controls where available: inline buttons for launcher choices, remembered recent values, select fields, boolean fields, skip/default choices, model setup, and final confirmation; force-reply prompts for required free-text and numeric fields. Required fields are asked first, then optional fields. Send `/skip` to keep a default value or skip an optional field. When a launcher has editable LLM model configuration, the final review includes a compact model summary and a **Change models** button. The model wizard lets operators choose a default model and per-turn overrides by button, number, or exact profile id; `/skip` keeps the current value and **Inherit** clears an override. Action form prompts also show a `Skip` button for optional fields. Successful launcher submissions update remembered values for future Telegram launches.
|
|
115
|
+
|
|
116
|
+
## Per-action model selection
|
|
117
|
+
|
|
118
|
+
When enabled (the default), the bot asks the operator to choose a next-turn model before executing any visible process action whose action plan selects an LLM turn. Action form fields are collected first, then the bot prompts with available model profiles and the resolved default model. When the operator's actual choice for a warm continuation (the previous turn ended within 30 minutes) would switch the underlying provider/model, the bot marks that choice with ⚠ and sends a cache-loss warning before executing the action. Thinking-level-only profile changes do not warn, root starts never warn, and the warning recommends the previous or an equivalent selectable profile when one is available. The operator can:
|
|
119
|
+
|
|
120
|
+
- pick a model by inline button, number, or exact profile id
|
|
121
|
+
- send `/skip` to keep the default/resolved model without an override
|
|
122
|
+
- send `/cancel` to discard
|
|
123
|
+
|
|
124
|
+
This only applies to actions that select an LLM turn. Non-LLM, unavailable-preview, and no-profile actions execute directly. Opt out with `action_model_selection.enabled: false`.
|
|
125
|
+
|
|
126
|
+
## Rendering
|
|
127
|
+
|
|
128
|
+
The extension receives leitwerk Markdown and sends Telegram messages with `HTML` parse mode. Unsupported Markdown degrades to escaped plain text. Messages longer than the configured Telegram message length are split into multiple ordered messages instead of being truncated.
|
|
129
|
+
|
|
130
|
+
Managed result images that belong to the published process turn are uploaded directly to Telegram; authenticated image URLs are never exposed to Telegram for fetching. Managed image references and Mermaid fences must be top-level Markdown blocks to become Telegram media. The extension sends those media blocks between ordinary rendered Markdown blocks; inline or list-nested image references remain escaped alt text. Each text section uses the normal message-length splitting. If Telegram rejects an image as a photo, the bot retries it as a document. Fenced Mermaid diagrams are rendered locally to PNG without a browser and uploaded as photos. Unsupported or invalid Mermaid syntax degrades to escaped diagram source. The Web UI and Telegram share the same lightweight Mermaid implementation, supporting flowcharts, state, sequence, class, ER, and XY diagrams.
|
|
131
|
+
|
|
132
|
+
For action-driven automatic work, the expected topic sequence is: submitted action summary (including entered form values), started turn, result markdown/log output when the turn finishes, then the next action prompt. Server-automatic turn results are posted from turn outcome markdown even when no leaf outcome snapshot is captured.
|
|
133
|
+
|
|
134
|
+
Opted-in LLM turns deliver durable operator questions to their process topic, including watcher- and scheduler-launched processes. Telegram shows the prepared options as guidance and collects one free-text reply per question; operators who want structured single- or multiple-selection controls can use the Web UI. The first valid Web or Telegram submission resumes the same active turn. Telegram rebuilds unanswered prompts from durable requests after restart and does not impose a question timeout.
|
|
135
|
+
|
|
136
|
+
## Reliability
|
|
137
|
+
|
|
138
|
+
Phase 1 delivery is best-effort:
|
|
139
|
+
|
|
140
|
+
- no replay of events missed while the bot is down,
|
|
141
|
+
- no exactly-once delivery guarantees,
|
|
142
|
+
- no message editing/deletion,
|
|
143
|
+
- pending form prompts are in memory and are lost on restart.
|
|
144
|
+
|
|
145
|
+
The process-to-topic mapping is persisted as extension-owned process events so replies keep routing after restart.
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Leitwerk contributors.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ProcessInstance } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { ProcessActionSummaryLike } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import type { TelegramInlineKeyboard } from "./types.js";
|
|
4
|
+
export declare function continuableFailedTurnRecordId(process: ProcessInstance): string | null;
|
|
5
|
+
export declare function buildActionKeyboard(input: {
|
|
6
|
+
process: ProcessInstance;
|
|
7
|
+
actions: readonly ProcessActionSummaryLike[];
|
|
8
|
+
}): TelegramInlineKeyboard | undefined;
|
|
9
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAiC,MAAM,sBAAsB,CAAC;AAC3F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAazD,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,CAQrF;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IAC1C,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,SAAS,wBAAwB,EAAE,CAAC;CAC7C,GAAG,sBAAsB,GAAG,SAAS,CAYrC"}
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { readFailedTurnRecoveryContext } from "@leitwerk-dev/domain";
|
|
2
|
+
const CALLBACKS = {
|
|
3
|
+
retry: "r",
|
|
4
|
+
continue: "c",
|
|
5
|
+
};
|
|
6
|
+
function rows(items, size) {
|
|
7
|
+
return Array.from({ length: Math.ceil(items.length / size) }, (_, index) => [
|
|
8
|
+
...items.slice(index * size, index * size + size),
|
|
9
|
+
]);
|
|
10
|
+
}
|
|
11
|
+
export function continuableFailedTurnRecordId(process) {
|
|
12
|
+
const turnRecordId = process.lifecycleStatus === "error" && process.currentExecution?.kind === "server_turn"
|
|
13
|
+
? process.currentExecution.id
|
|
14
|
+
: null;
|
|
15
|
+
return turnRecordId && readFailedTurnRecoveryContext(process.metadata, turnRecordId)
|
|
16
|
+
? turnRecordId
|
|
17
|
+
: null;
|
|
18
|
+
}
|
|
19
|
+
export function buildActionKeyboard(input) {
|
|
20
|
+
const buttons = input.actions.map((action) => ({
|
|
21
|
+
text: action.label,
|
|
22
|
+
callbackData: `a:${input.process.id}:${action.id}`,
|
|
23
|
+
}));
|
|
24
|
+
if (input.process.lifecycleStatus === "error" && input.process.currentExecution) {
|
|
25
|
+
buttons.push({ text: "Retry", callbackData: `${CALLBACKS.retry}:${input.process.id}` });
|
|
26
|
+
if (continuableFailedTurnRecordId(input.process)) {
|
|
27
|
+
buttons.push({ text: "Continue", callbackData: `${CALLBACKS.continue}:${input.process.id}` });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return buttons.length ? { inlineKeyboard: rows(buttons, 2) } : undefined;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=actions.js.map
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K,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACjF,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACxF,IAAI,6BAA6B,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAClD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/F,CAAC;IACF,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1E,CAAC"}
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { CoreServerSetupDeps, ServerExtensionEventMap, ServerExtensionLogger } from "@leitwerk-dev/process-sdk";
|
|
2
|
+
import type { TelegramExtensionConfig } from "./config.js";
|
|
3
|
+
import type { TelegramClient } from "./types.js";
|
|
4
|
+
export declare class TelegramBridge {
|
|
5
|
+
private readonly input;
|
|
6
|
+
private readonly store;
|
|
7
|
+
private readonly sessions;
|
|
8
|
+
private readonly launchSessions;
|
|
9
|
+
private readonly launchCallbacks;
|
|
10
|
+
private nextLaunchCallbackId;
|
|
11
|
+
private readonly processModelSelection;
|
|
12
|
+
private readonly threadEligibleInstanceIds;
|
|
13
|
+
private readonly introSentInstanceIds;
|
|
14
|
+
private readonly closedThreadKeys;
|
|
15
|
+
private readonly sentResultTurnRecordKeys;
|
|
16
|
+
private readonly deferredCompletedLifecycleProcesses;
|
|
17
|
+
private readonly queues;
|
|
18
|
+
private readonly lastTurnInfo;
|
|
19
|
+
constructor(input: {
|
|
20
|
+
config: TelegramExtensionConfig;
|
|
21
|
+
deps: CoreServerSetupDeps;
|
|
22
|
+
client: TelegramClient;
|
|
23
|
+
logger?: ServerExtensionLogger;
|
|
24
|
+
});
|
|
25
|
+
start(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* After a server restart the in-memory lastTurnInfo map is empty.
|
|
28
|
+
* Rebuild it from the most recent turn_started event for every non-terminal
|
|
29
|
+
* process that already has a Telegram thread, so that /status and actions
|
|
30
|
+
* prompts show the correct path label without waiting for the next turn.
|
|
31
|
+
*/
|
|
32
|
+
private seedLastTurnInfoFromEvents;
|
|
33
|
+
stop(): Promise<void>;
|
|
34
|
+
register(events: {
|
|
35
|
+
on<K extends keyof ServerExtensionEventMap & string>(event: K, handler: (payload: ServerExtensionEventMap[K]) => void | Promise<void>): void;
|
|
36
|
+
}): void;
|
|
37
|
+
private enqueue;
|
|
38
|
+
private onProcessCreated;
|
|
39
|
+
private onProcessUpdated;
|
|
40
|
+
private onTurnStarted;
|
|
41
|
+
private onQuestionRequested;
|
|
42
|
+
private resolveTurnModelLabel;
|
|
43
|
+
private filterProfiles;
|
|
44
|
+
private listSelectableProfiles;
|
|
45
|
+
private filterLaunchSchemaAvailableProfiles;
|
|
46
|
+
private onTurnFailed;
|
|
47
|
+
private sendPublishedResult;
|
|
48
|
+
private onLeafOutcome;
|
|
49
|
+
private onTurnOutcome;
|
|
50
|
+
private ensureThread;
|
|
51
|
+
private getThread;
|
|
52
|
+
private sendProcessIntro;
|
|
53
|
+
private closeThread;
|
|
54
|
+
private syncThreadTitle;
|
|
55
|
+
private sendActionsForProcess;
|
|
56
|
+
private handleForumTopicCreated;
|
|
57
|
+
private handleForumTopicClosed;
|
|
58
|
+
private abortProcessForClosedTopic;
|
|
59
|
+
private handleText;
|
|
60
|
+
private handleUnmappedTopicText;
|
|
61
|
+
private handleProcessText;
|
|
62
|
+
private handleCallback;
|
|
63
|
+
private resolveCallbackInstance;
|
|
64
|
+
private answerCallback;
|
|
65
|
+
private getLauncher;
|
|
66
|
+
private sendUnmappedTopicHelp;
|
|
67
|
+
private sendLauncherList;
|
|
68
|
+
private startLaunchSession;
|
|
69
|
+
private handleLaunchSessionText;
|
|
70
|
+
private executeLaunchCallbackCommand;
|
|
71
|
+
private getLaunchModelSchema;
|
|
72
|
+
private getLaunchModelPreview;
|
|
73
|
+
private getActiveLaunchSession;
|
|
74
|
+
private getLaunchContext;
|
|
75
|
+
private sendLaunchReviewForSession;
|
|
76
|
+
private finishLaunchModelEditAndReview;
|
|
77
|
+
private startLaunchModelEdit;
|
|
78
|
+
private executeLaunchModelCallbackCommand;
|
|
79
|
+
private finishLaunchModelEdit;
|
|
80
|
+
private handleLaunchModelText;
|
|
81
|
+
private continueAfterLaunchModelResult;
|
|
82
|
+
private resolveLaunchRecentValues;
|
|
83
|
+
private recordLaunchRecentValuesBestEffort;
|
|
84
|
+
private resolveLaunchOptions;
|
|
85
|
+
private sendNextLaunchModelPrompt;
|
|
86
|
+
private sendNextLaunchPrompt;
|
|
87
|
+
private sendLaunchReview;
|
|
88
|
+
private prepareLaunchSession;
|
|
89
|
+
private executeLaunchSession;
|
|
90
|
+
private createLaunchCallbackCommand;
|
|
91
|
+
private readLaunchCallbackCommand;
|
|
92
|
+
private buildLauncherListKeyboard;
|
|
93
|
+
private buildLaunchConfirmationKeyboard;
|
|
94
|
+
private buildLaunchModelReplyMarkup;
|
|
95
|
+
private buildLaunchFieldReplyMarkup;
|
|
96
|
+
private formatRecentValueButtonText;
|
|
97
|
+
private buildActionFormFieldReplyMarkup;
|
|
98
|
+
private sendActionFormFieldPrompt;
|
|
99
|
+
private executeCallbackCommand;
|
|
100
|
+
private sendCurrentSessionPrompt;
|
|
101
|
+
private maybeSelectActionModel;
|
|
102
|
+
private resolveActionModelSession;
|
|
103
|
+
private executeActionModelSession;
|
|
104
|
+
private sendActionModelSwitchWarning;
|
|
105
|
+
private handleActionModelSelect;
|
|
106
|
+
private handleActionModelSkip;
|
|
107
|
+
private sendActionModelPrompt;
|
|
108
|
+
private buildActionModelReplyMarkup;
|
|
109
|
+
private applyActionFormStep;
|
|
110
|
+
private applyActionFormText;
|
|
111
|
+
private applyActionFormSkip;
|
|
112
|
+
private skipCurrentActionFormField;
|
|
113
|
+
private handleSessionText;
|
|
114
|
+
private handleActionModelText;
|
|
115
|
+
private maybeSelectRecoveryModel;
|
|
116
|
+
private handleRecoveryModelSelect;
|
|
117
|
+
private handleRecoveryModelSkip;
|
|
118
|
+
private handleRecoveryModelText;
|
|
119
|
+
private executeRecoveryModelSession;
|
|
120
|
+
private sendRecoveryModelPrompt;
|
|
121
|
+
private buildRecoveryModelReplyMarkup;
|
|
122
|
+
private executeProcessAction;
|
|
123
|
+
private sendCommandResult;
|
|
124
|
+
private isAllowed;
|
|
125
|
+
private sendHtml;
|
|
126
|
+
private sendResultParts;
|
|
127
|
+
private sendPhotoWithDocumentFallback;
|
|
128
|
+
private sendPlainToChat;
|
|
129
|
+
private sendHtmlToChat;
|
|
130
|
+
private logError;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACX,mBAAmB,EASnB,uBAAuB,EACvB,qBAAqB,EAErB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAuE3D,OAAO,KAAK,EAEX,cAAc,EAOd,MAAM,YAAY,CAAC;AAqRpB,qBAAa,cAAc;IAmBzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAlBvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6C;IACtE,OAAO,CAAC,QAAQ,CAAC,cAAc,CA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