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