@llblab/pi-telegram 0.9.8 → 0.10.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/AGENTS.md +19 -2
- package/BACKLOG.md +0 -2
- package/CHANGELOG.md +26 -1
- package/README.md +8 -3
- package/docs/README.md +1 -1
- package/docs/callback-namespaces.md +1 -1
- package/docs/extension-sections.md +269 -164
- package/index.ts +31 -12
- package/lib/api.ts +23 -5
- package/lib/commands.ts +0 -36
- package/lib/extension-sections.ts +627 -0
- package/lib/menu-model.ts +1 -1
- package/lib/menu-settings.ts +68 -33
- package/lib/menu-status.ts +18 -0
- package/lib/menu.ts +130 -1
- package/lib/queue.ts +9 -2
- package/lib/replies.ts +28 -0
- package/lib/routing.ts +63 -16
- package/package.json +2 -2
package/index.ts
CHANGED
|
@@ -8,6 +8,11 @@ import * as Api from "./lib/api.ts";
|
|
|
8
8
|
import * as CommandTemplates from "./lib/command-templates.ts";
|
|
9
9
|
import * as Commands from "./lib/commands.ts";
|
|
10
10
|
import * as Config from "./lib/config.ts";
|
|
11
|
+
import {
|
|
12
|
+
createTelegramExtensionSectionRegistry,
|
|
13
|
+
setGlobalTelegramSectionRegistry,
|
|
14
|
+
type TelegramSectionRegistry,
|
|
15
|
+
} from "./lib/extension-sections.ts";
|
|
11
16
|
import { createTelegramExternalHandleUpdate } from "./lib/external-handlers.ts";
|
|
12
17
|
import * as InboundHandlers from "./lib/inbound-handlers.ts";
|
|
13
18
|
import * as Keyboard from "./lib/keyboard.ts";
|
|
@@ -69,6 +74,9 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
69
74
|
Model.ScopedTelegramModel<ActivePiModel>
|
|
70
75
|
>();
|
|
71
76
|
const modelMenuRuntime = Menu.createTelegramModelMenuRuntime<ActivePiModel>();
|
|
77
|
+
const sectionRegistry: TelegramSectionRegistry =
|
|
78
|
+
createTelegramExtensionSectionRegistry();
|
|
79
|
+
setGlobalTelegramSectionRegistry(sectionRegistry);
|
|
72
80
|
const runtimeEvents = Status.createTelegramRuntimeEventRecorder({
|
|
73
81
|
getBotToken: configStore.getBotToken,
|
|
74
82
|
});
|
|
@@ -157,6 +165,11 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
157
165
|
|
|
158
166
|
// --- Message Delivery & Preview ---
|
|
159
167
|
|
|
168
|
+
const sendGuestReply = Replies.createGuestMarkdownReplySender({
|
|
169
|
+
renderTelegramMessage: Replies.renderTelegramMessage,
|
|
170
|
+
answerGuestQuery,
|
|
171
|
+
});
|
|
172
|
+
|
|
160
173
|
const promptDispatchRuntime =
|
|
161
174
|
Runtime.createTelegramPromptDispatchRuntime<Pi.ExtensionContext>({
|
|
162
175
|
lifecycle,
|
|
@@ -272,6 +285,7 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
272
285
|
sendTextReply,
|
|
273
286
|
editInteractiveMessage,
|
|
274
287
|
sendInteractiveMessage,
|
|
288
|
+
sectionRegistry,
|
|
275
289
|
});
|
|
276
290
|
|
|
277
291
|
// --- Queue Menu ---
|
|
@@ -293,16 +307,19 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
293
307
|
updateStatusMessage: menuActions.updateStatusMessage,
|
|
294
308
|
updateStatus,
|
|
295
309
|
});
|
|
296
|
-
const settingsMenuRuntime = MenuSettings.createTelegramSettingsMenuRuntime(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
310
|
+
const settingsMenuRuntime = MenuSettings.createTelegramSettingsMenuRuntime(
|
|
311
|
+
{
|
|
312
|
+
getModelMenuState: getQueueMenuState,
|
|
313
|
+
getStoredModelMenuState: modelMenuRuntime.getState,
|
|
314
|
+
storeModelMenuState: modelMenuRuntime.storeState,
|
|
315
|
+
editInteractiveMessage,
|
|
316
|
+
sendInteractiveMessage,
|
|
317
|
+
answerCallbackQuery,
|
|
318
|
+
isProactivePushEnabled,
|
|
319
|
+
setProactivePushEnabled,
|
|
320
|
+
},
|
|
321
|
+
sectionRegistry,
|
|
322
|
+
);
|
|
306
323
|
|
|
307
324
|
// --- Polling ---
|
|
308
325
|
|
|
@@ -329,11 +346,14 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
329
346
|
queueMenuCallbackHandler: queueMenuRuntime.handleCallbackQuery,
|
|
330
347
|
openSettingsMenu: settingsMenuRuntime.openSettingsMenu,
|
|
331
348
|
settingsMenuCallbackHandler: settingsMenuRuntime.handleCallbackQuery,
|
|
349
|
+
sectionRegistry,
|
|
332
350
|
buttonActionStore,
|
|
333
351
|
inboundHandlerRuntime,
|
|
334
352
|
updateStatus,
|
|
335
353
|
dispatchNextQueuedTelegramTurn,
|
|
336
354
|
answerCallbackQuery,
|
|
355
|
+
editInteractiveMessage,
|
|
356
|
+
sendInteractiveMessage,
|
|
337
357
|
answerGuestQuery,
|
|
338
358
|
sendTextReply,
|
|
339
359
|
setMyCommands,
|
|
@@ -434,8 +454,6 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
434
454
|
startPolling: lockedPollingRuntime.start,
|
|
435
455
|
stopPolling: lockedPollingRuntime.stop,
|
|
436
456
|
updateStatus,
|
|
437
|
-
isProactivePushEnabled,
|
|
438
|
-
setProactivePushEnabled,
|
|
439
457
|
});
|
|
440
458
|
|
|
441
459
|
// --- Lifecycle Hooks ---
|
|
@@ -497,6 +515,7 @@ export default function (pi: Pi.ExtensionAPI) {
|
|
|
497
515
|
sendTextReply,
|
|
498
516
|
sendQueuedAttachments: queuedAttachmentSender,
|
|
499
517
|
answerGuestQuery,
|
|
518
|
+
sendGuestReply,
|
|
500
519
|
planOutboundReply: outboundReplyPlanner,
|
|
501
520
|
sendOutboundReplyArtifacts: outboundReplyArtifactSender,
|
|
502
521
|
isCurrentOwner: lockOwnershipGuard.ownsContext,
|
package/lib/api.ts
CHANGED
|
@@ -256,7 +256,11 @@ export interface TelegramApiClient {
|
|
|
256
256
|
callbackQueryId: string,
|
|
257
257
|
text?: string,
|
|
258
258
|
) => Promise<void>;
|
|
259
|
-
answerGuestQuery?: (
|
|
259
|
+
answerGuestQuery?: (
|
|
260
|
+
guestQueryId: string,
|
|
261
|
+
text?: string,
|
|
262
|
+
options?: { parseMode?: string },
|
|
263
|
+
) => Promise<void>;
|
|
260
264
|
}
|
|
261
265
|
|
|
262
266
|
export interface TelegramBridgeApiRuntimeDeps {
|
|
@@ -314,7 +318,11 @@ export interface TelegramBridgeApiRuntime {
|
|
|
314
318
|
callbackQueryId: string,
|
|
315
319
|
text?: string,
|
|
316
320
|
) => Promise<void>;
|
|
317
|
-
answerGuestQuery: (
|
|
321
|
+
answerGuestQuery: (
|
|
322
|
+
guestQueryId: string,
|
|
323
|
+
text?: string,
|
|
324
|
+
options?: { parseMode?: string },
|
|
325
|
+
) => Promise<void>;
|
|
318
326
|
prepareTempDir: () => Promise<number>;
|
|
319
327
|
}
|
|
320
328
|
|
|
@@ -785,14 +793,24 @@ export function createTelegramBridgeApiRuntime(
|
|
|
785
793
|
answerCallbackQuery: (callbackQueryId, text) => {
|
|
786
794
|
return deps.client.answerCallbackQuery(callbackQueryId, text);
|
|
787
795
|
},
|
|
788
|
-
answerGuestQuery: (
|
|
796
|
+
answerGuestQuery: (
|
|
797
|
+
guestQueryId: string,
|
|
798
|
+
text: string | undefined,
|
|
799
|
+
options: { parseMode?: string } | undefined,
|
|
800
|
+
) => {
|
|
789
801
|
const body: Record<string, unknown> = { guest_query_id: guestQueryId };
|
|
790
802
|
if (text !== undefined) {
|
|
803
|
+
const inputContent: Record<string, unknown> = {
|
|
804
|
+
message_text: text,
|
|
805
|
+
};
|
|
806
|
+
if (options?.parseMode) {
|
|
807
|
+
inputContent.parse_mode = options.parseMode;
|
|
808
|
+
}
|
|
791
809
|
body.result = {
|
|
792
810
|
type: "article",
|
|
793
811
|
id: "1",
|
|
794
|
-
title:
|
|
795
|
-
input_message_content:
|
|
812
|
+
title: "Response",
|
|
813
|
+
input_message_content: inputContent,
|
|
796
814
|
};
|
|
797
815
|
}
|
|
798
816
|
return callRecorded<void>("answerGuestQuery", body);
|
package/lib/commands.ts
CHANGED
|
@@ -135,10 +135,6 @@ export interface TelegramBridgeCommandStartPollingResult {
|
|
|
135
135
|
owner?: string;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
interface TelegramBridgeSettingsSelectUi {
|
|
139
|
-
select?: (title: string, items: string[]) => Promise<string | undefined>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
138
|
export interface TelegramBridgeCommandRegistrationDeps {
|
|
143
139
|
promptForConfig: (ctx: ExtensionCommandContext) => Promise<void>;
|
|
144
140
|
getStatusLines: () => string[];
|
|
@@ -153,8 +149,6 @@ export interface TelegramBridgeCommandRegistrationDeps {
|
|
|
153
149
|
| TelegramBridgeCommandStartPollingResult;
|
|
154
150
|
stopPolling: () => Promise<void | string>;
|
|
155
151
|
updateStatus: (ctx: ExtensionCommandContext) => void;
|
|
156
|
-
isProactivePushEnabled?: () => boolean;
|
|
157
|
-
setProactivePushEnabled?: (enabled: boolean) => Promise<void>;
|
|
158
152
|
}
|
|
159
153
|
|
|
160
154
|
function formatTelegramTakeoverTitle(ctx: ExtensionCommandContext): string {
|
|
@@ -189,36 +183,6 @@ export function registerTelegramBridgeCommands(
|
|
|
189
183
|
ctx.ui.notify(deps.getStatusLines().join("\n"), "info");
|
|
190
184
|
},
|
|
191
185
|
});
|
|
192
|
-
pi.registerCommand("telegram-settings", {
|
|
193
|
-
description: "Open Telegram bridge settings",
|
|
194
|
-
handler: async (_args, ctx) => {
|
|
195
|
-
if (!deps.isProactivePushEnabled || !deps.setProactivePushEnabled) {
|
|
196
|
-
ctx.ui.notify("Telegram settings are unavailable.", "warning");
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
await deps.reloadConfig();
|
|
200
|
-
const enabled = deps.isProactivePushEnabled();
|
|
201
|
-
const nextEnabled = !enabled;
|
|
202
|
-
const label = `${enabled ? "🟢" : "⚫️"} Proactive push`;
|
|
203
|
-
const action = `${nextEnabled ? "Enable" : "Disable"} proactive push`;
|
|
204
|
-
const select = (ctx.ui as TelegramBridgeSettingsSelectUi).select;
|
|
205
|
-
if (!select) {
|
|
206
|
-
ctx.ui.notify(
|
|
207
|
-
`${label}\n${action}: /telegram-settings requires interactive mode.`,
|
|
208
|
-
"info",
|
|
209
|
-
);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
const selected = await select("Telegram settings", [label, "Cancel"]);
|
|
213
|
-
if (selected !== label) return;
|
|
214
|
-
await deps.setProactivePushEnabled(nextEnabled);
|
|
215
|
-
deps.updateStatus(ctx);
|
|
216
|
-
ctx.ui.notify(
|
|
217
|
-
`Proactive push ${nextEnabled ? "enabled" : "disabled"}.`,
|
|
218
|
-
"info",
|
|
219
|
-
);
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
186
|
pi.registerCommand("telegram-connect", {
|
|
223
187
|
description: "Start the Telegram bridge in this π session",
|
|
224
188
|
handler: async (_args, ctx) => {
|