fix(#709): route Discord threads and approvals
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful

This commit is contained in:
Jarvis
2026-07-13 00:48:53 -05:00
parent 25ed367655
commit 689d5b6870
2 changed files with 33 additions and 3 deletions

View File

@@ -639,9 +639,36 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
* Creates it if absent — safe to call concurrently since a duplicate insert
* would fail on the PK constraint and be caught here.
*/
@SubscribeMessage('discord:approve')
async handleDiscordApproval(
@ConnectedSocket() client: Socket,
@MessageBody() envelope: DiscordIngressEnvelope,
): Promise<void> {
if (!client.data.discordService) return;
const ingress = this.resolveDiscordIngress(client, envelope, 'approve');
const command = ingress?.content.match(/^\/approve\s+([a-z][\w-]*)$/i)?.[1];
const serviceUserId = process.env['DISCORD_SERVICE_USER_ID'];
if (!ingress || !command || !serviceUserId) return;
const approval = await this.commandExecutor.createApproval(
{ command, conversationId: ingress.conversationId },
{
userId: serviceUserId,
tenantId: process.env['DISCORD_SERVICE_TENANT_ID'] ?? serviceUserId,
},
);
client.emit('discord:approval', {
correlationId: ingress.correlationId,
command,
success: approval !== null,
approvalId: approval?.approvalId,
expiresAt: approval?.expiresAt,
});
}
private resolveDiscordIngress(
client: Socket,
envelope: DiscordIngressEnvelope,
operation: 'send' | 'approve' = 'send',
): DiscordIngressPayload | null {
const payload = verifyDiscordIngressEnvelope(
envelope,
@@ -662,7 +689,7 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
payload.guildId,
payload.channelId,
payload.userId,
'send',
operation,
);
if (!binding) {
this.logger.warn(`Rejected unpaired Discord ingress from ${client.id}`);