2023-05-26 04:43:51 +03:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-06-14 17:10:01 +03:00
|
|
|
"encoding/json"
|
2023-05-26 04:43:51 +03:00
|
|
|
"net/url"
|
|
|
|
"strconv"
|
2023-09-17 17:55:13 +03:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2023-05-26 04:43:51 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// EditMessage make an editMessageText api request.
|
2023-09-06 16:14:07 +03:00
|
|
|
func (b *Bot) EditMessage(ctx context.Context, chatID, messageID int64, text string, inlineKeyboards [][]InlineKeyboardButton) (*Message, error) {
|
2023-05-26 04:43:51 +03:00
|
|
|
formData := url.Values{
|
2023-09-06 16:14:07 +03:00
|
|
|
"message_id": {strconv.FormatInt(messageID, 10)},
|
|
|
|
"chat_id": {strconv.FormatInt(chatID, 10)},
|
2023-05-26 04:43:51 +03:00
|
|
|
"text": {text},
|
|
|
|
}
|
|
|
|
|
2023-06-14 17:10:01 +03:00
|
|
|
if len(inlineKeyboards) > 0 {
|
|
|
|
var markup struct {
|
|
|
|
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
|
|
|
|
}
|
|
|
|
markup.InlineKeyboard = inlineKeyboards
|
|
|
|
data, err := json.Marshal(markup)
|
|
|
|
if err != nil {
|
2023-09-17 17:55:13 +03:00
|
|
|
return nil, errors.Wrap(err, "fail to encode inlineKeyboard")
|
2023-06-14 17:10:01 +03:00
|
|
|
}
|
|
|
|
formData.Set("reply_markup", string(data))
|
|
|
|
}
|
|
|
|
|
2023-05-26 04:43:51 +03:00
|
|
|
var result Message
|
2023-05-29 14:49:05 +03:00
|
|
|
err := b.postForm(ctx, "/editMessageText", formData, &result)
|
2023-05-26 04:43:51 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &result, nil
|
|
|
|
}
|