1
0
Fork 0

โ™ป๏ธ Refactoring code

This commit is contained in:
Maxim Lebedev 2020-01-09 20:27:00 +05:00
parent 7659fbb9f5
commit 82e84ed718
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
37 changed files with 8503 additions and 7216 deletions

56
add.go
View File

@ -1,56 +0,0 @@
package telegram
import (
"strings"
http "github.com/valyala/fasthttp"
)
type AddStickerToSetParameters struct {
// User identifier of sticker set owner
UserID int `json:"user_id"`
// Sticker set name
Name string `json:"name"`
// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More info on Sending Files ยป
PNGSticker interface{} `json:"png_sticker"`
// One or more emoji corresponding to the sticker
Emojis string `json:"emojis"`
// A JSON-serialized object for position where the mask should be placed on faces
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
}
// AddStickerToSet add a new sticker to a set created by the bot. Returns True
// on success.
func (b *Bot) AddStickerToSet(params *AddStickerToSetParameters) (bool, error) {
args := http.AcquireArgs()
defer http.ReleaseArgs(args)
args.SetUint("user_id", params.UserID)
if !strings.HasSuffix(strings.ToLower(params.Name), strings.ToLower("_by_"+b.Username)) {
params.Name = params.Name + "_by_" + b.Username
}
args.Set("emojis", params.Emojis)
if params.MaskPosition != nil {
mp, err := parser.Marshal(params.MaskPosition)
if err != nil {
return false, err
}
args.SetBytesV("mask_position", mp)
}
resp, err := b.Upload(MethodAddStickerToSet, TypeSticker, "sticker", params.PNGSticker, args)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

227
answer.go
View File

@ -1,227 +0,0 @@
package telegram
type (
// AnswerCallbackQueryParameters represents data for AnswerCallbackQuery method.
AnswerCallbackQueryParameters struct {
// Unique identifier for the query to be answered
CallbackQueryID string `json:"callback_query_id"`
// Text of the notification. If not specified, nothing will be shown to the
// user, 0-200 characters
Text string `json:"text,omitempty"`
// URL that will be opened by the user's client. If you have created a Game
// and accepted the conditions via @Botfather, specify the URL that opens
// your game โ€“ note that this will only work if the query comes from a
// callback_game button.
//
// Otherwise, you may use links like t.me/your_bot?start=XXXX that open your
// bot with a parameter.
URL string `json:"url,omitempty"`
// If true, an alert will be shown by the client instead of a notification at
// the top of the chat screen. Defaults to false.
ShowAlert bool `json:"show_alert,omitempty"`
// The maximum amount of time in seconds that the result of the callback
// query may be cached client-side. Telegram apps will support caching
// starting in version 3.14. Defaults to 0.
CacheTime int `json:"cache_time,omitempty"`
}
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery
// method.
AnswerPreCheckoutQueryParameters struct {
// Unique identifier for the query to be answered
PreCheckoutQueryID string `json:"pre_checkout_query_id"`
// Required if ok is False. Error message in human readable form that
// explains the reason for failure to proceed with the checkout (e.g. "Sorry,
// somebody just bought the last of our amazing black T-shirts while you were
// busy filling out your payment details. Please choose a different color or
// garment!"). Telegram will display this message to the user.
ErrorMessage string `json:"error_message,omitempty"`
// Specify True if everything is alright (goods are available, etc.) and the
// bot is ready to proceed with the order. Use False if there are any
// problems.
Ok bool `json:"ok"`
}
// AnswerShippingQueryParameters represents data for AnswerShippingQuery method.
AnswerShippingQueryParameters struct {
// Unique identifier for the query to be answered
ShippingQueryID string `json:"shipping_query_id"`
// Required if ok is False. Error message in human readable form that
// explains why it is impossible to complete the order (e.g. "Sorry, delivery
// to your desired address is unavailable'). Telegram will display this
// message to the user.
ErrorMessage string `json:"error_message,omitempty"`
// Specify True if delivery to the specified address is possible and False
// if there are any problems (for example, if delivery to the specified
// address is not possible)
Ok bool `json:"ok"`
// Required if ok is True. A JSON-serialized array of available shipping
// options.
ShippingOptions []ShippingOption `json:"shipping_options,omitempty"`
}
// AnswerInlineQueryParameters represents data for AnswerInlineQuery method.
AnswerInlineQueryParameters struct {
// Unique identifier for the answered query
InlineQueryID string `json:"inline_query_id"`
// Pass the offset that a client should send in the next query with the same
// text to receive more results. Pass an empty string if there are no more
// results or if you donโ€˜t support pagination. Offset length canโ€™t exceed 64
// bytes.
NextOffset string `json:"next_offset,omitempty"`
// If passed, clients will display a button with specified text that switches
// the user to a private chat with the bot and sends the bot a start message
// with the parameter switch_pm_parameter
SwitchPrivateMessageText string `json:"switch_pm_text,omitempty"`
// Deep-linking parameter for the /start message sent to the bot when user
// presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and -
// are allowed.
SwitchPrivateMessageParameter string `json:"switch_pm_parameter,omitempty"`
// A JSON-serialized array of results for the inline query
Results []interface{} `json:"results"`
// The maximum amount of time in seconds that the result of the inline query
// may be cached on the server. Defaults to 300.
CacheTime int `json:"cache_time,omitempty"`
// Pass True, if results may be cached on the server side only for the user
// that sent the query. By default, results may be returned to any user who
// sends the same query
IsPersonal bool `json:"is_personal,omitempty"`
}
)
// NewAnswerCallbackQuery creates AnswerCallbackQueryParameters only with
// required parameters.
func NewAnswerCallbackQuery(callbackQueryID string) *AnswerCallbackQueryParameters {
return &AnswerCallbackQueryParameters{CallbackQueryID: callbackQueryID}
}
// NewAnswerPreCheckoutQuery creates AnswerPreCheckoutQueryParameters only with
// required parameters.
func NewAnswerPreCheckoutQuery(preCheckoutQueryID string, ok bool) *AnswerPreCheckoutQueryParameters {
return &AnswerPreCheckoutQueryParameters{
PreCheckoutQueryID: preCheckoutQueryID,
Ok: ok,
}
}
// NewAnswerShippingQuery creates AnswerShippingQueryParameters only with
// required parameters.
func NewAnswerShippingQuery(shippingQueryID string, ok bool) *AnswerShippingQueryParameters {
return &AnswerShippingQueryParameters{
ShippingQueryID: shippingQueryID,
Ok: ok,
}
}
// NewAnswerInlineQuery creates AnswerInlineQueryParameters only with required
// parameters.
func NewAnswerInlineQuery(inlineQueryID string, results ...interface{}) *AnswerInlineQueryParameters {
return &AnswerInlineQueryParameters{
InlineQueryID: inlineQueryID,
Results: results,
}
}
// AnswerCallbackQuery send answers to callback queries sent from inline
// keyboards. The answer will be displayed to the user as a notification at the
// top of the chat screen or as an alert. On success, True is returned.
//
// Alternatively, the user can be redirected to the specified Game URL. For this
// option to work, you must first create a game for your bot via @Botfather and
// accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX
// that open your bot with a parameter.
func (bot *Bot) AnswerCallbackQuery(params *AnswerCallbackQueryParameters) (bool, error) {
dst, err := parser.Marshal(params)
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodAnswerCallbackQuery)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// AnswerPreCheckoutQuery respond to such pre-checkout queries.
//
// Once the user has confirmed their payment and shipping details, the Bot API
// sends the final confirmation in the form of an Update with the field
// pre_checkout_query. Use this method to respond to such pre-checkout queries.
// On success, True is returned.
//
// Note: The Bot API must receive an answer within 10 seconds after the
// pre-checkout query was sent.
func (bot *Bot) AnswerPreCheckoutQuery(params *AnswerShippingQueryParameters) (bool, error) {
dst, err := parser.Marshal(params)
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodAnswerPreCheckoutQuery)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// AnswerShippingQuery reply to shipping queries.
//
// If you sent an invoice requesting a shipping address and the parameter
// is_flexible was specified, the Bot API will send an Update with a
// shipping_query field to the bot. On success, True is returned.
func (bot *Bot) AnswerShippingQuery(params *AnswerShippingQueryParameters) (bool, error) {
dst, err := parser.Marshal(params)
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodAnswerShippingQuery)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// AnswerInlineQuery send answers to an inline query. On success, True is returned.
//
// No more than 50 results per query are allowed.
func (bot *Bot) AnswerInlineQuery(params *AnswerInlineQueryParameters) (bool, error) {
dst, err := parser.Marshal(params)
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodAnswerInlineQuery)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

View File

@ -1,7 +1,9 @@
package telegram
import "github.com/Masterminds/semver"
// Version represents current version of Telegram API supported by this package
const Version string = "4.4"
var Version = semver.MustParse("4.5.0")
// Action represents available and supported status actions of bot
const (
@ -25,14 +27,14 @@ const (
ChatSuperGroup string = "supergroup"
)
// Command represents global commands which should be supported by any bot.
// Command represents global commands which should be supported by any b.
// You can user IsCommandEqual method of Message for checking.
//
// See: https://core.telegram.org/bots#global-commands
const (
CommandStart string = "start"
CommandHelp string = "help"
CommandSettings string = "settings"
CommandStart string = "start"
)
// Entity represents available and supported entity types
@ -131,6 +133,13 @@ const (
ParseModeMarkdownV2 string = "MarkdownV2"
)
const (
PointForehead string = "forehead"
PointEyes string = "eyes"
PointMouth string = "mouth"
PointChin string = "chin"
)
// Mime represents available and supported MIME types of data
const (
MimeHTML string = "text/html"
@ -198,3 +207,8 @@ const (
UpdatePreCheckoutQuery string = "pre_checkout_query"
UpdateShippingQuery string = "shipping_query"
)
const (
DefaultAudioSeparator = " โ€“ "
DefaultAudioTitle = "[untitled]"
)

View File

@ -1,76 +0,0 @@
package telegram
import (
"strconv"
"strings"
http "github.com/valyala/fasthttp"
)
type CreateNewStickerSetParameters struct {
// User identifier of created sticker set owner
UserID int `json:"user_id"`
// Short name of sticker set, to be used in t.me/addstickers/ URLs
// (e.g., animals). Can contain only english letters, digits and
// underscores. Must begin with a letter, can't contain consecutive
// underscores and must end in โ€œ_by_<bot username>โ€. <bot_username>
// is case insensitive. 1-64 characters.
Name string `json:"name"`
// Sticker set title, 1-64 characters
Title string `json:"title"`
// Png image with the sticker, must be up to 512 kilobytes in size,
// dimensions must not exceed 512px, and either width or height must
// be exactly 512px. Pass a file_id as a String to send a file that
// already exists on the Telegram servers, pass an HTTP URL as a
// String for Telegram to get a file from the Internet, or upload
// a new one using multipart/form-data.
PNGSticker interface{} `json:"png_sticker"`
// One or more emoji corresponding to the sticker
Emojis string `json:"emojis"`
// Pass True, if a set of mask stickers should be created
ContainsMasks bool `json:"contains_masks,omitempty"`
// A JSON-serialized object for position where the mask should be
// placed on faces
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
}
// CreateNewStickerSet create new sticker set owned by a user. The bot will be
// able to edit the created sticker set. Returns True on success.
func (b *Bot) CreateNewStickerSet(params *CreateNewStickerSetParameters) (bool, error) {
args := http.AcquireArgs()
defer http.ReleaseArgs(args)
args.SetUint("user_id", params.UserID)
if !strings.HasSuffix(strings.ToLower(params.Name), strings.ToLower("_by_"+b.Username)) {
params.Name = params.Name + "_by_" + b.Username
}
args.Set("name", params.Name)
args.Set("title", params.Title)
args.Set("emojis", params.Emojis)
args.Set("contains_masks", strconv.FormatBool(params.ContainsMasks))
if params.MaskPosition != nil {
mp, err := parser.Marshal(params.MaskPosition)
if err != nil {
return false, err
}
args.SetBytesV("mask_position", mp)
}
resp, err := b.Upload(MethodCreateNewStickerSet, TypeSticker, "sticker", params.PNGSticker, args)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

129
delete.go
View File

@ -1,129 +0,0 @@
package telegram
type (
// DeleteChatPhotoParameters represents data for DeleteChatPhoto method.
DeleteChatPhotoParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
}
// DeleteChatStickerSetParameters represents data for DeleteChatStickerSet method.
DeleteChatStickerSetParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
}
// DeleteMessageParameters represents data for DeleteMessage method.
DeleteMessageParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Identifier of the message to delete
MessageID int `json:"message_id"`
}
// DeleteStickerFromSetParameters represents data for DeleteStickerFromSet method.
DeleteStickerFromSetParameters struct {
// File identifier of the sticker
Sticker string `json:"sticker"`
}
)
// DeleteChatPhoto delete a chat photo. Photos can't be changed for private
// chats. The bot must be an administrator in the chat for this to work and must
// have the appropriate admin rights. Returns True on success.
//
// Note: In regular groups (non-supergroups), this method will only work if the
// 'All Members Are Admins' setting is off in the target group.
func (bot *Bot) DeleteChatPhoto(chatID int64) (bool, error) {
dst, err := parser.Marshal(&DeleteChatPhotoParameters{ChatID: chatID})
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodDeleteChatPhoto)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// DeleteChatStickerSet delete a group sticker set from a supergroup. The bot must be an administrator
// in the chat for this to work and must have the appropriate admin rights. Use the field
// can_set_sticker_set optionally returned in getChat requests to check if the bot can use this
// method. Returns True on success.
func (bot *Bot) DeleteChatStickerSet(chatID int64) (bool, error) {
dst, err := parser.Marshal(&DeleteChatStickerSetParameters{ChatID: chatID})
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodDeleteChatStickerSet)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// DeleteWebhook remove webhook integration if you decide to switch back to
// getUpdates. Returns True on success. Requires no parameters.
func (bot *Bot) DeleteWebhook() (bool, error) {
resp, err := bot.request(nil, MethodDeleteWebhook)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// DeleteMessage delete a message, including service messages, with the following
// limitations: A message can only be deleted if it was sent less than 48 hours
// ago; Bots can delete outgoing messages in groups and supergroups; Bots granted
// can_post_messages permissions can delete outgoing messages in channels; If the
// bot is an administrator of a group, it can delete any message there; If the
// bot has can_delete_messages permission in a supergroup or a channel, it can
// delete any message there. Returns True on success.
func (bot *Bot) DeleteMessage(chatID int64, messageID int) (bool, error) {
dst, err := parser.Marshal(&DeleteMessageParameters{
ChatID: chatID,
MessageID: messageID,
})
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodDeleteMessage)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// DeleteStickerFromSet delete a sticker from a set created by the bot. Returns
// True on success.
func (bot *Bot) DeleteStickerFromSet(sticker string) (bool, error) {
dst, err := parser.Marshal(&DeleteStickerFromSetParameters{Sticker: sticker})
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodDeleteStickerFromSet)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

29
errors.go Normal file
View File

@ -0,0 +1,29 @@
package telegram
import (
"fmt"
"golang.org/x/xerrors"
)
type Error struct {
Code int `json:"error_code"`
Description string `json:"description"`
Parameters []*ResponseParameters `json:"parameters,omitempty"`
frame xerrors.Frame
}
func (e Error) FormatError(p xerrors.Printer) error {
p.Printf("%d %s", e.Code, e.Description)
e.frame.Format(p)
return nil
}
func (e Error) Format(s fmt.State, r rune) {
xerrors.FormatError(e, s, r)
}
func (e Error) Error() string {
return fmt.Sprint(e)
}

View File

@ -1,26 +0,0 @@
package telegram
// ExportChatInviteLinkParameters represents data for ExportChatInviteLink method.
type ExportChatInviteLinkParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
}
// ExportChatInviteLink export an invite link to a supergroup or a channel. The
// bot must be an administrator in the chat for this to work and must have the
// appropriate admin rights. Returns exported invite link as String on success.
func (bot *Bot) ExportChatInviteLink(chatID int64) (string, error) {
dst, err := parser.Marshal(&ExportChatInviteLinkParameters{ChatID: chatID})
if err != nil {
return "", err
}
resp, err := bot.request(dst, MethodExportChatInviteLink)
if err != nil {
return "", err
}
var inviteLink string
err = parser.Unmarshal(resp.Result, &inviteLink)
return inviteLink, err
}

View File

@ -1,45 +0,0 @@
package telegram
// ForwardMessageParameters represents data for ForwardMessage method.
type ForwardMessageParameters struct {
// Unique identifier for the target chat or username of the target
// channel (in the format @channelusername)
ChatID int64 `json:"chat_id"`
// Unique identifier for the chat where the original message was sent
// (or channel username in the format @channelusername)
FromChatID int64 `json:"from_chat_id"`
// Sends the message silently. Users will receive a notification with no
// sound.
DisableNotification bool `json:"disable_notification,omitempty"`
// Message identifier in the chat specified in from_chat_id
MessageID int `json:"message_id"`
}
// NewForwardMessage creates ForwardMessageParameters only with reqired parameters.
func NewForwardMessage(from, to int64, messageID int) *ForwardMessageParameters {
return &ForwardMessageParameters{
FromChatID: from,
ChatID: to,
MessageID: messageID,
}
}
// ForwardMessage forward messages of any kind. On success, the sent Message is returned.
func (bot *Bot) ForwardMessage(params *ForwardMessageParameters) (*Message, error) {
dst, err := parser.Marshal(params)
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodForwardMessage)
if err != nil {
return nil, err
}
var msg Message
err = parser.Unmarshal(resp.Result, &msg)
return &msg, err
}

