Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(im): change api name to make it consistent #66

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ For Chat Bot, we can send simple messages with the following method:
- `PostImage`
- `PostShareChatCard`
- `ReplyMessage`
- `ReactionMessage`
- `DeleteReactionMessage`
- `AddReaction`
- `DeleteReaction`

Basic message examples: [examples/basic-message](https://github.com/go-lark/examples/tree/main/basic-message)

Expand Down
4 changes: 2 additions & 2 deletions README_zhCN.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ resp, err := bot.GetTenantAccessTokenInternal(true)
- `PostImage`
- `PostShareChatCard`
- `ReplyMessage`
- `ReactionMessage`
- `DeleteReactionMessage`
- `AddReaction`
- `DeleteReaction`

参考实例:[基本消息](https://github.com/go-lark/examples/tree/main/basic-message)。

Expand Down
24 changes: 12 additions & 12 deletions api_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (bot Bot) PostShareUser(openID string, userID *OptionalUserID) (*PostMessag
return bot.PostMessage(om)
}

// PostMessage posts message
// PostMessage posts a message
func (bot Bot) PostMessage(om OutcomingMessage) (*PostMessageResponse, error) {
req, err := BuildMessage(om)
if err != nil {
Expand All @@ -260,7 +260,7 @@ func (bot Bot) PostMessage(om OutcomingMessage) (*PostMessageResponse, error) {
return &respData, err
}

// ReplyMessage replies messages
// ReplyMessage replies a message
func (bot Bot) ReplyMessage(om OutcomingMessage) (*PostMessageResponse, error) {
req, err := BuildMessage(om)
if err != nil {
Expand All @@ -274,26 +274,26 @@ func (bot Bot) ReplyMessage(om OutcomingMessage) (*PostMessageResponse, error) {
return &respData, err
}

// ReactionMessage reactions messages
func (bot Bot) ReactionMessage(messageID string, emojiType EmojiType) (*ReactionResponse, error) {
// AddReaction adds reaction to a message
func (bot Bot) AddReaction(messageID string, emojiType EmojiType) (*ReactionResponse, error) {
req := map[string]interface{}{
"reaction_type": map[string]interface{}{
"emoji_type": emojiType,
},
}
var respData ReactionResponse
err := bot.PostAPIRequest("ReactionMessage", fmt.Sprintf(reactionsMessageURL, messageID), true, req, &respData)
err := bot.PostAPIRequest("AddReaction", fmt.Sprintf(reactionsMessageURL, messageID), true, req, &respData)
return &respData, err
}

// DeleteReactionMessage delete reactions messages
func (bot Bot) DeleteReactionMessage(messageID string, reactionID string) (*ReactionResponse, error) {
// DeleteReaction deletes reaction of a message
func (bot Bot) DeleteReaction(messageID string, reactionID string) (*ReactionResponse, error) {
var respData ReactionResponse
err := bot.DeleteAPIRequest("DeleteReactionMessage", fmt.Sprintf(deleteReactionsMessageURL, messageID, reactionID), true, nil, &respData)
err := bot.DeleteAPIRequest("DeleteReaction", fmt.Sprintf(deleteReactionsMessageURL, messageID, reactionID), true, nil, &respData)
return &respData, err
}

// UpdateMessage update message card
// UpdateMessage updates a message
func (bot Bot) UpdateMessage(messageID string, om OutcomingMessage) (*UpdateMessageResponse, error) {
if om.MsgType != MsgInteractive {
return nil, ErrMessageType
Expand All @@ -308,7 +308,7 @@ func (bot Bot) UpdateMessage(messageID string, om OutcomingMessage) (*UpdateMess
return &respData, err
}

// GetMessage posts message with im/v1
// GetMessage gets a message with im/v1
func (bot Bot) GetMessage(messageID string) (*GetMessageResponse, error) {
var respData GetMessageResponse
err := bot.GetAPIRequest("GetMessage", fmt.Sprintf(getMessageURL, messageID), true, nil, &respData)
Expand Down Expand Up @@ -354,7 +354,7 @@ func (bot Bot) DeleteEphemeralMessage(messageID string) (*DeleteEphemeralMessage
return &respData, err
}

// PinMessage pin a message
// PinMessage pins a message
func (bot Bot) PinMessage(messageID string) (*PinMessageResponse, error) {
params := map[string]interface{}{
"message_id": messageID,
Expand All @@ -364,7 +364,7 @@ func (bot Bot) PinMessage(messageID string) (*PinMessageResponse, error) {
return &respData, err
}

// UnpinMessage unpin a message
// UnpinMessage unpins a message
func (bot Bot) UnpinMessage(messageID string) (*UnpinMessageResponse, error) {
url := fmt.Sprintf(unpinMessageURL, messageID)
var respData UnpinMessageResponse
Expand Down
4 changes: 2 additions & 2 deletions api_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,11 @@ func TestReactionMessage(t *testing.T) {
resp, err := bot.PostMessage(om)
if assert.NoError(t, err) {
messageID := resp.Data.MessageID
resp, err := bot.ReactionMessage(messageID, EmojiTypeOK)
resp, err := bot.AddReaction(messageID, EmojiTypeOK)
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
assert.Equal(t, EmojiTypeOK, resp.Data.ReactionType.EmojiType)
deleteReactionResp, err := bot.DeleteReactionMessage(messageID, resp.Data.ReactionID)
deleteReactionResp, err := bot.DeleteReaction(messageID, resp.Data.ReactionID)
assert.NoError(t, err)
assert.Equal(t, 0, deleteReactionResp.Code)
}
Expand Down
Loading