refactor(plugins): single-source interactive dispatch and its auth downgrade via plugin SDK (#120062)

This commit is contained in:
Peter Steinberger
2026-08-06 16:31:04 -07:00
committed by GitHub
parent d64f5b6a09
commit 0b849a316d
10 changed files with 377 additions and 371 deletions
+15 -66
View File
@@ -1,7 +1,6 @@
// Telegram plugin module implements interactive dispatch behavior.
import {
createInteractiveConversationBindingHelpers,
dispatchPluginInteractiveHandler,
createChannelInteractiveDispatcher,
type PluginConversationBinding,
type PluginConversationBindingRequestParams,
type PluginConversationBindingRequestResult,
@@ -63,78 +62,28 @@ export type TelegramInteractiveHandlerRegistration = PluginInteractiveRegistrati
TelegramInteractiveHandlerResult
>;
type TelegramInteractiveDispatchContext = Omit<
const dispatchTelegramInteractive = createChannelInteractiveDispatcher<
"telegram",
"callback",
TelegramInteractiveHandlerContext,
| "callback"
| "respond"
| "channel"
| "requestConversationBinding"
| "detachConversationBinding"
| "getCurrentConversationBinding"
> & {
callbackMessage: {
messageId: number;
chatId: string;
messageText?: string;
};
};
TelegramInteractiveHandlerResult,
"callbackMessage"
>({
channel: "telegram",
interactiveKey: "callback",
dispatchInteractiveKey: "callbackMessage",
});
export async function dispatchTelegramPluginInteractiveHandler(params: {
data: string;
callbackId: string;
ctx: TelegramInteractiveDispatchContext;
respond: {
reply: (params: { text: string; buttons?: TelegramInteractiveButtons }) => Promise<void>;
editMessage: (params: { text: string; buttons?: TelegramInteractiveButtons }) => Promise<void>;
editButtons: (params: { buttons: TelegramInteractiveButtons }) => Promise<void>;
clearButtons: () => Promise<void>;
deleteMessage: () => Promise<void>;
};
ctx: Parameters<typeof dispatchTelegramInteractive>[0]["ctx"];
respond: TelegramInteractiveHandlerContext["respond"];
onMatched?: () => Promise<void> | void;
afterInvoke?: (result: TelegramInteractiveHandlerResult) => Promise<void> | void;
}) {
return await dispatchPluginInteractiveHandler<
TelegramInteractiveHandlerRegistration,
TelegramInteractiveHandlerResult
>({
channel: "telegram",
data: params.data,
return await dispatchTelegramInteractive({
...params,
dedupeId: params.callbackId,
onMatched: params.onMatched,
afterInvoke: params.afterInvoke,
invoke: ({ registration, namespace, payload }) => {
const { callbackMessage, ...handlerContext } = params.ctx;
return registration.handler({
...handlerContext,
channel: "telegram",
callback: {
data: params.data,
namespace,
payload,
messageId: callbackMessage.messageId,
chatId: callbackMessage.chatId,
messageText: callbackMessage.messageText,
},
respond: params.respond,
...createInteractiveConversationBindingHelpers({
// Untrusted callbacks may reach their plugin, but never inherit conversation-binding authority.
registration:
handlerContext.auth?.isAuthorizedSender &&
handlerContext.senderId?.trim() &&
handlerContext.accountId?.trim() &&
handlerContext.conversationId?.trim()
? registration
: { ...registration, pluginRoot: undefined },
senderId: handlerContext.senderId,
conversation: {
channel: "telegram",
accountId: handlerContext.accountId,
conversationId: handlerContext.conversationId,
parentConversationId: handlerContext.parentConversationId,
threadId: handlerContext.threadId,
},
}),
});
},
});
}