165
games.go Normal file
View File

@ -0,0 +1,165 @@
package telegram
type (
// Game represents a game. Use BotFather to create and edit games, their short names will act as unique
// identifiers.
Game struct {
// Title of the game
Title string `json:"title"`
// Description of the game
Description string `json:"description"`
// Brief description of the game or high scores included in the game message. Can be automatically
// edited to include current high scores for the game when the bot calls setGameScore, or manually
// edited using editMessageText. 0-4096 characters.
Text string `json:"text,omitempty"`
// Photo that will be displayed in the game message in chats.
Photo []*PhotoSize `json:"photo"`
// Special entities that appear in text, such as usernames, URLs, bot commands, etc.
TextEntities []*MessageEntity `json:"text_entities,omitempty"`
// Animation that will be displayed in the game message in chats. Upload via BotFather
Animation *Animation `json:"animation,omitempty"`
}
// CallbackGame a placeholder, currently holds no information. Use BotFather to set up your game.
CallbackGame struct{}
// GameHighScore represents one row of the high scores table for a game.
GameHighScore struct {
// Position in high score table for the game
Position int `json:"position"`
// Score
Score int `json:"score"`
// User
User *User `json:"user"`
}
// SendGameParameters represents data for SendGame method.
SendGame struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Short name of the game, serves as the unique identifier for the game. Set up your games via
// Botfather.
GameShortName string `json:"game_short_name"`
// 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"`
// A JSON-serialized object for an inline keyboard. If empty, one โ€˜Play game_titleโ€™ button will be
// shown. If not empty, the first button must launch the game.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// SetGameScoreParameters represents data for SetGameScore method.
SetGameScore struct {
// User identifier
UserID int `json:"user_id"`
// New score, must be non-negative
Score int `json:"score"`
// Required if inline_message_id is not specified. Identifier of the sent message
MessageID int `json:"message_id,omitempty"`
// Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or
// banning cheaters
Force bool `json:"force,omitempty"`
// Pass True, if the game message should not be automatically edited to include the current scoreboard
DisableEditMessage bool `json:"disable_edit_message,omitempty"`
// Required if inline_message_id is not specified. Unique identifier for the target chat
ChatID int64 `json:"chat_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
}
// GetGameHighScoresParameters represents data for GetGameHighScores method.
GetGameHighScores struct {
// Target user id
UserID int `json:"user_id"`
// Required if inline_message_id is not specified. Identifier of the sent message
MessageID int `json:"message_id,omitempty"`
// Required if inline_message_id is not specified. Unique identifier for the target chat
ChatID int64 `json:"chat_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
}
)
// SendGame send a game. On success, the sent Message is returned.
func (b *Bot) SendGame(p SendGame) (*Message, error) {
src, err := b.Do(MethodSendGame, p)
if err != nil {
return nil, err
}
resp := new(Response)
if err = b.marshler.Unmarshal(src, resp); err != nil {
return nil, err
}
result := new(Message)
if err = b.marshler.Unmarshal(resp.Result, result); err != nil {
return nil, err
}
return result, nil
}
// SetGameScore set the score of the specified user in a game. On success, if the message was sent by the bot, returns
// the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's
// current score in the chat and force is False.
func (b *Bot) SetGameScore(p SetGameScore) (*Message, error) {
src, err := b.Do(MethodSetGameScore, p)
if err != nil {
return nil, err
}
resp := new(Response)
if err = b.marshler.Unmarshal(src, resp); err != nil {
return nil, err
}
result := new(Message)
if err = b.marshler.Unmarshal(resp.Result, result); err != nil {
return nil, err
}
return result, nil
}
// GetGameHighScores get data for high score tables. Will return the score of the specified user and several of his
// neighbors in a game. On success, returns an Array of GameHighScore objects.
func (b *Bot) GetGameHighScores(p GetGameHighScores) ([]*GameHighScore, error) {
src, err := b.Do(MethodGetGameHighScores, p)
if err != nil {
return nil, err
}
resp := new(Response)
if err = b.marshler.Unmarshal(src, resp); err != nil {
return nil, err
}
result := make([]*GameHighScore, 0)
if err = b.marshler.Unmarshal(resp.Result, &result); err != nil {
return nil, err
}
return result, nil
}

