-
Notifications
You must be signed in to change notification settings - Fork 42
/
mark_msg_as_read.go
54 lines (44 loc) · 1.4 KB
/
mark_msg_as_read.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package handlers
import (
"encoding/json"
"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/mylog"
"github.com/tencent-connect/botgo/openapi"
"github.com/tidwall/gjson"
)
type MarkThisMessageAsReadAPIResponse struct {
Status string `json:"status"`
Data gjson.Result `json:"data"`
Msg string `json:"msg"`
Wording string `json:"wording"`
RetCode int64 `json:"retcode"`
Echo interface{} `json:"echo"`
}
func init() {
callapi.RegisterHandler("mark_msg_as_read", MarkThisMessageAsRead)
}
func MarkThisMessageAsRead(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) (string, error) {
var response MarkThisMessageAsReadAPIResponse
response.Data.Str = "123"
response.Msg = "123"
response.RetCode = 0
response.Status = "ok"
response.Echo = message.Echo
// Convert the members slice to a map
outputMap := structToMap(response)
mylog.Printf("mark_msg_as_read: %+v\n", outputMap)
err := client.SendMessage(outputMap)
if err != nil {
mylog.Printf("Error sending message via client: %v", err)
} else {
mylog.Printf("响应mark_msg_as_read: %+v", outputMap)
}
//把结果从struct转换为json
result, err := json.Marshal(response)
if err != nil {
mylog.Printf("Error marshaling data: %v", err)
//todo 符合onebotv11 ws返回的错误码
return "", nil
}
return string(result), nil
}