Add set message reaction helpers.
This commit is contained in:
parent
e41be9f718
commit
a304e9002d
3 changed files with 76 additions and 1 deletions
12
bot.go
12
bot.go
|
@ -746,3 +746,15 @@ func EscapeText(parseMode string, text string) string {
|
||||||
|
|
||||||
return replacer.Replace(text)
|
return replacer.Replace(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *BotAPI) SendReaction(config SetMessageReactionConfig) (Message, error) {
|
||||||
|
resp, err := bot.Request(config)
|
||||||
|
if err != nil {
|
||||||
|
return Message{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var message Message
|
||||||
|
err = json.Unmarshal(resp.Result, &message)
|
||||||
|
|
||||||
|
return message, err
|
||||||
|
}
|
||||||
|
|
|
@ -1141,3 +1141,31 @@ func ValidateWebAppData(token, telegramInitData string) (bool, error) {
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewSetMessageReactionType(chatID int64, messageID int, reaction ReactionType, isBig bool) SetMessageReactionConfig {
|
||||||
|
return SetMessageReactionConfig{
|
||||||
|
BaseChatMessage: BaseChatMessage{
|
||||||
|
ChatConfig: ChatConfig{
|
||||||
|
ChatID: chatID,
|
||||||
|
},
|
||||||
|
MessageID: messageID,
|
||||||
|
},
|
||||||
|
Reaction: []ReactionType{reaction},
|
||||||
|
IsBig: isBig,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSetMessageReactionEmoji(chatID int64, messageID int, reaction string, isBig bool) SetMessageReactionConfig {
|
||||||
|
return SetMessageReactionConfig{
|
||||||
|
BaseChatMessage: BaseChatMessage{
|
||||||
|
ChatConfig: ChatConfig{
|
||||||
|
ChatID: chatID,
|
||||||
|
},
|
||||||
|
MessageID: messageID,
|
||||||
|
},
|
||||||
|
Reaction: []ReactionType{
|
||||||
|
{Type: "emoji", Emoji: reaction},
|
||||||
|
},
|
||||||
|
IsBig: isBig,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -845,7 +845,6 @@ func TestCommands(t *testing.T) {
|
||||||
require.Equal(t, "a private command", commands[0].Description)
|
require.Equal(t, "a private command", commands[0].Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: figure out why test is failing
|
|
||||||
func TestEditMessageMedia(t *testing.T) {
|
func TestEditMessageMedia(t *testing.T) {
|
||||||
bot, err := getBot(t)
|
bot, err := getBot(t)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -872,3 +871,39 @@ func TestEditMessageMedia(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetReaction(t *testing.T) {
|
||||||
|
bot, err := getBot(t)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
t.Run("set reaction using reaction type", func(t *testing.T) {
|
||||||
|
msg := tgbotapi.NewMessage(ChatID, "An initial message to test reaction type")
|
||||||
|
msg.ParseMode = tgbotapi.ModeMarkdown
|
||||||
|
m, err := bot.Send(msg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, m)
|
||||||
|
|
||||||
|
reaction := tgbotapi.NewSetMessageReactionType(ChatID, m.MessageID, tgbotapi.ReactionType{
|
||||||
|
Type: "emoji",
|
||||||
|
Emoji: "👍",
|
||||||
|
}, true)
|
||||||
|
|
||||||
|
res, err := bot.Request(reaction)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, res)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("set reaction using reaction emoji", func(t *testing.T) {
|
||||||
|
msg := tgbotapi.NewMessage(ChatID, "An initial message to test reaction emoji")
|
||||||
|
msg.ParseMode = tgbotapi.ModeMarkdown
|
||||||
|
m, err := bot.Send(msg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, m)
|
||||||
|
|
||||||
|
reaction := tgbotapi.NewSetMessageReactionEmoji(ChatID, m.MessageID, "👀", true)
|
||||||
|
|
||||||
|
res, err := bot.Request(reaction)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, res)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue