* Fetch channel info and build a partial ThreadContext with channel details * Also looks up any associated working group for the channel
(channelId: string)
| 461 | * Also looks up any associated working group for the channel |
| 462 | */ |
| 463 | async function buildChannelContext(channelId: string): Promise<Partial<ThreadContext>> { |
| 464 | const context: Partial<ThreadContext> = { |
| 465 | viewing_channel_id: channelId, |
| 466 | }; |
| 467 | |
| 468 | try { |
| 469 | const channelInfo = await getChannelInfo(channelId); |
| 470 | if (channelInfo) { |
| 471 | context.viewing_channel_name = channelInfo.name; |
| 472 | context.viewing_channel_is_private = channelInfo.is_private; |
| 473 | if (channelInfo.purpose?.value) { |
| 474 | context.viewing_channel_description = channelInfo.purpose.value; |
| 475 | } |
| 476 | if (channelInfo.topic?.value) { |
| 477 | context.viewing_channel_topic = channelInfo.topic.value; |
| 478 | } |
| 479 | } |
| 480 | } catch (error) { |
| 481 | logger.debug({ error, channelId }, 'Could not fetch channel info'); |
| 482 | } |
| 483 | |
| 484 | // Look up if this channel is associated with a working group |
| 485 | try { |
| 486 | const workingGroup = await workingGroupDb.getWorkingGroupBySlackChannelId(channelId); |
| 487 | if (workingGroup) { |
| 488 | context.viewing_channel_working_group_slug = workingGroup.slug; |
| 489 | context.viewing_channel_working_group_name = workingGroup.name; |
| 490 | context.viewing_channel_working_group_id = workingGroup.id; |
| 491 | logger.debug({ channelId, workingGroupSlug: workingGroup.slug }, 'Channel associated with working group'); |
| 492 | } |
| 493 | } catch (error) { |
| 494 | logger.debug({ error, channelId }, 'Could not look up working group for channel'); |
| 495 | } |
| 496 | |
| 497 | // Check if this channel is a system-configured channel (prospect, escalation, etc.) |
| 498 | try { |
| 499 | const systemRole = await getSystemChannelRole(channelId); |
| 500 | if (systemRole) { |
| 501 | context.viewing_channel_system_role = systemRole; |
| 502 | logger.debug({ channelId, systemRole }, 'Channel is a system channel'); |
| 503 | } |
| 504 | } catch (error) { |
| 505 | logger.debug({ error, channelId }, 'Could not check system channel role'); |
| 506 | } |
| 507 | |
| 508 | return context; |
| 509 | } |
| 510 | |
| 511 | let addieDb: AddieDatabase | null = null; |
| 512 | let addieRouter: AddieRouter | null = null; |
no test coverage detected