Skip to content

Commit aa5bbfa

Browse files
openapi: 拉取表情表态用户列表 (merge request !46)
Squash merge branch 'feature_20220411_getreactions_story_873145169' into 'master' - 新增拉取表情表态用户列表 TAPD: --story=873145169
1 parent 6f5ee07 commit aa5bbfa

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

dto/message.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ type EmbedField struct {
6262
type MessageAttachment struct {
6363
URL string `json:"url"`
6464
}
65+
66+
// MessageReactionUsers 消息表情表态用户列表
67+
type MessageReactionUsers struct {
68+
Users []*User `json:"users,omitempty"`
69+
Cookie string `json:"cookie,omitempty"`
70+
IsEnd bool `json:"is_end,omitempty"`
71+
}

dto/pager.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ func (m *MessagesPager) QueryParams() map[string]string {
6666
return query
6767
}
6868

69+
// MessageReactionPager 分页器
70+
type MessageReactionPager struct {
71+
Cookie string `json:"cookie"` // 分页游标
72+
Limit string `json:"limit"` // 分页大小,1-1000,默认是20
73+
}
74+
75+
// QueryParams 转换为 query 参数
76+
func (g *MessageReactionPager) QueryParams() map[string]string {
77+
query := make(map[string]string)
78+
if g.Limit != "" {
79+
query["limit"] = g.Limit
80+
}
81+
if g.Cookie != "" {
82+
query["cookie"] = g.Cookie
83+
}
84+
return query
85+
}
86+
6987
// MessagePagerType 消息翻页拉取方式
7088
type MessagePagerType string
7189

examples/apitest/message_reaction_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,26 @@ func TestMessageReaction(t *testing.T) {
2525
t.Logf("err:%+v", err)
2626
},
2727
)
28+
t.Run(
29+
"Get Reaction Users", func(t *testing.T) {
30+
users, err := api.GetMessageReactions(ctx, testChannelID, testMessageID, dto.Emoji{Type: 1, ID: "43"},
31+
&dto.MessageReactionPager{
32+
Limit: "20",
33+
})
34+
if err != nil {
35+
t.Error(err)
36+
}
37+
t.Logf("err:%+v", err)
38+
39+
_, err = api.GetMessageReactions(ctx, testChannelID, testMessageID, dto.Emoji{Type: 1, ID: "43"},
40+
&dto.MessageReactionPager{
41+
Cookie: users.Cookie,
42+
Limit: "20",
43+
})
44+
if err != nil {
45+
t.Error(err)
46+
}
47+
t.Logf("err:%+v", err)
48+
},
49+
)
2850
}

openapi/iface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ type MessageReactionAPI interface {
216216
CreateMessageReaction(ctx context.Context, channelID, messageID string, emoji dto.Emoji) error
217217
// DeleteOwnMessageReaction 删除自己的消息表情表态
218218
DeleteOwnMessageReaction(ctx context.Context, channelID, messageID string, emoji dto.Emoji) error
219+
// GetMessageReactions 获取消息表情表态用户列表
220+
GetMessageReactions(ctx context.Context, channelID, messageID string, emoji dto.Emoji,
221+
pager *dto.MessageReactionPager) (*dto.MessageReactionUsers, error)
219222
}
220223

221224
// InteractionAPI 互动接口

openapi/v1/message_reaction.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package v1
22

33
import (
44
"context"
5+
"encoding/json"
56
"strconv"
67

78
"github.com/tencent-connect/botgo/dto"
9+
"github.com/tencent-connect/botgo/errs"
810
)
911

1012
// CreateMessageReaction 对消息发表表情表态
@@ -36,3 +38,28 @@ func (o *openAPI) DeleteOwnMessageReaction(ctx context.Context,
3638
}
3739
return nil
3840
}
41+
42+
// GetMessageReactionUsers 获取消息表情表态用户列表
43+
func (o *openAPI) GetMessageReactionUsers(ctx context.Context, channelID, messageID string, emoji dto.Emoji,
44+
pager *dto.MessageReactionPager) (*dto.MessageReactionUsers, error) {
45+
if pager == nil {
46+
return nil, errs.ErrPagerIsNil
47+
}
48+
resp, err := o.request(ctx).
49+
SetPathParam("channel_id", channelID).
50+
SetPathParam("message_id", messageID).
51+
SetPathParam("emoji_type", strconv.FormatUint(uint64(emoji.Type), 10)).
52+
SetPathParam("emoji_id", emoji.ID).
53+
SetQueryParams(pager.QueryParams()).
54+
Get(o.getURL(messageReactionURI))
55+
if err != nil {
56+
return nil, err
57+
}
58+
59+
messageReactionUsers := &dto.MessageReactionUsers{}
60+
if err := json.Unmarshal(resp.Body(), &messageReactionUsers); err != nil {
61+
return nil, err
62+
}
63+
64+
return messageReactionUsers, nil
65+
}

0 commit comments

Comments
 (0)