2023-05-26 09:43:51 +08:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-06-14 22:10:01 +08:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2023-05-26 09:43:51 +08:00
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EditMessage make an editMessageText api request.
|
2023-06-14 22:10:01 +08:00
|
|
|
func (b *Bot) EditMessage(ctx context.Context, chatID, messageID int, text string, inlineKeyboards [][]InlineKeyboardButton) (*Message, error) {
|
2023-05-26 09:43:51 +08:00
|
|
|
formData := url.Values{
|
|
|
|
"message_id": {strconv.Itoa(messageID)},
|
|
|
|
"chat_id": {strconv.Itoa(chatID)},
|
|
|
|
"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 {
|
|
|
|
return nil, fmt.Errorf("fail to encode inlineKeyboard: %s", err)
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|