Skip to content

Commit d0ed86d

Browse files
fix(slack): default absent appType to custom at deploy; deactivate custom-bot webhooks on credential delete
- appType is hidden and seeded 'custom' by value(), which only covers editor-created blocks; defaultValue now persists it via buildProviderConfig and the deploy fallback flips to custom (the only exposed mode this ship) - deleting a slack-custom-bot credential now also deactivates provider='slack' webhooks routed by that credential id, not just native slack_app rows
1 parent d4ae64c commit d0ed86d

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

apps/sim/lib/credentials/deletion.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AuditAction, AuditResourceType, recordAudit } from '@sim/audit'
22
import { db } from '@sim/db'
33
import * as schema from '@sim/db/schema'
44
import { createLogger } from '@sim/logger'
5-
import { and, eq, sql } from 'drizzle-orm'
5+
import { and, eq, or, sql } from 'drizzle-orm'
66
import type { NextRequest } from 'next/server'
77
import { CREDENTIAL_SUBBLOCK_IDS } from '@/lib/workflows/persistence/utils'
88

@@ -95,20 +95,26 @@ export async function clearCredentialRefs(
9595
}
9696

9797
/**
98-
* Deactivates native Slack (`slack_app`) trigger webhooks bound to this
99-
* credential so inbound events stop routing once the account is disconnected.
100-
* The credential id lives in `providerConfig`, not a foreign key, so it is not
101-
* covered by CASCADE.
98+
* Deactivates Slack trigger webhooks bound to this credential so inbound
99+
* events stop routing once the account is disconnected: native (`slack_app`)
100+
* rows reference it via `providerConfig.credentialId`, custom-bot (`slack`)
101+
* rows via `routingKey` = the bot credential id. Neither is a foreign key, so
102+
* neither is covered by CASCADE.
102103
*/
103104
async function deactivateSlackAppWebhooks(credentialId: string): Promise<void> {
104105
await db
105106
.update(schema.webhook)
106107
.set({ isActive: false, updatedAt: new Date() })
107108
.where(
108109
and(
109-
eq(schema.webhook.provider, 'slack_app'),
110110
eq(schema.webhook.isActive, true),
111-
sql`${schema.webhook.providerConfig}->>'credentialId' = ${credentialId}`
111+
or(
112+
and(
113+
eq(schema.webhook.provider, 'slack_app'),
114+
sql`${schema.webhook.providerConfig}->>'credentialId' = ${credentialId}`
115+
),
116+
and(eq(schema.webhook.provider, 'slack'), eq(schema.webhook.routingKey, credentialId))
117+
)
112118
)
113119
)
114120
}

apps/sim/lib/webhooks/deploy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,10 @@ export async function saveTriggerWebhooksForDeploy({
430430
let effectivePath: string | null = triggerPath
431431
let routingKey: string | null = null
432432
if (triggerId === 'slack_oauth') {
433-
const appType = typeof providerConfig.appType === 'string' ? providerConfig.appType : 'sim'
433+
// Absent appType means custom: it's the only mode this ship exposes (the
434+
// hidden selector seeds/persists 'custom'), and defaulting to sim would
435+
// send credential-less configs down the OAuth/team-id branch.
436+
const appType = typeof providerConfig.appType === 'string' ? providerConfig.appType : 'custom'
434437
if (appType === 'sim') {
435438
const eventType =
436439
typeof providerConfig.eventType === 'string' ? providerConfig.eventType : null

apps/sim/triggers/slack/oauth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export const slackOAuthTrigger: TriggerConfig = {
7373
{ label: 'Custom', id: 'custom' },
7474
],
7575
value: () => 'custom',
76+
// `value()` only seeds editor-created blocks; `defaultValue` is what
77+
// buildProviderConfig persists when the stored value is absent
78+
// (imported / programmatically-created workflows).
79+
defaultValue: 'custom',
7680
description: 'Use the official Sim Slack app, or your own custom Slack app.',
7781
mode: 'trigger',
7882
},

0 commit comments

Comments
 (0)