Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
fwzookeeper/vendor/gitlab.com/toby3d/telegram/send_photo.go

86 lines
2.6 KiB
Go
Raw Normal View History

2018-11-29 20:32:51 +04:00
package telegram
import (
"strconv"
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
// SendPhotoParameters represents data for SendPhoto method.
type SendPhotoParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Photo to send. Pass a file_id as String to send a photo that exists on the
// Telegram servers (recommended), pass an HTTP URL as a String for Telegram
// to get a photo from the Internet, or upload a new photo using
// multipart/form-data.
Photo InputFile `json:"photo"`
// Photo caption (may also be used when resending photos by file_id), 0-200
// characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Disables link previews for links in this message
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
// Sends the message silently. Users will receive a notification with no
// sound.
DisableNotification bool `json:"disable_notification,omitempty"`
// If the message is a reply, ID of the original message
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
// Additional interface options. A JSON-serialized object for an inline
// keyboard, custom reply keyboard, instructions to remove reply keyboard or
// to force a reply from the user.
ReplyMarkup interface{} `json:"reply_markup,omitempty"`
}
// NewPhoto creates SendPhotoParameters only with required parameters.
func NewPhoto(chatID int64, photo interface{}) *SendPhotoParameters {
return &SendPhotoParameters{
ChatID: chatID,
Photo: photo,
}
}
// SendPhoto send photos. On success, the sent Message is returned.
func (bot *Bot) SendPhoto(params *SendPhotoParameters) (msg *Message, err error) {
args := http.AcquireArgs()
defer http.ReleaseArgs(args)
args.Add("chat_id", strconv.FormatInt(params.ChatID, 10))
if params.Caption != "" {
args.Add("caption", params.Caption)
}
if params.ReplyMarkup != nil {
dst, err := json.Marshal(params.ReplyMarkup)
if err != nil {
return nil, err
}
args.Add("reply_markup", string(dst))
}
if params.ReplyToMessageID != 0 {
args.Add("reply_to_message_id", strconv.Itoa(params.ReplyToMessageID))
}
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
resp, err := bot.Upload(MethodSendPhoto, "photo", "", params.Photo, args)
if err != nil {
return
}
msg = new(Message)
err = json.Unmarshal(*resp.Result, msg)
return
}