Skip to content

Commit c26f773

Browse files
committed
fix(triggers): address PR review feedback for Intercom triggers
1 parent c9a1e21 commit c26f773

File tree

1 file changed

+20
-50
lines changed

1 file changed

+20
-50
lines changed

apps/sim/triggers/intercom/utils.ts

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,17 @@ export const INTERCOM_TRIGGER_TOPIC_MAP: Record<string, string[]> = {
7272
*/
7373
export function isIntercomEventMatch(triggerId: string, topic: string): boolean {
7474
const allowedTopics = INTERCOM_TRIGGER_TOPIC_MAP[triggerId]
75-
if (!allowedTopics || allowedTopics.length === 0) {
75+
if (allowedTopics === undefined) return false
76+
if (allowedTopics.length === 0) {
7677
return true
7778
}
7879
return allowedTopics.includes(topic)
7980
}
8081

8182
/**
82-
* Build outputs for Intercom conversation triggers.
83+
* Shared base outputs for all Intercom webhook triggers.
8384
*/
84-
export function buildIntercomConversationOutputs(): Record<string, TriggerOutput> {
85+
function buildIntercomBaseOutputs(dataDescription: string): Record<string, TriggerOutput> {
8586
return {
8687
topic: { type: 'string', description: 'The webhook topic (e.g., conversation.user.created)' },
8788
id: { type: 'string', description: 'Unique notification ID' },
@@ -95,64 +96,33 @@ export function buildIntercomConversationOutputs(): Record<string, TriggerOutput
9596
type: 'number',
9697
description: 'Unix timestamp of first delivery attempt',
9798
},
98-
data: {
99-
type: 'json',
100-
description:
101-
'Event data containing the conversation object. Access via data.item for conversation details including id, state, open, assignee, contacts, conversation_parts, tags, and source',
102-
},
99+
data: { type: 'json', description: dataDescription },
103100
} as Record<string, TriggerOutput>
104101
}
105102

103+
/**
104+
* Build outputs for Intercom conversation triggers.
105+
*/
106+
export function buildIntercomConversationOutputs(): Record<string, TriggerOutput> {
107+
return buildIntercomBaseOutputs(
108+
'Event data containing the conversation object. Access via data.item for conversation details including id, state, open, assignee, contacts, conversation_parts, tags, and source'
109+
)
110+
}
111+
106112
/**
107113
* Build outputs for Intercom contact triggers.
108114
*/
109115
export function buildIntercomContactOutputs(): Record<string, TriggerOutput> {
110-
return {
111-
topic: { type: 'string', description: 'The webhook topic (e.g., contact.created)' },
112-
id: { type: 'string', description: 'Unique notification ID' },
113-
app_id: { type: 'string', description: 'Your Intercom app ID' },
114-
created_at: { type: 'number', description: 'Unix timestamp when the event occurred' },
115-
delivery_attempts: {
116-
type: 'number',
117-
description: 'Number of delivery attempts for this notification',
118-
},
119-
first_sent_at: {
120-
type: 'number',
121-
description: 'Unix timestamp of first delivery attempt',
122-
},
123-
data: {
124-
type: 'json',
125-
description:
126-
'Event data containing the contact object. Access via data.item for contact details including id, role, email, name, phone, external_id, custom_attributes, location, avatar, tags, companies, and timestamps',
127-
},
128-
} as Record<string, TriggerOutput>
116+
return buildIntercomBaseOutputs(
117+
'Event data containing the contact object. Access via data.item for contact details including id, role, email, name, phone, external_id, custom_attributes, location, avatar, tags, companies, and timestamps'
118+
)
129119
}
130120

131121
/**
132122
* Build outputs for the generic Intercom webhook trigger.
133123
*/
134124
export function buildIntercomGenericOutputs(): Record<string, TriggerOutput> {
135-
return {
136-
topic: {
137-
type: 'string',
138-
description:
139-
'The webhook topic (e.g., conversation.user.created, contact.created, company.created, ticket.created)',
140-
},
141-
id: { type: 'string', description: 'Unique notification ID' },
142-
app_id: { type: 'string', description: 'Your Intercom app ID' },
143-
created_at: { type: 'number', description: 'Unix timestamp when the event occurred' },
144-
delivery_attempts: {
145-
type: 'number',
146-
description: 'Number of delivery attempts for this notification',
147-
},
148-
first_sent_at: {
149-
type: 'number',
150-
description: 'Unix timestamp of first delivery attempt',
151-
},
152-
data: {
153-
type: 'json',
154-
description:
155-
'Event data containing the affected object. Access via data.item for the resource (conversation, contact, company, ticket, etc.)',
156-
},
157-
} as Record<string, TriggerOutput>
125+
return buildIntercomBaseOutputs(
126+
'Event data containing the affected object. Access via data.item for the resource (conversation, contact, company, ticket, etc.)'
127+
)
158128
}

0 commit comments

Comments
 (0)