* Index a Slack message for local full-text search * Fetches user/channel info and stores in addie_knowledge
(event: SlackMessageEvent)
| 549 | * Fetches user/channel info and stores in addie_knowledge |
| 550 | */ |
| 551 | async function indexMessageForSearch(event: SlackMessageEvent): Promise<void> { |
| 552 | try { |
| 553 | // Fetch user and channel info in parallel |
| 554 | const [user, channel] = await Promise.all([ |
| 555 | getSlackUser(event.user!), |
| 556 | getChannelInfo(event.channel), |
| 557 | ]); |
| 558 | |
| 559 | if (!user || !channel) { |
| 560 | logger.debug( |
| 561 | { userId: event.user, channelId: event.channel }, |
| 562 | 'Skipping message index: could not fetch user or channel info' |
| 563 | ); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | // Construct permalink |
| 568 | // Format: https://workspace.slack.com/archives/CHANNEL_ID/pTIMESTAMP |
| 569 | // The timestamp needs dots removed |
| 570 | const tsForLink = event.ts.replace('.', ''); |
| 571 | const permalink = `https://agenticads.slack.com/archives/${event.channel}/p${tsForLink}`; |
| 572 | |
| 573 | await addieDb.indexSlackMessage({ |
| 574 | channel_id: event.channel, |
| 575 | channel_name: channel.name || 'unknown', |
| 576 | user_id: event.user!, |
| 577 | username: user.profile?.display_name || user.profile?.real_name || user.name || 'unknown', |
| 578 | ts: event.ts, |
| 579 | text: event.text!, |
| 580 | permalink, |
| 581 | }); |
| 582 | |
| 583 | logger.debug( |
| 584 | { channelName: channel.name, username: user.name }, |
| 585 | 'Indexed Slack message for search' |
| 586 | ); |
| 587 | } catch (error) { |
| 588 | // Don't fail the main event handler if indexing fails |
| 589 | logger.error({ error, channelId: event.channel }, 'Failed to index Slack message for search'); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Handle reaction_added event |
no test coverage detected