|
@@ -265,11 +265,11 @@ type MessagePayload[T any] struct {
|
|
|
}
|
|
|
|
|
|
// SendMessage 函数用于发送消息
|
|
|
-func SendMessage[T any](hook *Hook, msgType workphone.EnumMsgType, msgTypeStr string, content T) (MessagePayload[T], error) {
|
|
|
+func SendMessage[T any](hook *Hook, msgType workphone.EnumMsgType, msgTypeStr string, content T) (map[string]interface{}, error) {
|
|
|
conn, err := hook.connWorkPhone()
|
|
|
if err != nil {
|
|
|
logx.Errorf("WebSocket 连接失败: %v", err)
|
|
|
- return MessagePayload[T]{}, err
|
|
|
+ return MessagePayload[T]{}.ToMap(), err
|
|
|
}
|
|
|
defer func() {
|
|
|
if cerr := conn.Close(); cerr != nil {
|
|
@@ -285,13 +285,13 @@ func SendMessage[T any](hook *Hook, msgType workphone.EnumMsgType, msgTypeStr st
|
|
|
|
|
|
data, err := json.Marshal(message)
|
|
|
if err != nil {
|
|
|
- return message, fmt.Errorf("JSON 序列化失败: %w", err)
|
|
|
+ return message.ToMap(), fmt.Errorf("JSON 序列化失败: %w", err)
|
|
|
}
|
|
|
|
|
|
if err := conn.WriteMessage(websocket.TextMessage, data); err != nil {
|
|
|
- return message, fmt.Errorf("发送消息失败: %w", err)
|
|
|
+ return message.ToMap(), fmt.Errorf("发送消息失败: %w", err)
|
|
|
}
|
|
|
- return message, nil
|
|
|
+ return message.ToMap(), nil
|
|
|
}
|
|
|
|
|
|
// AddFriendTask 函数用于创建并发送一个添加好友的任务
|
|
@@ -306,9 +306,9 @@ func SendMessage[T any](hook *Hook, msgType workphone.EnumMsgType, msgTypeStr st
|
|
|
//
|
|
|
// 成功时返回包含添加好友任务信息的消息负载和nil错误
|
|
|
// 失败时返回空的消息负载和相应的错误
|
|
|
-func (h *Hook) AddFriendTask(ownerWxId, phone, msg string, taskId int64) (MessagePayload[AddFriendsTask], error) {
|
|
|
+func (h *Hook) AddFriendTask(ownerWxId, phone, msg string, taskId int64) (map[string]interface{}, error) {
|
|
|
if ownerWxId == "" || phone == "" || msg == "" {
|
|
|
- return MessagePayload[AddFriendsTask]{}, fmt.Errorf("invalid input parameters")
|
|
|
+ return MessagePayload[AddFriendsTask]{}.ToMap(), fmt.Errorf("invalid input parameters")
|
|
|
}
|
|
|
content := AddFriendsTask{
|
|
|
WeChatId: ownerWxId,
|
|
@@ -330,9 +330,9 @@ func (h *Hook) AddFriendTask(ownerWxId, phone, msg string, taskId int64) (Messag
|
|
|
//
|
|
|
// 成功时返回包含查找联系人任务信息的消息负载和nil错误
|
|
|
// 失败时返回空的消息负载和相应的错误
|
|
|
-func (h *Hook) FindContactByContent(ownerWxId, contentMessage string) (MessagePayload[FindContactTask], error) {
|
|
|
+func (h *Hook) FindContactByContent(ownerWxId, contentMessage string) (map[string]interface{}, error) {
|
|
|
if ownerWxId == "" || contentMessage == "" {
|
|
|
- return MessagePayload[FindContactTask]{}, fmt.Errorf("invalid input parameters")
|
|
|
+ return MessagePayload[FindContactTask]{}.ToMap(), fmt.Errorf("invalid input parameters")
|
|
|
}
|
|
|
content := FindContactTask{
|
|
|
WeChatId: ownerWxId,
|
|
@@ -340,3 +340,11 @@ func (h *Hook) FindContactByContent(ownerWxId, contentMessage string) (MessagePa
|
|
|
}
|
|
|
return SendMessage(h, workphone.EnumMsgType_FindContactTask, "FindContactTask", content)
|
|
|
}
|
|
|
+
|
|
|
+func (m MessagePayload[T]) ToMap() map[string]interface{} {
|
|
|
+ return map[string]interface{}{
|
|
|
+ "Id": m.Id,
|
|
|
+ "MsgType": m.MsgType,
|
|
|
+ "Content": m.Content,
|
|
|
+ }
|
|
|
+}
|