(edit: {
entity_type: 'brand' | 'property';
domain: string;
editor_email?: string;
editor_name?: string;
edit_summary: string;
revision_number: number;
})
| 25 | * Returns the Slack message timestamp for threading. |
| 26 | */ |
| 27 | export async function notifyRegistryEdit(edit: { |
| 28 | entity_type: 'brand' | 'property'; |
| 29 | domain: string; |
| 30 | editor_email?: string; |
| 31 | editor_name?: string; |
| 32 | edit_summary: string; |
| 33 | revision_number: number; |
| 34 | }): Promise<string | null> { |
| 35 | const channelId = getChannelId(); |
| 36 | if (!channelId || !isSlackConfigured()) return null; |
| 37 | |
| 38 | const emoji = edit.entity_type === 'brand' ? '🏷️' : '🌐'; |
| 39 | const typeLabel = edit.entity_type === 'brand' ? 'Brand' : 'Property'; |
| 40 | const editorDisplay = edit.editor_name || edit.editor_email || 'Unknown'; |
| 41 | const viewUrl = edit.entity_type === 'brand' |
| 42 | ? `${APP_URL}/brand/view/${edit.domain}` |
| 43 | : `${APP_URL}/property/view/${edit.domain}`; |
| 44 | |
| 45 | const message: SlackBlockMessage = { |
| 46 | text: `${emoji} ${typeLabel} edited: ${edit.domain} by ${editorDisplay}`, |
| 47 | blocks: [ |
| 48 | { |
| 49 | type: 'section', |
| 50 | text: { |
| 51 | type: 'mrkdwn', |
| 52 | text: `${emoji} *${typeLabel} edited:* <${viewUrl}|${edit.domain}> (rev ${edit.revision_number})`, |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | type: 'section', |
| 57 | fields: [ |
| 58 | { type: 'mrkdwn', text: `*Editor:*\n${editorDisplay}` }, |
| 59 | { type: 'mrkdwn', text: `*Summary:*\n${edit.edit_summary}` }, |
| 60 | ], |
| 61 | }, |
| 62 | ], |
| 63 | }; |
| 64 | |
| 65 | try { |
| 66 | const result = await sendChannelMessage(channelId, message); |
| 67 | return result.ts || null; |
| 68 | } catch (error) { |
| 69 | logger.error({ error, domain: edit.domain }, 'Failed to send registry edit notification'); |
| 70 | return null; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Notify when a new record is created and pending Addie review. |
no test coverage detected