From 8755b74a05dca7c4d15072eb78e082626369a165 Mon Sep 17 00:00:00 2001 From: 4t145 Date: Sat, 28 Oct 2023 18:39:41 +0800 Subject: [PATCH] reach: fix only send to phone (#515) * reach: fix only send to phone * update * update --- support/reach/src/reach_consts.rs | 1 + support/reach/src/reach_init.rs | 18 +++++++++--------- .../reach/src/task/message_send_listener.rs | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/support/reach/src/reach_consts.rs b/support/reach/src/reach_consts.rs index d4e7b5873..a04d10851 100644 --- a/support/reach/src/reach_consts.rs +++ b/support/reach/src/reach_consts.rs @@ -17,6 +17,7 @@ pub const RBUM_SCOPE_LEVEL_APP: RbumScopeLevelKind = RbumScopeLevelKind::L2; pub const REACH_INIT_OWNER: &str = "ReachInit"; pub const IAM_KEY_PHONE_V_CODE: &str = "PhoneVCode"; +pub const IAM_KEY_MAIL_V_CODE: &str = "MailVCode"; pub const ACCOUNT_SPLIT: char = ';'; diff --git a/support/reach/src/reach_init.rs b/support/reach/src/reach_init.rs index 40c555ca8..8ff33fdf7 100644 --- a/support/reach/src/reach_init.rs +++ b/support/reach/src/reach_init.rs @@ -74,15 +74,15 @@ pub async fn db_init() -> TardisResult<()> { DOMAIN_REACH_ID.set(domain_id).expect("fail to set DOMAIN_REACH_ID"); let db_kind = TardisFuns::reldb().backend(); let compatible_type = TardisFuns::reldb().compatible_type(); - funs.db().init(crate::domain::message_log::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - funs.db().init(crate::domain::message_signature::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - funs.db().init(crate::domain::message_template::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - funs.db().init(crate::domain::message::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - funs.db().init(crate::domain::trigger_global_config::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - funs.db().init(crate::domain::trigger_instance_config::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - funs.db().init(crate::domain::trigger_scene::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - funs.db().init(crate::domain::reach_vcode_strategy::ActiveModel::init(db_kind, None, compatible_type.clone())).await?; - ReachTriggerSceneService::init(&funs, &ctx).await?; + funs.db().init(crate::domain::message_log::ActiveModel::init(db_kind, None, compatible_type)).await?; + funs.db().init(crate::domain::message_signature::ActiveModel::init(db_kind, None, compatible_type)).await?; + funs.db().init(crate::domain::message_template::ActiveModel::init(db_kind, None, compatible_type)).await?; + funs.db().init(crate::domain::message::ActiveModel::init(db_kind, None, compatible_type)).await?; + funs.db().init(crate::domain::trigger_global_config::ActiveModel::init(db_kind, None, compatible_type)).await?; + funs.db().init(crate::domain::trigger_instance_config::ActiveModel::init(db_kind, None, compatible_type)).await?; + funs.db().init(crate::domain::trigger_scene::ActiveModel::init(db_kind, None, compatible_type)).await?; + funs.db().init(crate::domain::reach_vcode_strategy::ActiveModel::init(db_kind, None, compatible_type)).await?; + // ReachTriggerSceneService::init(&funs, &ctx).await?; funs.commit().await?; Ok(()) } diff --git a/support/reach/src/task/message_send_listener.rs b/support/reach/src/task/message_send_listener.rs index 5683f4d43..198ac7895 100644 --- a/support/reach/src/task/message_send_listener.rs +++ b/support/reach/src/task/message_send_listener.rs @@ -49,13 +49,22 @@ impl MessageSendListener { let mut to = HashSet::new(); let start_time = Utc::now(); let owner_path = rbum_scope_helper::get_pre_paths(RBUM_SCOPE_LEVEL_TENANT as i16, &message.own_paths).unwrap_or_default(); + let cert_key = match message.rel_reach_channel { + ReachChannelKind::Sms => IAM_KEY_PHONE_V_CODE, + ReachChannelKind::Email => IAM_KEY_MAIL_V_CODE, + _ => { + // unsupported + ReachMessageServ::update_status(&message.id, ReachStatusKind::Pending, ReachStatusKind::Fail, &self.funs, &ctx).await?; + return Ok(()); + } + }; for account_id in message.to_res_ids.split(ACCOUNT_SPLIT) { if let Ok(mut resp) = iam_client.get_account(account_id, &owner_path).await { - let Some(phone) = resp.certs.remove(IAM_KEY_PHONE_V_CODE) else { - log::warn!("[Reach] Notify Phone channel send error, missing [PhoneVCode] parameters, resp: {resp:?}"); + let Some(res_id) = resp.certs.remove(cert_key) else { + log::warn!("[Reach] Notify {chan} channel send error, missing [{cert_key}] parameters, resp: {resp:?}", chan = message.rel_reach_channel); continue; }; - to.insert(phone); + to.insert(res_id); } else { log::warn!("[Reach] iam get account info error, account_id: {account_id}") }