photo keyboard
This commit is contained in:
43
bot.go
43
bot.go
@@ -370,6 +370,31 @@ func (ctx *MsgContext) EditCallbackf(format string, keyboard *InlineKeyboard, ar
|
|||||||
return ctx.EditCallback(fmt.Sprintf(format, args...), keyboard)
|
return ctx.EditCallback(fmt.Sprintf(format, args...), keyboard)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *MsgContext) editPhotoText(messageId int, text string, kb *InlineKeyboard) *AnswerMessage {
|
||||||
|
params := &EditMessageCaptionP{
|
||||||
|
ChatID: ctx.Msg.Chat.ID,
|
||||||
|
MessageID: messageId,
|
||||||
|
Caption: text,
|
||||||
|
ParseMode: ParseMD,
|
||||||
|
}
|
||||||
|
if kb != nil {
|
||||||
|
params.ReplyMarkup = kb.Get()
|
||||||
|
}
|
||||||
|
msg, err := ctx.Bot.EditMessageCaption(params)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Bot.logger.Error(err)
|
||||||
|
}
|
||||||
|
return &AnswerMessage{
|
||||||
|
MessageID: msg.MessageID, ctx: ctx, Text: text, IsMedia: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *AnswerMessage) EditCaption(text string) *AnswerMessage {
|
||||||
|
return m.ctx.editPhotoText(m.MessageID, text, nil)
|
||||||
|
}
|
||||||
|
func (m *AnswerMessage) EditCaptionKeyboard(text string, kb *InlineKeyboard) *AnswerMessage {
|
||||||
|
return m.ctx.editPhotoText(m.MessageID, text, kb)
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *MsgContext) answer(text string, keyboard *InlineKeyboard) *AnswerMessage {
|
func (ctx *MsgContext) answer(text string, keyboard *InlineKeyboard) *AnswerMessage {
|
||||||
params := &SendMessageP{
|
params := &SendMessageP{
|
||||||
ChatID: ctx.Msg.Chat.ID,
|
ChatID: ctx.Msg.Chat.ID,
|
||||||
@@ -399,20 +424,30 @@ func (ctx *MsgContext) Keyboard(text string, kb *InlineKeyboard) *AnswerMessage
|
|||||||
return ctx.answer(text, kb)
|
return ctx.answer(text, kb)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *MsgContext) AnswerPhoto(photoId string, text string) *AnswerMessage {
|
func (ctx *MsgContext) answerPhoto(photoId, text string, kb *InlineKeyboard) *AnswerMessage {
|
||||||
_, err := ctx.Bot.SendPhoto(&SendPhotoP{
|
params := &SendPhotoP{
|
||||||
ChatID: ctx.Msg.Chat.ID,
|
ChatID: ctx.Msg.Chat.ID,
|
||||||
Caption: text,
|
Caption: text,
|
||||||
Photo: photoId,
|
Photo: photoId,
|
||||||
ParseMode: ParseMD,
|
ParseMode: ParseMD,
|
||||||
})
|
}
|
||||||
|
if kb != nil {
|
||||||
|
params.ReplyMarkup = kb.Get()
|
||||||
|
}
|
||||||
|
msg, err := ctx.Bot.SendPhoto(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Bot.logger.Error(err)
|
ctx.Bot.logger.Error(err)
|
||||||
}
|
}
|
||||||
return &AnswerMessage{
|
return &AnswerMessage{
|
||||||
MessageID: ctx.Msg.MessageID, ctx: ctx, IsMedia: true, Text: text,
|
MessageID: msg.MessageID, ctx: ctx, Text: text, IsMedia: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func (ctx *MsgContext) AnswerPhoto(photoId, text string) *AnswerMessage {
|
||||||
|
return ctx.answerPhoto(photoId, text, nil)
|
||||||
|
}
|
||||||
|
func (ctx *MsgContext) AnswerPhotoKeyboard(photoId, text string, kb *InlineKeyboard) *AnswerMessage {
|
||||||
|
return ctx.answerPhoto(photoId, text, kb)
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *MsgContext) delete(messageId int) {
|
func (ctx *MsgContext) delete(messageId int) {
|
||||||
_, err := ctx.Bot.DeleteMessage(&DeleteMessageP{
|
_, err := ctx.Bot.DeleteMessage(&DeleteMessageP{
|
||||||
|
|||||||
40
methods.go
40
methods.go
@@ -87,19 +87,20 @@ func (b *Bot) SendMessage(params *SendMessageP) (*Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SendPhotoP struct {
|
type SendPhotoP struct {
|
||||||
BusinessConnectionID string `json:"business_connection_id,omitempty"`
|
BusinessConnectionID string `json:"business_connection_id,omitempty"`
|
||||||
ChatID int `json:"chat_id"`
|
ChatID int `json:"chat_id"`
|
||||||
MessageThreadID int `json:"message_thread_id,omitempty"`
|
MessageThreadID int `json:"message_thread_id,omitempty"`
|
||||||
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
||||||
Photo string `json:"photo"`
|
Photo string `json:"photo"`
|
||||||
Caption string `json:"caption,omitempty"`
|
Caption string `json:"caption,omitempty"`
|
||||||
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
|
||||||
ShowCaptionAboveMedia bool `json:"show_caption_above_media"`
|
ShowCaptionAboveMedia bool `json:"show_caption_above_media"`
|
||||||
HasSpoiler bool `json:"has_spoiler"`
|
HasSpoiler bool `json:"has_spoiler"`
|
||||||
DisableNotifications bool `json:"disable_notifications,omitempty"`
|
DisableNotifications bool `json:"disable_notifications,omitempty"`
|
||||||
ProtectContent bool `json:"protect_content,omitempty"`
|
ProtectContent bool `json:"protect_content,omitempty"`
|
||||||
AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"`
|
AllowPaidBroadcast bool `json:"allow_paid_broadcast,omitempty"`
|
||||||
MessageEffectID string `json:"message_effect_id,omitempty"`
|
MessageEffectID string `json:"message_effect_id,omitempty"`
|
||||||
|
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) SendPhoto(params *SendPhotoP) (*Message, error) {
|
func (b *Bot) SendPhoto(params *SendPhotoP) (*Message, error) {
|
||||||
@@ -133,12 +134,13 @@ func (b *Bot) EditMessageText(params *EditMessageTextP) (*Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EditMessageCaptionP struct {
|
type EditMessageCaptionP struct {
|
||||||
BusinessConnectionID string `json:"business_connection_id,omitempty"`
|
BusinessConnectionID string `json:"business_connection_id,omitempty"`
|
||||||
ChatID int `json:"chat_id,omitempty"`
|
ChatID int `json:"chat_id,omitempty"`
|
||||||
MessageID int `json:"message_id,omitempty"`
|
MessageID int `json:"message_id,omitempty"`
|
||||||
InlineMessageID string `json:"inline_message_id,omitempty"`
|
InlineMessageID string `json:"inline_message_id,omitempty"`
|
||||||
Caption string `json:"caption"`
|
Caption string `json:"caption"`
|
||||||
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
ParseMode ParseMode `json:"parse_mode,omitempty"`
|
||||||
|
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) EditMessageCaption(params *EditMessageCaptionP) (*Message, error) {
|
func (b *Bot) EditMessageCaption(params *EditMessageCaptionP) (*Message, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user