Skip to content

Commit aaa839a

Browse files
openapi/v1: 表情表态api SDK (merge request !30)
Squash merge branch 'feature_20220221_reactionapi_story_872022587' into 'master' openapi/v1: 表情表态api SDK --story=872022051 TAPD: --story=872022051
1 parent 1ef27e7 commit aaa839a

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package apitest
2+
3+
import (
4+
"testing"
5+
6+
"github.com/tencent-connect/botgo/dto"
7+
)
8+
9+
func TestMessageReaction(t *testing.T) {
10+
t.Run(
11+
"Create Message Reaction", func(t *testing.T) {
12+
err := api.CreateMessageReaction(ctx, testChannelID, testMessageID, dto.Emoji{Type: 1, ID: "43"})
13+
if err != nil {
14+
t.Error(err)
15+
}
16+
t.Logf("err:%+v", err)
17+
},
18+
)
19+
t.Run(
20+
"Delete Own Reaction", func(t *testing.T) {
21+
err := api.DeleteOwnMessageReaction(ctx, testChannelID, testMessageID, dto.Emoji{Type: 1, ID: "43"})
22+
if err != nil {
23+
t.Error(err)
24+
}
25+
t.Logf("err:%+v", err)
26+
},
27+
)
28+
}

openapi/iface.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type OpenAPI interface {
2424
AnnouncesAPI
2525
ScheduleAPI
2626
APIPermissionsAPI
27+
MessageReactionAPI
2728
}
2829

2930
// Base 基础能力接口
@@ -178,3 +179,11 @@ type APIPermissionsAPI interface {
178179
RequireAPIPermissions(ctx context.Context,
179180
guildID string, demand *dto.APIPermissionDemandToCreate) (*dto.APIPermissionDemand, error)
180181
}
182+
183+
// MessageReactionAPI 消息表情表态接口
184+
type MessageReactionAPI interface {
185+
// CreateMessageReaction 对消息发表表情表态
186+
CreateMessageReaction(ctx context.Context, channelID, messageID string, emoji dto.Emoji) error
187+
// DeleteOwnMessageReaction 删除自己的消息表情表态
188+
DeleteOwnMessageReaction(ctx context.Context, channelID, messageID string, emoji dto.Emoji) error
189+
}

openapi/v1/message_reaction.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package v1
2+
3+
import (
4+
"context"
5+
"strconv"
6+
7+
"github.com/tencent-connect/botgo/dto"
8+
)
9+
10+
// CreateMessageReaction 对消息发表表情表态
11+
func (o *openAPI) CreateMessageReaction(ctx context.Context,
12+
channelID, messageID string, emoji dto.Emoji) error {
13+
_, err := o.request(ctx).
14+
SetPathParam("channel_id", channelID).
15+
SetPathParam("message_id", messageID).
16+
SetPathParam("emoji_type", strconv.FormatUint(uint64(emoji.Type), 10)).
17+
SetPathParam("emoji_id", emoji.ID).
18+
Put(o.getURL(messageReactionURI))
19+
if err != nil {
20+
return err
21+
}
22+
return nil
23+
}
24+
25+
// DeleteOwnMessageReaction 删除自己的消息表情表态
26+
func (o *openAPI) DeleteOwnMessageReaction(ctx context.Context,
27+
channelID, messageID string, emoji dto.Emoji) error {
28+
_, err := o.request(ctx).
29+
SetPathParam("channel_id", channelID).
30+
SetPathParam("message_id", messageID).
31+
SetPathParam("emoji_type", strconv.FormatUint(uint64(emoji.Type), 10)).
32+
SetPathParam("emoji_id", emoji.ID).
33+
Delete(o.getURL(messageReactionURI))
34+
if err != nil {
35+
return err
36+
}
37+
return nil
38+
}

openapi/v1/resource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const (
5656

5757
apiPermissionURI uri = "/guilds/{guild_id}/api_permission"
5858
apiPermissionDemandURI uri = "/guilds/{guild_id}/api_permission/demand"
59+
60+
messageReactionURI uri = "/channels/{channel_id}/messages/{message_id}/reactions/{emoji_type}/{emoji_id}"
5961
)
6062

6163
// getURL 获取接口地址,会处理沙箱环境判断

0 commit comments

Comments
 (0)