2023-05-26 09:43:51 +08:00
|
|
|
package telegram
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SendReplyMessage make a sendMessage api request.
|
2023-09-06 21:14:07 +08:00
|
|
|
func (b *Bot) SendReplyMessage(ctx context.Context, chatID, replyID int64, text string) (*Message, error) {
|
2023-05-26 09:43:51 +08:00
|
|
|
formData := url.Values{
|
2023-09-13 21:36:43 +08:00
|
|
|
"chat_id": {strconv.FormatInt(chatID, 10)},
|
|
|
|
"text": {text},
|
|
|
|
}
|
|
|
|
|
|
|
|
if replyID > 0 {
|
|
|
|
formData.Set("reply_to_message_id", strconv.FormatInt(replyID, 10))
|
2023-05-26 09:43:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var result Message
|
2023-05-29 19:49:05 +08:00
|
|
|
err := b.postForm(ctx, "/sendMessage", formData, &result)
|
2023-05-26 09:43:51 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &result, nil
|
|
|
|
}
|
2023-09-13 21:36:43 +08:00
|
|
|
|
|
|
|
// SendMessage make a sendMessage api request.
|
|
|
|
func (b *Bot) SendMessage(ctx context.Context, chatID int64, text string) (*Message, error) {
|
|
|
|
return b.SendReplyMessage(ctx, chatID, 0, text)
|
|
|
|
}
|