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

add: set message reaction #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2555,3 +2555,39 @@ func (c *Client) SetChatPermissions(chatID string, permissions *ChatPermissions)
var set bool
return c.doRequest("setChatPermissions", req, &set)
}

type reaction struct {
Type string `json:"type"`
Emoji string `json:"emoji"`
}

/*
SetMessageReaction set emojis to message.
Use this method to change the chosen reactions on a message.
Service messages can't be reacted to. Automatically forwarded messages from a channel to
its discussion group have the same available reactions as messages in the channel.
Bots can't use paid reactions.
*/
func (c *Client) SetMessageReaction(chatID string, messageID int, isBig bool, emojis ...string) error {
if len(emojis) == 0 {
return errors.New("no emojis specified")
}

var reactions []reaction
for _, emoji := range emojis {
reactions = append(reactions, reaction{
Type: "emoji", // only "emoji" type supported
Emoji: emoji,
})
}

reactionsData, _ := json.Marshal(reactions)
req := url.Values{}
req.Set("chat_id", chatID)
req.Set("message_id", fmt.Sprint(messageID))
req.Set("is_big", strconv.FormatBool(isBig))
req.Set("reaction", string(reactionsData))

var set bool
return c.doRequest("setMessageReaction", req, &set)
}
11 changes: 11 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ func TestSendDice(t *testing.T) {
}
}

func TestSetMessageReaction(t *testing.T) {
c := testClient(t, `
{"ok":true,"result":true}
`)

err := c.SetMessageReaction("123", 123, false, "🎲")
if err != nil {
t.Fatalf("error on SetMessageReaction: %v", err)
}
}

func testClient(t *testing.T, resp string) *tbot.Client {
t.Helper()
handler := func(w http.ResponseWriter, r *http.Request) {
Expand Down