api_send_message.go 745 B

1234567891011121314151617181920212223242526272829303132
  1. package telegram
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. )
  7. // SendReplyMessage make a sendMessage api request.
  8. func (b *Bot) SendReplyMessage(ctx context.Context, chatID, replyID int64, text string) (*Message, error) {
  9. formData := url.Values{
  10. "chat_id": {strconv.FormatInt(chatID, 10)},
  11. "text": {text},
  12. }
  13. if replyID > 0 {
  14. formData.Set("reply_to_message_id", strconv.FormatInt(replyID, 10))
  15. }
  16. var result Message
  17. err := b.postForm(ctx, "/sendMessage", formData, &result)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return &result, nil
  22. }
  23. // SendMessage make a sendMessage api request.
  24. func (b *Bot) SendMessage(ctx context.Context, chatID int64, text string) (*Message, error) {
  25. return b.SendReplyMessage(ctx, chatID, 0, text)
  26. }