Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/api/src/handlers/discord/__tests__/index.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apps/api/src/handlers/discord/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ async function processDiscordGatewayEvent(event: DiscordGatewayEvent) {
const metadata = discordMetadataForChannel({
channel,
messageId: event.payload.id,
// Only a real channel message provides an anchor for the task thread;
// interactions (slash commands, buttons) do not.
...(message?.id ? { anchorMessageId: message.id } : {}),
});

if (interaction?.type === 3) {
Expand Down
9 changes: 9 additions & 0 deletions apps/api/src/handlers/discord/task-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export async function resolveDiscordChannelContext(
export function discordMetadataForChannel(input: {
channel: DiscordChannelContext;
messageId: string;
/**
* The real channel message that triggered the event — set only for
* message events. Interactions have no message a task thread could
* anchor to, so launches from them keep detached threads.
*/
anchorMessageId?: string;
}): DiscordEventCommunicationMetadata {
return {
communicationProvider: 'discord',
Expand All @@ -78,6 +84,9 @@ export function discordMetadataForChannel(input: {
...(input.channel.guildId
? { communicationGuildId: input.channel.guildId }
: {}),
...(input.anchorMessageId
? { communicationAnchorMessageId: input.anchorMessageId }
: {}),
};
}

Expand Down
27 changes: 27 additions & 0 deletions packages/communication/src/__tests__/discord-event.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/communication/src/discord-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ export const discordInteractionSchema = z
.optional(),
data: z
.object({
id: z.string().optional(),
// Slash commands carry the command's snowflake here (a string);
// component interactions carry the numeric layout id of the pressed
// component. Real button clicks were rejected as invalid while the
// string-only shape was assumed.
id: z.union([z.string(), z.number()]).optional(),
name: z.string().optional(),
type: z.number().int().optional(),
options: z.array(discordInteractionOptionSchema).optional(),
Expand Down
Loading