(record: {
entity_type: 'brand' | 'property';
domain: string;
editor_email?: string;
editor_name?: string;
})
| 75 | * Notify when a new record is created and pending Addie review. |
| 76 | */ |
| 77 | export async function notifyRegistryCreate(record: { |
| 78 | entity_type: 'brand' | 'property'; |
| 79 | domain: string; |
| 80 | editor_email?: string; |
| 81 | editor_name?: string; |
| 82 | }): Promise<string | null> { |
| 83 | const channelId = getChannelId(); |
| 84 | if (!channelId || !isSlackConfigured()) return null; |
| 85 | |
| 86 | const emoji = record.entity_type === 'brand' ? '🏷️' : '🌐'; |
| 87 | const typeLabel = record.entity_type === 'brand' ? 'Brand' : 'Property'; |
| 88 | const editorDisplay = record.editor_name || record.editor_email || 'Unknown'; |
| 89 | |
| 90 | const message: SlackBlockMessage = { |
| 91 | text: `${emoji} New ${typeLabel.toLowerCase()}: ${record.domain} by ${editorDisplay} - awaiting review`, |
| 92 | blocks: [ |
| 93 | { |
| 94 | type: 'section', |
| 95 | text: { |
| 96 | type: 'mrkdwn', |
| 97 | text: `${emoji} *New ${typeLabel.toLowerCase()} record:* \`${record.domain}\`\n_Awaiting Addie review_`, |
| 98 | }, |
| 99 | }, |
| 100 | { |
| 101 | type: 'section', |
| 102 | fields: [ |
| 103 | { type: 'mrkdwn', text: `*Created by:*\n${editorDisplay}` }, |
| 104 | ], |
| 105 | }, |
| 106 | ], |
| 107 | }; |
| 108 | |
| 109 | try { |
| 110 | const result = await sendChannelMessage(channelId, message); |
| 111 | return result.ts || null; |
| 112 | } catch (error) { |
| 113 | logger.error({ error, domain: record.domain }, 'Failed to send registry create notification'); |
| 114 | return null; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Notify when Addie approves a new record. |
no test coverage detected