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{
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ type SendPhotoP struct {
|
|||||||
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) {
|
||||||
@@ -139,6 +140,7 @@ type EditMessageCaptionP struct {
|
|||||||
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