fix(regression): preserve discord thread bindings for plugin commands

This commit is contained in:
Tak Hoffman
2026-03-27 19:48:18 -05:00
parent b1eeca3b00
commit b598cdf968
7 changed files with 108 additions and 1 deletions

View File

@@ -243,6 +243,24 @@ describe("registerPluginCommand", () => {
});
});
it("resolves Discord thread command bindings with parent channel context intact", () => {
expect(
__testing.resolveBindingConversationFromCommand({
channel: "discord",
from: "discord:channel:1480554272859881494",
accountId: "default",
messageThreadId: "thread-42",
threadParentId: "channel-parent-7",
}),
).toEqual({
channel: "discord",
accountId: "default",
conversationId: "channel:1480554272859881494",
parentConversationId: "channel-parent-7",
threadId: "thread-42",
});
});
it("resolves Telegram topic command bindings without a Telegram registry entry", () => {
expect(
__testing.resolveBindingConversationFromCommand({

View File

@@ -148,6 +148,7 @@ function resolveBindingConversationFromCommand(params: {
to?: string;
accountId?: string;
messageThreadId?: string | number;
threadParentId?: string;
}): {
channel: string;
accountId: string;
@@ -199,6 +200,8 @@ function resolveBindingConversationFromCommand(params: {
"conversationId" in target
? target.conversationId
: `${target.chatType === "direct" ? "user" : "channel"}:${target.to}`,
parentConversationId: params.threadParentId?.trim() || undefined,
threadId: params.messageThreadId,
};
}
return null;
@@ -224,6 +227,7 @@ export async function executePluginCommand(params: {
to?: PluginCommandContext["to"];
accountId?: PluginCommandContext["accountId"];
messageThreadId?: PluginCommandContext["messageThreadId"];
threadParentId?: PluginCommandContext["threadParentId"];
}): Promise<PluginCommandResult> {
const { command, args, senderId, channel, isAuthorizedSender, commandBody, config } = params;
@@ -244,6 +248,7 @@ export async function executePluginCommand(params: {
to: params.to,
accountId: params.accountId,
messageThreadId: params.messageThreadId,
threadParentId: params.threadParentId,
});
const ctx: PluginCommandContext = {
@@ -259,6 +264,7 @@ export async function executePluginCommand(params: {
to: params.to,
accountId: params.accountId,
messageThreadId: params.messageThreadId,
threadParentId: params.threadParentId,
requestConversationBinding: async (bindingParams) => {
if (!command.pluginRoot || !bindingConversation) {
return {

View File

@@ -1178,6 +1178,8 @@ export type PluginCommandContext = {
accountId?: string;
/** Thread/topic id if available */
messageThreadId?: string | number;
/** Parent conversation id for thread-capable channels */
threadParentId?: string;
requestConversationBinding: (
params?: PluginConversationBindingRequestParams,
) => Promise<PluginConversationBindingRequestResult>;