314
get.go
View File

@ -1,314 +0,0 @@
package telegram
type (
// GetChatParameters represents data for GetChat method.
GetChatParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
}
// GetChatAdministratorsParameters represents data for GetChatAdministrators
// method.
GetChatAdministratorsParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
}
// GetChatMemberParameters represents data for GetChatMember method.
GetChatMemberParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Unique identifier of the target user
UserID int `json:"user_id"`
}
// GetChatMembersCountParameters represents data for GetChatMembersCount method.
GetChatMembersCountParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
}
// GetFileParameters represents data for GetFile method.
GetFileParameters struct {
// File identifier to get info about
FileID string `json:"file_id"`
}
// GetUpdatesParameters represents data for GetUpdates method.
GetUpdatesParameters struct {
// Identifier of the first update to be returned. Must be greater by one than the highest among the
// identifiers of previously received updates. By default, updates starting with the earliest unconfirmed
// update are returned. An update is considered confirmed as soon as getUpdates is called with an offset
// higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset
// update from the end of the updates queue. All previous updates will forgotten.
Offset int `json:"offset,omitempty"`
// Limits the number of updates to be retrieved. Values between 1โ€”100 are accepted. Defaults to 100.
Limit int `json:"limit,omitempty"`
// Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short
// polling should be used for testing purposes only.
Timeout int `json:"timeout,omitempty"`
// List the types of updates you want your bot to receive. For example, specify ["message",
// "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete
// list of available update types. Specify an empty list to receive all updates regardless of type (default).
// If not specified, the previous setting will be used.
//
// Please note that this parameter doesn't affect updates created before the call to the getUpdates, so
// unwanted updates may be received for a short period of time.
AllowedUpdates []string `json:"allowed_updates,omitempty"`
}
// GetUserProfilePhotosParameters represents data for GetUserProfilePhotos method.
GetUserProfilePhotosParameters struct {
// Unique identifier of the target user
UserID int `json:"user_id"`
// Sequential number of the first photo to be returned. By default, all
// photos are returned.
Offset int `json:"offset,omitempty"`
// Limits the number of photos to be retrieved. Values between 1โ€”100 are
// accepted. Defaults to 100.
Limit int `json:"limit,omitempty"`
}
// GetGameHighScoresParameters represents data for GetGameHighScores method.
GetGameHighScoresParameters struct {
// Target user id
UserID int `json:"user_id"`
// Required if inline_message_id is not specified. Identifier of the sent
// message
MessageID int `json:"message_id,omitempty"`
// Required if inline_message_id is not specified. Unique identifier for the
// target chat
ChatID int64 `json:"chat_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the
// inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
}
// GetStickerSetParameters represents data for GetStickerSet method.
GetStickerSetParameters struct {
// Name of the sticker set
Name string `json:"name"`
}
)
// NewGameHighScores creates GetGameHighScoresParameters only with required parameters.
func NewGameHighScores(userID int) *GetGameHighScoresParameters {
return &GetGameHighScoresParameters{
UserID: userID,
}
}
// GetChat get up to date information about the chat (current name of the user
// for one-on-one conversations, current username of a user, group or channel,
// etc.). Returns a Chat object on success.
func (bot *Bot) GetChat(chatID int64) (*Chat, error) {
dst, err := parser.Marshal(&GetChatParameters{ChatID: chatID})
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodGetChat)
if err != nil {
return nil, err
}
var chat Chat
err = parser.Unmarshal(resp.Result, &chat)
return &chat, err
}
// GetChatAdministrators get a list of administrators in a chat. On success,
// returns an Array of ChatMember objects that contains information about all
// chat administrators except other bots. If the chat is a group or a supergroup
// and no administrators were appointed, only the creator will be returned.
func (bot *Bot) GetChatAdministrators(chatID int64) ([]ChatMember, error) {
dst, err := parser.Marshal(&GetChatAdministratorsParameters{ChatID: chatID})
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodGetChatAdministrators)
if err != nil {
return nil, err
}
var chatMembers []ChatMember
err = parser.Unmarshal(resp.Result, &chatMembers)
return chatMembers, err
}
// GetChatMember get information about a member of a chat. Returns a ChatMember
// object on success.
func (bot *Bot) GetChatMember(chatID int64, userID int) (*ChatMember, error) {
dst, err := parser.Marshal(&GetChatMemberParameters{
ChatID: chatID,
UserID: userID,
})
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodGetChatMember)
if err != nil {
return nil, err
}
var chatMember ChatMember
err = parser.Unmarshal(resp.Result, &chatMember)
return &chatMember, err
}
// GetChatMembersCount get the number of members in a chat. Returns Int on
// success.
func (bot *Bot) GetChatMembersCount(chatID int64) (int, error) {
dst, err := parser.Marshal(&GetChatMembersCountParameters{ChatID: chatID})
if err != nil {
return 0, err
}
resp, err := bot.request(dst, MethodGetChatMembersCount)
if err != nil {
return 0, err
}
var count int
err = parser.Unmarshal(resp.Result, &count)
return count, err
}
// GetFile get basic info about a file and prepare it for downloading. For the
// moment, bots can download files of up to 20MB in size. On success, a File
// object is returned. The file can then be downloaded via the link
// https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is
// taken from the response. It is guaranteed that the link will be valid for at
// least 1 hour. When the link expires, a new one can be requested by calling
// getFile again.
//
// Note: This function may not preserve the original file name and MIME type. You
// should save the file's MIME type and name (if available) when the File object
// is received.
func (bot *Bot) GetFile(fileID string) (*File, error) {
dst, err := parser.Marshal(&GetFileParameters{FileID: fileID})
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodGetFile)
if err != nil {
return nil, err
}
var file File
err = parser.Unmarshal(resp.Result, &file)
return &file, err
}
// GetMe testing your bot's auth token. Requires no parameters. Returns basic
// information about the bot in form of a User object.
func (bot *Bot) GetMe() (*User, error) {
resp, err := bot.request(nil, MethodGetMe)
if err != nil {
return nil, err
}
var me User
err = parser.Unmarshal(resp.Result, &me)
return &me, err
}
// GetUpdates receive incoming updates using long polling. An Array of Update objects is returned.
func (bot *Bot) GetUpdates(params *GetUpdatesParameters) ([]Update, error) {
if params == nil {
params = &GetUpdatesParameters{Limit: 100}
}
src, err := parser.Marshal(params)
if err != nil {
return nil, err
}
resp, err := bot.request(src, MethodGetUpdates)
if err != nil {
return nil, err
}
updates := make([]Update, params.Limit)
err = parser.Unmarshal(resp.Result, &updates)
return updates, err
}
// GetUserProfilePhotos get a list of profile pictures for a user. Returns a UserProfilePhotos object.
func (bot *Bot) GetUserProfilePhotos(params *GetUserProfilePhotosParameters) (*UserProfilePhotos, error) {
dst, err := parser.Marshal(params)
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodGetUserProfilePhotos)
if err != nil {
return nil, err
}
var photos UserProfilePhotos
err = parser.Unmarshal(resp.Result, &photos)
return &photos, err
}
// GetWebhookInfo get current webhook status. Requires no parameters. On success,
// returns a WebhookInfo object. If the bot is using getUpdates, will return an
// object with the url field empty.
func (bot *Bot) GetWebhookInfo() (*WebhookInfo, error) {
resp, err := bot.request(nil, MethodGetWebhookInfo)
if err != nil {
return nil, err
}
var info WebhookInfo
err = parser.Unmarshal(resp.Result, &info)
return &info, err
}
// GetGameHighScores get data for high score tables. Will return the score of the
// specified user and several of his neighbors in a game. On success, returns an
// Array of GameHighScore objects.
func (bot *Bot) GetGameHighScores(params *GetGameHighScoresParameters) ([]GameHighScore, error) {
dst, err := parser.Marshal(params)
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodGetGameHighScores)
if err != nil {
return nil, err
}
var scores []GameHighScore
err = parser.Unmarshal(resp.Result, &scores)
return scores, err
}
// GetStickerSet get a sticker set. On success, a StickerSet object is returned.
func (bot *Bot) GetStickerSet(name string) (*StickerSet, error) {
dst, err := parser.Marshal(&GetStickerSetParameters{Name: name})
if err != nil {
return nil, err
}
resp, err := bot.request(dst, MethodGetStickerSet)
if err != nil {
return nil, err
}
var set StickerSet
err = parser.Unmarshal(resp.Result, &set)
return &set, err
}

9
go.mod
View File

@ -3,14 +3,15 @@ module gitlab.com/toby3d/telegram
go 1.12
require (
github.com/json-iterator/go v1.1.7
github.com/Masterminds/semver v1.5.0
github.com/json-iterator/go v1.1.9
github.com/kirillDanshin/dlog v0.0.0-20170728000807-97d876b12bf9
github.com/kirillDanshin/myutils v0.0.0-20160713214838-182269b1fbcc // indirect
github.com/klauspost/compress v1.7.4 // indirect
github.com/klauspost/cpuid v1.2.1 // indirect
github.com/klauspost/compress v1.9.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/stretchr/testify v1.3.0
github.com/valyala/fasthttp v1.4.0
github.com/valyala/fasthttp v1.7.1
golang.org/x/text v0.3.2
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
)

26
go.sum
View File

@ -1,20 +1,19 @@
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kirillDanshin/dlog v0.0.0-20170728000807-97d876b12bf9 h1:mA7k8E2Vrmyj5CW/D1XZBFmohVNi7jf757vibGwzRbo=
github.com/kirillDanshin/dlog v0.0.0-20170728000807-97d876b12bf9/go.mod h1:l8CN7iyX1k2xlsTYVTpCtwBPcxThf/jLWDGVcF6T/bM=
github.com/kirillDanshin/myutils v0.0.0-20160713214838-182269b1fbcc h1:OkOhOn3WBUmfATC1NsA3rBlgHGkjk0KGnR5akl/8uXc=
github.com/kirillDanshin/myutils v0.0.0-20160713214838-182269b1fbcc/go.mod h1:Bt95qRxLvpdmASW9s2tTxGdQ5ma4o4n8QFhCvzCew/M=
github.com/klauspost/compress v1.4.0 h1:8nsMz3tWa9SWWPL60G1V6CUsf4lLjWLTNEtibhe8gh8=
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.7.4 h1:4UqAIzZ1Ns2epCTyJ1d2xMWvxtX+FNSCYWeOFogK9nc=
github.com/klauspost/compress v1.7.4/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e h1:+lIPJOWl+jSiJOc70QXJ07+2eg2Jy2EC7Mi11BWujeM=
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.9.7 h1:hYW1gP94JUmAhBtJ+LNz5My+gBobDxPR1iVuKug26aA=
github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -30,10 +29,15 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.4.0 h1:PuaTGZIw3mjYhhhbVbCQp8aciRZN9YdoB7MGX9Ko76A=
github.com/valyala/fasthttp v1.4.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
github.com/valyala/fasthttp v1.7.1 h1:UHtt5/7O70RSUZTR/hSu0PNWMAfWx5AtsPp9Jk+g17M=
github.com/valyala/fasthttp v1.7.1/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

1143
inline.go Normal file

File diff suppressed because it is too large Load Diff

51
inline_test.go Normal file
View File

@ -0,0 +1,51 @@
package telegram
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestInlineQueryHasQuery(t *testing.T) {
t.Run("true", func(t *testing.T) {
iq := InlineQuery{Query: "sample text"}
assert.True(t, iq.HasQuery())
})
t.Run("false", func(t *testing.T) {
iq := InlineQuery{}
assert.False(t, iq.HasQuery())
})
}
func TestInlineQueryHasOffset(t *testing.T) {
t.Run("true", func(t *testing.T) {
iq := InlineQuery{Offset: "42"}
assert.True(t, iq.HasOffset())
})
t.Run("false", func(t *testing.T) {
iq := InlineQuery{}
assert.False(t, iq.HasOffset())
})
}
func TestInlineQueryHasLocation(t *testing.T) {
t.Run("true", func(t *testing.T) {
iq := InlineQuery{Location: &Location{Latitude: 56.085180, Longitude: 60.735150}}
assert.True(t, iq.HasLocation())
})
t.Run("false", func(t *testing.T) {
iq := InlineQuery{}
assert.False(t, iq.HasLocation())
})
}
func TestChosenInlineResultInlineQueryHasLocation(t *testing.T) {
t.Run("true", func(t *testing.T) {
cir := ChosenInlineResult{Location: &Location{Latitude: 56.085180, Longitude: 60.735150}}
assert.True(t, cir.HasLocation())
})
t.Run("false", func(t *testing.T) {
cir := ChosenInlineResult{}
assert.False(t, cir.HasLocation())
})
}

39
kick.go
View File

@ -1,39 +0,0 @@
package telegram
// KickChatMemberParameters represents data for KickChatMember method.
type KickChatMemberParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Unique identifier of the target user
UserID int `json:"user_id"`
// Date when the user will be unbanned, unix time. If user is banned for
// more than 366 days or less than 30 seconds from the current time they
// are considered to be banned forever
UntilDate int64 `json:"until_date"`
}
// KickChatMember kick a user from a group, a supergroup or a channel. In the case of supergroups and
// channels, the user will not be able to return to the group on their own using invite links, etc.,
// unless unbanned first. The bot must be an administrator in the chat for this to work and must have
// the appropriate admin rights. Returns True on success.
//
// Note: In regular groups (non-supergroups), this method will only work if the 'All Members Are
// Admins' setting is off in the target group. Otherwise members may only be removed by the group's
// creator or by the member that added them.
func (bot *Bot) KickChatMember(params *KickChatMemberParameters) (bool, error) {
dst, err := parser.Marshal(params)
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodKickChatMember)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

View File

@ -1,24 +0,0 @@
package telegram
// LeaveChatParameters represents data for LeaveChat method.
type LeaveChatParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
}
// LeaveChat leave a group, supergroup or channel. Returns True on success.
func (bot *Bot) LeaveChat(chatID int64) (bool, error) {
dst, err := parser.Marshal(&LeaveChatParameters{ChatID: chatID})
if err != nil {
return false, err
}
resp, err := bot.request(dst, MethodLeaveChat)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

1728
methods.go Normal file

File diff suppressed because it is too large Load Diff

1070
passport.go Normal file

File diff suppressed because it is too large Load Diff

347
payments.go Normal file
View File

@ -0,0 +1,347 @@
package telegram
type (
// LabeledPrice represents a portion of the price for goods or services.
LabeledPrice struct {
// Portion label
Label string `json:"label"`
// Price of the product in the smallest units of the currency (integer,
// not float/double). For example, for a price of US$ 1.45 pass amount =
// 145. See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority
// of currencies).
Amount int `json:"amount"`
}
// Invoice contains basic information about an invoice.
Invoice struct {
// Product name
Title string `json:"title"`
// Product description
Description string `json:"description"`
// Unique bot deep-linking parameter that can be used to generate this
// invoice
StartParameter string `json:"start_parameter"`
// Three-letter ISO 4217 currency code
Currency string `json:"currency"`
// Total price in the smallest units of the currency (integer, not
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
// See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority
// of currencies).
TotalAmount int `json:"total_amount"`
}
// ShippingAddress represents a shipping address.
ShippingAddress struct {
// ISO 3166-1 alpha-2 country code
CountryCode string `json:"country_code"`
// State, if applicable
State string `json:"state"`
// City
City string `json:"city"`
// First line for the address
StreetLine1 string `json:"street_line1"`
// Second line for the address
StreetLine2 string `json:"street_line2"`
// Address post code
PostCode string `json:"post_code"`
}
// OrderInfo represents information about an order.
OrderInfo struct {
// User name
Name string `json:"name,omitempty"`
// User's phone number
PhoneNumber string `json:"phone_number,omitempty"`
// User email
Email string `json:"email,omitempty"`
// User shipping address
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
}
// ShippingOption represents one shipping option.
ShippingOption struct {
// Shipping option identifier
ID string `json:"id"`
// Option title
Title string `json:"title"`
// List of price portions
Prices []*LabeledPrice `json:"prices"`
}
// SuccessfulPayment contains basic information about a successful payment.
SuccessfulPayment struct {
// Three-letter ISO 4217 currency code
Currency string `json:"currency"`
// Bot specified invoice payload
InvoicePayload string `json:"invoice_payload"`
// Identifier of the shipping option chosen by the user
ShippingOptionID string `json:"shipping_option_id,omitempty"`
// Telegram payment identifier
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
// Provider payment identifier
ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
// Total price in the smallest units of the currency (integer, not
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
// See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority
// of currencies).
TotalAmount int `json:"total_amount"`
// Order info provided by the user
OrderInfo *OrderInfo `json:"order_info,omitempty"`
}
// ShippingQuery contains information about an incoming shipping query.
ShippingQuery struct {
// Unique query identifier
ID string `json:"id"`
// Bot specified invoice payload
InvoicePayload string `json:"invoice_payload"`
// User who sent the query
From *User `json:"from"`
// User specified shipping address
ShippingAddress *ShippingAddress `json:"shipping_address"`
}
// PreCheckoutQuery contains information about an incoming pre-checkout query.
PreCheckoutQuery struct {
// Unique query identifier
ID string `json:"id"`
// Three-letter ISO 4217 currency code
Currency string `json:"currency"`
// Bot specified invoice payload
InvoicePayload string `json:"invoice_payload"`
// Identifier of the shipping option chosen by the user
ShippingOptionID string `json:"shipping_option_id,omitempty"`
// User who sent the query
From *User `json:"from"`
// Total price in the smallest units of the currency (integer, not
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
// See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority of
// currencies).
TotalAmount int `json:"total_amount"`
// Order info provided by the user
OrderInfo *OrderInfo `json:"order_info,omitempty"`
}
// SendInvoiceParameters represents data for SendInvoice method.
SendInvoice struct {
// Unique identifier for the target private chat
ChatID int64 `json:"chat_id"`
// Product name, 1-32 characters
Title string `json:"title"`
// Product description, 1-255 characters
Description string `json:"description"`
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
// the user, use for your internal processes.
Payload string `json:"payload"`
// Payments provider token, obtained via Botfather
ProviderToken string `json:"provider_token"`
// Unique deep-linking parameter that can be used to generate this invoice
// when used as a start parameter
StartParameter string `json:"start_parameter"`
// Three-letter ISO 4217 currency code, see more on currencies
Currency string `json:"currency"`
// JSON-encoded data about the invoice, which will be shared with the payment
// provider. A detailed description of required fields should be provided by
// the payment provider.
ProviderData string `json:"provider_data,omitempty"`
// URL of the product photo for the invoice. Can be a photo of the goods or a
// marketing image for a service. People like it better when they see what
// they are paying for.
PhotoURL string `json:"photo_url,omitempty"`
// Price breakdown, a list of components (e.g. product price, tax, discount,
// delivery cost, delivery tax, bonus, etc.)
Prices []*LabeledPrice `json:"prices"`
// Photo size
PhotoSize int `json:"photo_size,omitempty"`
// Photo width
PhotoWidth int `json:"photo_width,omitempty"`
// Photo height
PhotoHeight int `json:"photo_height,omitempty"`
// If the message is a reply, ID of the original message
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
// Pass True, if you require the user's full name to complete the order
NeedName bool `json:"need_name,omitempty"`
// Pass True, if you require the user's phone number to complete the order
NeedPhoneNumber bool `json:"need_phone_number,omitempty"`
// Pass True, if you require the user's email to complete the order
NeedEmail bool `json:"need_email,omitempty"`
// Pass True, if you require the user's shipping address to complete the
// order
NeedShippingAddress bool `json:"need_shipping_address,omitempty"`</