Add methods for editing messages.

bot-api-6.1
Syfaro 2016-04-12 12:53:19 -05:00
parent a92f88ce2c
commit b6130533a3
2 changed files with 110 additions and 0 deletions

View File

@ -340,6 +340,28 @@ func TestSendChatConfig(t *testing.T) {
} }
} }
func TestSendEditMessage(t *testing.T) {
bot, _ := getBot(t)
msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing."))
if err != nil {
t.Fail()
}
edit := tgbotapi.EditMessageTextConfig{
BaseEdit: tgbotapi.BaseEdit{
ChatID: ChatID,
MessageID: msg.MessageID,
},
Text: "Updated text.",
}
_, err = bot.Send(edit)
if err != nil {
t.Fail()
}
}
func TestGetUserProfilePhotos(t *testing.T) { func TestGetUserProfilePhotos(t *testing.T) {
bot, _ := getBot(t) bot, _ := getBot(t)

View File

@ -153,6 +153,37 @@ func (file BaseFile) useExistingFile() bool {
return file.UseExisting return file.UseExisting
} }
// BaseEdit is base type of all chat edits.
type BaseEdit struct {
ChatID int64
ChannelUsername string
MessageID int
InlineMessageID string
ReplyMarkup *InlineKeyboardMarkup
}
func (edit BaseEdit) values() (url.Values, error) {
v := url.Values{}
if edit.ChannelUsername != "" {
v.Add("chat_id", edit.ChannelUsername)
} else {
v.Add("chat_id", strconv.FormatInt(edit.ChatID, 10))
}
v.Add("message_id", strconv.Itoa(edit.MessageID))
v.Add("inline_message_id", edit.InlineMessageID)
if edit.ReplyMarkup != nil {
data, err := json.Marshal(edit.ReplyMarkup)
if err != nil {
return v, err
}
v.Add("reply_markup", string(data))
}
return v, nil
}
// MessageConfig contains information about a SendMessage request. // MessageConfig contains information about a SendMessage request.
type MessageConfig struct { type MessageConfig struct {
BaseChat BaseChat
@ -500,6 +531,63 @@ func (config ChatActionConfig) method() string {
return "sendChatAction" return "sendChatAction"
} }
// EditMessageTextConfig allows you to modify the text in a message.
type EditMessageTextConfig struct {
BaseEdit
Text string
ParseMode string
DisableWebPagePreview bool
ReplyMarkup InlineKeyboardMarkup
}
func (config EditMessageTextConfig) values() (url.Values, error) {
v, _ := config.BaseEdit.values()
v.Add("text", config.Text)
v.Add("parse_mode", config.ParseMode)
v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview))
return v, nil
}
func (config EditMessageTextConfig) method() string {
return "editMessageText"
}
// EditMessageCaptionConfig allows you to modify the caption of a message.
type EditMessageCaptionConfig struct {
BaseEdit
Caption string
ReplyMarkup InlineKeyboardMarkup
}
func (config EditMessageCaptionConfig) values() (url.Values, error) {
v, _ := config.BaseEdit.values()
v.Add("caption", config.Caption)
return v, nil
}
func (config EditMessageCaptionConfig) method() string {
return "editMessageCaption"
}
// EditMessageReplyMarkup allows you to modify the reply markup
// of a message.
type EditMessageReplyMarkup struct {
BaseEdit
ReplyMarkup InlineKeyboardMarkup
}
func (config EditMessageReplyMarkup) values() (url.Values, error) {
return config.BaseEdit.values()
}
func (config EditMessageReplyMarkup) method() string {
return "editMessageReplyMarkup"
}
// UserProfilePhotosConfig contains information about a // UserProfilePhotosConfig contains information about a
// GetUserProfilePhotos request. // GetUserProfilePhotos request.
type UserProfilePhotosConfig struct { type UserProfilePhotosConfig struct {