* Index a channel message for local full-text search * Stores in addie_knowledge for the search_slack tool
( channelId: string, userId: string, messageText: string, ts: string )
| 2963 | * Stores in addie_knowledge for the search_slack tool |
| 2964 | */ |
| 2965 | async function indexChannelMessage( |
| 2966 | channelId: string, |
| 2967 | userId: string, |
| 2968 | messageText: string, |
| 2969 | ts: string |
| 2970 | ): Promise<void> { |
| 2971 | // Only index messages with substantial content |
| 2972 | if (messageText.length < 20) { |
| 2973 | return; |
| 2974 | } |
| 2975 | |
| 2976 | try { |
| 2977 | // Fetch user and channel info |
| 2978 | const [user, channel] = await Promise.all([ |
| 2979 | getSlackUser(userId), |
| 2980 | getChannelInfo(channelId), |
| 2981 | ]); |
| 2982 | |
| 2983 | if (!user || !channel) { |
| 2984 | logger.debug( |
| 2985 | { userId, channelId }, |
| 2986 | 'Addie Bolt: Skipping message index - could not fetch user or channel info' |
| 2987 | ); |
| 2988 | return; |
| 2989 | } |
| 2990 | |
| 2991 | // Construct permalink |
| 2992 | const tsForLink = ts.replace('.', ''); |
| 2993 | const permalink = `https://agenticads.slack.com/archives/${channelId}/p${tsForLink}`; |
| 2994 | |
| 2995 | await addieDb?.indexSlackMessage({ |
| 2996 | channel_id: channelId, |
| 2997 | channel_name: channel.name || 'unknown', |
| 2998 | user_id: userId, |
| 2999 | username: user.profile?.display_name || user.profile?.real_name || user.name || 'unknown', |
| 3000 | ts, |
| 3001 | text: messageText, |
| 3002 | permalink, |
| 3003 | }); |
| 3004 | |
| 3005 | logger.debug( |
| 3006 | { channelName: channel.name, username: user.name }, |
| 3007 | 'Addie Bolt: Indexed channel message for search' |
| 3008 | ); |
| 3009 | } catch (error) { |
| 3010 | // Don't fail the main handler if indexing fails |
| 3011 | logger.warn({ error, channelId }, 'Addie Bolt: Failed to index message for search'); |
| 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | /** |
| 3016 | * Handle direct messages (DMs) to Addie |
no test coverage detected