Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(channel): default macro support channel for new users (#5077)
Will Hutchinsondb172292bfc5
diff --git a/services/authentication_service/src/api/context.rs b/services/authentication_service/src/api/context.rsindex 324c0fdd7f..3e69f9035d 100644--- a/services/authentication_service/src/api/context.rs+++ b/services/authentication_service/src/api/context.rs@@ -38,12 +38,14 @@ use sqlx::PgPool;pub(crate) type NotificationIngressType = SqsNotificationIngress<SqsQueue>;+pub(crate) type ChannelServiceType = channels::domain::service::ChannelServiceImpl<+ channels::outbound::pg_channels_repo::PgChannelsRepo,+>;+pub(crate) type TeamsServiceType = teams::domain::team_service::TeamServiceImpl<teams::outbound::team_repo::TeamRepositoryImpl,teams::outbound::customer_repo::CustomerRepositoryImpl,- channels::domain::service::ChannelServiceImpl<- channels::outbound::pg_channels_repo::PgChannelsRepo,- >,+ ChannelServiceType,UserRolesAndPermissionsServiceImpl<MacroDB, MacroDB>,NotificationIngressType,teams::outbound::crm_enqueuer::SqsCrmEnqueuer,@@ -96,6 +98,7 @@ pub(crate) struct ApiContext {pub user_roles_and_permissions_service:Arc<UserRolesAndPermissionsServiceImpl<MacroDB, MacroDB>>, // Note: since FromRef doesn't support generics we have to specify the concrete types herepub teams_service: Arc<TeamsServiceType>,+ pub channel_service: Arc<ChannelServiceType>,pub entity_access_service: Arc<EntityAccessServiceType>,pub native_app_service: Arc<NativeAppServiceImpl<DefaultBundleFetcher>>,pub analytics_client: Arc<AnalyticsClient>,diff --git a/services/authentication_service/src/api/webhooks/user/create_user_webhook.rs b/services/authentication_service/src/api/webhooks/user/create_user_webhook.rsindex b69e65ac68..b3f2481fda 100644--- a/services/authentication_service/src/api/webhooks/user/create_user_webhook.rs+++ b/services/authentication_service/src/api/webhooks/user/create_user_webhook.rs@@ -13,11 +13,19 @@ use crate::{rate_limit_config::RATE_LIMIT_CONFIG,};use authentication_service::service::user::create_user::create_user;+use channels::domain::{+ models::{ChannelType, CreateChannelRequest, Sender},+ ports::ChannelService,+};use fusionauth::error::FusionAuthClientError;use macro_user_id::{email::Email, user_id::MacroUserIdStr};use model::authentication::webhooks::FusionAuthUserWebhook;+use std::collections::HashSet;use teams::domain::team_repo::TeamService;+/// Macro support team members added to every new user's support channel.+const MACRO_SUPPORT_EMAILS: [&str; 3] = ["[email protected]", "[email protected]", "[email protected]"];+/// FusionAuth create user webhook#[tracing::instrument(skip(ctx, req, _internal_authorization), fields(email=%req.event.user.email, fusionauth_user_id=%req.event.user.id, username=?req.event.user.username, event_type=%req.event.event_type, ip_address=%req.event.info.ip_address))]pub async fn handler(@@ -290,6 +298,53 @@ async fn create_user_webhook(ctx: &ApiContext, req: FusionAuthUserWebhook) -> an}});+ // Create a private support channel connecting the new user with the+ // Macro support team. Fire-and-forget: a failed channel creation must+ // never block user creation.+ tokio::spawn({+ let channel_service = ctx.channel_service.clone();+ let user_id = user_id.clone();+ let email = email.clone();+ async move {+ let owner_id = match MacroUserIdStr::try_from(user_id) {+ Ok(owner_id) => owner_id,+ Err(e) => {+ tracing::error!(error=?e, "unable to parse user id for support channel");+ return;+ }+ };++ let participants = match MACRO_SUPPORT_EMAILS+ .into_iter()+ .map(MacroUserIdStr::try_from_email)+ .collect::<Result<HashSet<_>, _>>()+ {+ Ok(participants) => participants,+ Err(e) => {+ tracing::error!(error=?e, "unable to parse support user ids for support channel");+ return;+ }+ };++ if let Err(e) = channel_service+ .create_channel(+ Sender::new_from_user(owner_id),+ None,+ CreateChannelRequest {+ name: Some(format!("{email} x Macro Support")),+ channel_type: ChannelType::Private,+ team_id: None,+ auto_join_team: false,+ participants,+ },+ )+ .await+ {+ tracing::error!(error=?e, %email, "failed to create Macro support channel");+ }+ }+ });+tracing::trace!(email, fusionauth_user_id, elapsed=?start_time.elapsed(), "created user");// Allow to fail silentlydiff --git a/services/authentication_service/src/main.rs b/services/authentication_service/src/main.rsindex 6ac384e6f4..6286d412b9 100644--- a/services/authentication_service/src/main.rs+++ b/services/authentication_service/src/main.rs@@ -312,7 +312,7 @@ async fn main() -> anyhow::Result<()> {let teams_service_impl = TeamServiceImpl::new_with_analytics(teams_repo_impl,customer_repo_impl,- channel_service,+ channel_service.clone(),user_roles_and_permissions_service.clone(),notification_ingress_service.clone(),crm_enqueuer,@@ -382,6 +382,7 @@ async fn main() -> anyhow::Result<()> {stripe_webhook_secret,user_roles_and_permissions_service: Arc::new(user_roles_and_permissions_service),teams_service: Arc::new(teams_service_impl),+ channel_service: Arc::new(channel_service),entity_access_service: Arc::new(entity_access_service_impl),referral_service: Arc::new(referral_service),native_app_service: Arc::new(NativeAppServiceImpl {