Skip to content

Commit

Permalink
feat(im): support forward message
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Dec 27, 2023
1 parent 3b0dcee commit cd189e5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,13 @@
# CHANGELOG

## v1.12.0

- feat(im): support forward message
- feat(im): change reaction API names (#66)

## v1.11.0

- feat(message): support reactions (#62)
- feat(im): support reactions (#62)
- ci: run tests under private tenant to avoid applying permissions (#65)

## v1.10.2
Expand Down
15 changes: 15 additions & 0 deletions api_message.go
Expand Up @@ -15,6 +15,7 @@ const (
deleteEphemeralMessageURL = "/open-apis/ephemeral/v1/delete"
pinMessageURL = "/open-apis/im/v1/pins"
unpinMessageURL = "/open-apis/im/v1/pins/%s"
forwardMessageURL = "/open-apis/im/v1/messages/%s/forward?receive_id_type=%s"
)

// PostMessageResponse .
Expand Down Expand Up @@ -112,6 +113,9 @@ type RecallMessageResponse = BaseResponse
// UpdateMessageResponse .
type UpdateMessageResponse = BaseResponse

// ForwardMessageResponse .
type ForwardMessageResponse = PostMessageResponse

// MessageReceiptResponse .
type MessageReceiptResponse struct {
BaseResponse
Expand Down Expand Up @@ -371,3 +375,14 @@ func (bot Bot) UnpinMessage(messageID string) (*UnpinMessageResponse, error) {
err := bot.DeleteAPIRequest("PinMessage", url, true, nil, &respData)
return &respData, err
}

// ForwardMessage forwards a message
func (bot Bot) ForwardMessage(messageID string, receiveID *OptionalUserID) (*ForwardMessageResponse, error) {
url := fmt.Sprintf(forwardMessageURL, messageID, receiveID.UIDType)
params := map[string]interface{}{
"receive_id": receiveID.RealID,
}
var respData ForwardMessageResponse
err := bot.PostAPIRequest("ForwardMessage", url, true, params, &respData)
return &respData, err
}
13 changes: 13 additions & 0 deletions api_message_test.go
Expand Up @@ -462,3 +462,16 @@ func TestReactionMessage(t *testing.T) {
}
}
}

func TestForwardMessage(t *testing.T) {
msg := NewMsgBuffer(MsgText)
om := msg.BindEmail(testUserEmail).Text("let's forward").Build()
resp, err := bot.PostMessage(om)
if assert.NoError(t, err) {
messageID := resp.Data.MessageID
resp, err := bot.ForwardMessage(messageID, WithChatID(testGroupChatID))
if assert.NoError(t, err) {
assert.Equal(t, 0, resp.Code)
}
}
}

0 comments on commit cd189e5

Please sign in to comment.