mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-09 17:30:25 +08:00
refactor: 消息模块重构,infra包路径简写等
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package sender
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
@@ -34,7 +35,7 @@ type feishuBotMsgResp struct {
|
||||
// FeishuBotSender 发送飞书机器人消息
|
||||
type FeishuBotSender struct{}
|
||||
|
||||
func (f FeishuBotSender) Send(channel *msgx.Channel, msg *msgx.Msg) error {
|
||||
func (f FeishuBotSender) Send(ctx context.Context, channel *msgx.Channel, msg *msgx.Msg) error {
|
||||
// https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot
|
||||
msgReq := feishuBotMsgReq{
|
||||
MsgType: "text",
|
||||
@@ -45,7 +46,7 @@ func (f FeishuBotSender) Send(channel *msgx.Channel, msg *msgx.Msg) error {
|
||||
// 使用receiver参数替换消息内容中可能存在的接收人信息
|
||||
if len(msg.Receivers) > 0 {
|
||||
if to := collx.ArrayMapFilter(msg.Receivers, func(a msgx.Receiver) (string, bool) {
|
||||
if uid := a.GetExtraString("feishuUserId"); uid != "" {
|
||||
if uid := a.Extra.GetStr("feishuUserId"); uid != "" {
|
||||
// 使用<at user_id="userId"></at>
|
||||
return fmt.Sprintf(`<at user_id="%s"></at>`, uid), true
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func (f FeishuBotSender) Send(channel *msgx.Channel, msg *msgx.Msg) error {
|
||||
|
||||
msgReq.Content.Text = content
|
||||
|
||||
if secret := channel.GetExtraString("secret"); secret != "" {
|
||||
if secret := channel.Extra.GetStr("secret"); secret != "" {
|
||||
timestamp := time.Now().Unix()
|
||||
if sign, err := f.sign(secret, timestamp); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user