Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 支持语音通知 #9686 #9687

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,16 @@ enum class NotifyType {
WECHAT,
SMS,
WEWORK,
WEWORK_GROUP
WEWORK_GROUP,
VOICE
;

/**
* OP系统可以编辑的通知模板
*/
companion object {
fun opEditable(): List<NotifyType> {
return listOf(EMAIL, RTX, WECHAT)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tencent.devops.common.notify.pojo

import com.fasterxml.jackson.annotation.JsonProperty

/**
* 语音消息
*/
class VoiceNotifyPost : BaseNotifyPost() {
@JsonProperty("Receiver")
var receiver = ""

@JsonProperty("TaskName")
var taskName = ""

@JsonProperty("Content")
var content = ""

@JsonProperty("TransferReceiver")
var transferReceiver = ""

@JsonProperty("Interval")
var interval = 0

@JsonProperty("RecallTimes")
var recallTimes = 0

@JsonProperty("TextNotify.EnableWorkwxNotify")
var workwxNotifyEnabled = false

@JsonProperty("TextNotify.NotifyTitle")
var workwxNotifyTitle = ""

@JsonProperty("TextNotify.NotifyContent")
var workwxNotifyContent = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ const val QUEUE_NOTIFY_EMAIL = "queue_notify_email"
const val QUEUE_NOTIFY_SMS = "queue_notify_sms"
const val QUEUE_NOTIFY_WEWORK = "queue_notify_wework"
const val QUEUE_NOTIFY_PUSH = "queue_notify_push"
const val QUEUE_NOTIFY_VOICE = "queue_notify_voice"
const val EXCHANGE_NOTIFY = "exchange_notify"
const val ROUTE_RTX = "rtx"
const val ROUTE_WECHAT = "wechat"
const val ROUTE_EMAIL = "email"
const val ROUTE_SMS = "sms"
const val ROUTE_WEWORK = "wework"
const val ROUTE_PUSH = "push"
const val ROUTE_VOICE = "voice"

const val PIPELINE_QUALITY_AUDIT_NOTIFY_TEMPLATE = "QUALITY_AUDIT_NOTIFY_TEMPLATE"
const val PIPELINE_QUALITY_END_NOTIFY_TEMPLATE = "QUALITY_END_NOTIFY_TEMPLATE"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.tencent.devops.notify.pojo

import com.tencent.devops.common.notify.pojo.VoiceNotifyPost
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@ApiModel("语音信息")
open class VoiceNotifyMessage : BaseMessage() {
@ApiModelProperty("接收人(英文ID),支持多个")
var receivers = mutableSetOf<String>()

@ApiModelProperty("任务名称,不超过200字符")
var taskName = ""

@ApiModelProperty("呼叫内容,建议只传简短的文字内容,详细信息通过企业微信提醒方式发送")
var content = ""

@ApiModelProperty("转接责任人(英文ID),单人")
var transferReceiver = ""

@ApiModelProperty("重呼间隔(秒),默认为0")
var interval = 0

@ApiModelProperty("最大重呼次数,默认为0")
var recallTime = 0

@ApiModelProperty("企业微信提醒")
var textNotify = TextNotify.DEFAULT

@ApiModel("语音信息--企业微信提醒")
data class TextNotify(
@ApiModelProperty("是否开启企业微信提醒")
val enabled: Boolean = false,
@ApiModelProperty("提醒Title")
val title: String = "",
@ApiModelProperty("提醒内容")
val content: String = ""
) {
companion object {
val DEFAULT = TextNotify(false, "", "")
}
}

fun addAllReceivers(receiverSet: Set<String>) {
receivers.addAll(receiverSet)
}

fun clearReceivers() {
receivers.clear()
}

@Throws(IllegalArgumentException::class)
fun asPost(): VoiceNotifyPost {
checkParams()
val post = VoiceNotifyPost()
post.receiver = this.receivers.joinToString(",")
post.taskName = this.taskName
post.content = this.content
post.transferReceiver = this.transferReceiver
post.interval = this.interval
post.recallTimes = this.recallTime
post.workwxNotifyEnabled = this.textNotify.enabled
post.workwxNotifyTitle = this.textNotify.title
post.workwxNotifyContent = this.textNotify.content

return post
}

private fun checkParams() {
if (receivers.isEmpty()) {
throw IllegalArgumentException("receiver can`t not empty")
}
if (taskName.length > 200) {
throw IllegalArgumentException("the length of task name can`t be greater then 200")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ data class MessageTemplate(
var wechatTemplate: WechatMessageTemplate? = null,
@ApiModelProperty("微信群模板", required = false)
var weworkGroupTemplate: WeworkGroupMessageTemplate? = null,
@ApiModelProperty("语音模板", required = false)
val voiceTemplate: VoiceTemplate? = null,
@ApiModelProperty("创建人", required = true)
val creator: String,
@ApiModelProperty("修改人", required = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.tencent.devops.notify.pojo.messageTemplate

import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@ApiModel("语音模板信息")
data class VoiceTemplate(
@ApiModelProperty("模板ID", required = true)
val id: String,
@ApiModelProperty("任务名称", required = false)
var taskName: String,
@ApiModelProperty("内容", required = true)
var content: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.tencent.devops.notify.blueking.sdk.CMSApi
import com.tencent.devops.notify.blueking.sdk.pojo.NotifyProperties
import com.tencent.devops.notify.blueking.service.inner.BlueKingWeworkServiceImpl
import com.tencent.devops.notify.blueking.service.inner.EmailServiceImpl
import com.tencent.devops.notify.blueking.service.inner.OrgServiceImpl
import com.tencent.devops.notify.blueking.service.inner.RtxServiceImpl
import com.tencent.devops.notify.blueking.service.inner.SmsServiceImpl
import com.tencent.devops.notify.blueking.service.inner.WechatServiceImpl
Expand All @@ -14,7 +13,6 @@ import com.tencent.devops.notify.dao.RtxNotifyDao
import com.tencent.devops.notify.dao.SmsNotifyDao
import com.tencent.devops.notify.dao.WechatNotifyDao
import com.tencent.devops.notify.service.EmailService
import com.tencent.devops.notify.service.OrgService
import com.tencent.devops.notify.service.RtxService
import com.tencent.devops.notify.service.SmsService
import com.tencent.devops.notify.service.WechatService
Expand Down Expand Up @@ -66,10 +64,6 @@ class BluekingNotifyConfiguration {
@ConditionalOnMissingBean(WeworkService::class)
fun weworkService() = BlueKingWeworkServiceImpl()

@Bean
@ConditionalOnMissingBean(OrgService::class)
fun orgService() = OrgServiceImpl()

@Bean
@ConditionalOnMissingBean(RtxService::class)
fun rtxService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.notify.pojo.EmailNotifyPost
import com.tencent.devops.common.notify.pojo.RtxNotifyPost
import com.tencent.devops.common.notify.pojo.SmsNotifyPost
import com.tencent.devops.common.notify.pojo.VoiceNotifyPost
import com.tencent.devops.common.notify.pojo.WechatNotifyPost
import com.tencent.devops.common.web.utils.I18nUtil
import com.tencent.devops.notify.blueking.sdk.pojo.ApiReq
Expand All @@ -40,11 +41,13 @@ import com.tencent.devops.notify.blueking.sdk.pojo.NotifyProperties
import com.tencent.devops.notify.blueking.sdk.pojo.SendMailReq
import com.tencent.devops.notify.blueking.sdk.pojo.SendQyWxReq
import com.tencent.devops.notify.blueking.sdk.pojo.SendSmsReq
import com.tencent.devops.notify.blueking.sdk.pojo.SendVoiceReq
import com.tencent.devops.notify.blueking.sdk.pojo.SendWxReq
import com.tencent.devops.notify.blueking.utils.NotifyService.Companion.EMAIL_URL
import com.tencent.devops.notify.blueking.utils.NotifyService.Companion.NOC_NOTICE_URL
import com.tencent.devops.notify.blueking.utils.NotifyService.Companion.RTX_URL
import com.tencent.devops.notify.blueking.utils.NotifyService.Companion.SMS_URL
import com.tencent.devops.notify.blueking.utils.NotifyService.Companion.VOICE_URL
import com.tencent.devops.notify.blueking.utils.NotifyService.Companion.WECHAT_URL
import com.tencent.devops.notify.constant.NotifyMessageCode
import com.tencent.devops.notify.constant.NotifyMessageCode.BK_NOTIFY_MESSAGES
Expand Down Expand Up @@ -140,6 +143,17 @@ class CMSApi(private val notifyProperties: NotifyProperties) {
return doPostRequest(WECHAT_URL, wechatReq)
}

fun sendVoice(voiceNotifyPost: VoiceNotifyPost): ApiResp {
val voiceReq = with(voiceNotifyPost) {
SendVoiceReq(
auto_read_message = content,
receiver__username = receiver,
bk_username = "蓝鲸助手"
)
}
return doPostRequest(VOICE_URL, voiceReq)
}

private val logger = LoggerFactory.getLogger(CMSApi::class.java)

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tencent.devops.notify.blueking.sdk.pojo

import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@ApiModel("发送语音请求参数")
data class SendVoiceReq(
@ApiModelProperty("自动语音读字信息")
var auto_read_message: String,
@ApiModelProperty(
"待通知的用户列表,自动语音通知列表,若user_list_information、receiver__username同时存在," +
"以user_list_information为准"
)
var user_list_information: Collection<String>? = null,
@ApiModelProperty(
"待通知的用户列表,包含用户名,用户需在蓝鲸平台注册,多个以逗号分隔," +
"若user_list_information、receiver__username同时存在,以user_list_information为准"
)
var receiver__username: String? = null,

override var bk_app_code: String? = "",
override var bk_app_secret: String? = "",
override var bk_token: String? = "",
override var bk_username: String? = ""
) : ApiReq(
bk_app_code, bk_app_secret, bk_token, bk_username
) {
@ApiModel("用户信息")
data class UserListInformation(
@ApiModelProperty("被通知人")
var username: String,
@ApiModelProperty("被通知人手机号")
var mobile_phone: String? = null
)
}

This file was deleted.

Loading
Loading