all repos — telegram-bot-api @ b24a37443a9122cc263f3f82eaeb6b687d65db76

Golang bindings for the Telegram Bot API

Add PinChatMessage and UnpinChatMessage methods
Lord-Protector savely@krasovsky.me
Sat, 05 Aug 2017 12:29:06 +0300
commit

b24a37443a9122cc263f3f82eaeb6b687d65db76

parent

13c54dc548f7ca692fe434d4b7cac072b0de0e0b

2 files changed, 72 insertions(+), 10 deletions(-)

jump to
M bot.gobot.go

@@ -837,18 +837,42 @@ }

// GetInviteLink get InviteLink for a chat func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) { - v := url.Values{} + v := url.Values{} - if config.SuperGroupUsername == "" { - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - } else { - v.Add("chat_id", config.SuperGroupUsername) - } + if config.SuperGroupUsername == "" { + v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) + } else { + v.Add("chat_id", config.SuperGroupUsername) + } - resp, err := bot.MakeRequest("exportChatInviteLink", v) + resp, err := bot.MakeRequest("exportChatInviteLink", v) - var inviteLink string - err = json.Unmarshal(resp.Result, &inviteLink) + var inviteLink string + err = json.Unmarshal(resp.Result, &inviteLink) - return inviteLink, err + return inviteLink, err } + +// Pin message in supergroup +func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, error) { + v, err := config.values() + if err != nil { + return APIResponse{}, err + } + + bot.debugLog(config.method(), v, nil) + + return bot.MakeRequest(config.method(), v) +} + +// Unpin message in supergroup +func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error) { + v, err := config.values() + if err != nil { + return APIResponse{}, err + } + + bot.debugLog(config.method(), v, nil) + + return bot.MakeRequest(config.method(), v) +}
M configs.goconfigs.go

@@ -1035,3 +1035,41 @@ v.Add("message_id", strconv.Itoa(config.MessageID))

return v, nil } + +// PinChatMessageConfig contains information of a message in a chat to pin. +type PinChatMessageConfig struct { + ChatID int64 + MessageID int + DisableNotification bool +} + +func (config PinChatMessageConfig) method() string { + return "pinChatMessage" +} + +func (config PinChatMessageConfig) values() (url.Values, error) { + v := url.Values{} + + v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) + v.Add("message_id", strconv.Itoa(config.MessageID)) + v.Add("disable_notification", strconv.FormatBool(config.DisableNotification)) + + return v, nil +} + +// UnpinChatMessageConfig contains information of chat to unpin. +type UnpinChatMessageConfig struct { + ChatID int64 +} + +func (config UnpinChatMessageConfig) method() string { + return "unpinChatMessage" +} + +func (config UnpinChatMessageConfig) values() (url.Values, error) { + v := url.Values{} + + v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) + + return v, nil +}