Bot API 4.6: Polls 2.0, misc. changes
parent
5ce2767dad
commit
5aaa0b2d03
15
configs.go
15
configs.go
|
@ -3,6 +3,7 @@ package tgbotapi
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Telegram constants
|
// Telegram constants
|
||||||
|
@ -503,8 +504,13 @@ func (config ContactConfig) method() string {
|
||||||
// SendPollConfig allows you to send a poll.
|
// SendPollConfig allows you to send a poll.
|
||||||
type SendPollConfig struct {
|
type SendPollConfig struct {
|
||||||
BaseChat
|
BaseChat
|
||||||
Question string
|
Question string
|
||||||
Options []string
|
Options []string
|
||||||
|
IsAnonymous bool
|
||||||
|
Type string
|
||||||
|
AllowsMultipleAnswers bool
|
||||||
|
CorrectOptionID int64
|
||||||
|
IsClosed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config SendPollConfig) params() (Params, error) {
|
func (config SendPollConfig) params() (Params, error) {
|
||||||
|
@ -515,6 +521,11 @@ func (config SendPollConfig) params() (Params, error) {
|
||||||
|
|
||||||
params["question"] = config.Question
|
params["question"] = config.Question
|
||||||
err = params.AddInterface("options", config.Options)
|
err = params.AddInterface("options", config.Options)
|
||||||
|
params["is_anonymous"] = strconv.FormatBool(config.IsAnonymous)
|
||||||
|
params.AddNonEmpty("type", config.Type)
|
||||||
|
params["allows_multiple_answers"] = strconv.FormatBool(config.AllowsMultipleAnswers)
|
||||||
|
params["correct_option_id"] = strconv.FormatInt(config.CorrectOptionID, 10)
|
||||||
|
params["is_closed"] = strconv.FormatBool(config.IsClosed)
|
||||||
|
|
||||||
return params, err
|
return params, err
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
||||||
module github.com/go-telegram-bot-api/telegram-bot-api/v5
|
module github.com/go-telegram-bot-api/telegram-bot-api/v5
|
||||||
|
|
||||||
require github.com/technoweenie/multipartstreamer v1.0.1
|
require github.com/technoweenie/multipartstreamer v1.0.1
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
|
@ -821,8 +821,9 @@ func NewPoll(chatID int64, question string, options ...string) SendPollConfig {
|
||||||
BaseChat: BaseChat{
|
BaseChat: BaseChat{
|
||||||
ChatID: chatID,
|
ChatID: chatID,
|
||||||
},
|
},
|
||||||
Question: question,
|
Question: question,
|
||||||
Options: options,
|
Options: options,
|
||||||
|
IsAnonymous: true, // This is Telegram's default.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
59
types.go
59
types.go
|
@ -38,6 +38,7 @@ type Update struct {
|
||||||
ShippingQuery *ShippingQuery `json:"shipping_query"`
|
ShippingQuery *ShippingQuery `json:"shipping_query"`
|
||||||
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`
|
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`
|
||||||
Poll *Poll `json:"poll"`
|
Poll *Poll `json:"poll"`
|
||||||
|
PollAnswer *PollAnswer `json:"poll_answer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatesChannel is the channel for getting updates.
|
// UpdatesChannel is the channel for getting updates.
|
||||||
|
@ -52,12 +53,15 @@ func (ch UpdatesChannel) Clear() {
|
||||||
|
|
||||||
// User is a user on Telegram.
|
// User is a user on Telegram.
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
LastName string `json:"last_name"` // optional
|
LastName string `json:"last_name"` // optional
|
||||||
UserName string `json:"username"` // optional
|
UserName string `json:"username"` // optional
|
||||||
LanguageCode string `json:"language_code"` // optional
|
LanguageCode string `json:"language_code"` // optional
|
||||||
IsBot bool `json:"is_bot"` // optional
|
IsBot bool `json:"is_bot"` // optional
|
||||||
|
CanJoinGroups bool `json:"can_join_groups"` // optional
|
||||||
|
CanReadAllGroupMessages bool `json:"can_read_all_group_messages"` // optional
|
||||||
|
SupportsInlineQueries bool `json:"supports_inline_queries"` // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
// String displays a simple text version of a user.
|
// String displays a simple text version of a user.
|
||||||
|
@ -271,11 +275,12 @@ func (m *Message) CommandArguments() string {
|
||||||
|
|
||||||
// MessageEntity contains information about data in a Message.
|
// MessageEntity contains information about data in a Message.
|
||||||
type MessageEntity struct {
|
type MessageEntity struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Offset int `json:"offset"`
|
Offset int `json:"offset"`
|
||||||
Length int `json:"length"`
|
Length int `json:"length"`
|
||||||
URL string `json:"url"` // optional
|
URL string `json:"url"` // optional
|
||||||
User *User `json:"user"` // optional
|
User *User `json:"user"` // optional
|
||||||
|
Language string `json:"language"` // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseURL attempts to parse a URL contained within a MessageEntity.
|
// ParseURL attempts to parse a URL contained within a MessageEntity.
|
||||||
|
@ -420,12 +425,23 @@ type PollOption struct {
|
||||||
VoterCount int `json:"voter_count"`
|
VoterCount int `json:"voter_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PollAnswer represents an answer of a user in a non-anonymous poll.
|
||||||
|
type PollAnswer struct {
|
||||||
|
PollID string `json:"poll_id"`
|
||||||
|
User User `json:"user"`
|
||||||
|
OptionIDs []int `json:"option_ids"`
|
||||||
|
}
|
||||||
|
|
||||||
// Poll contains information about a poll.
|
// Poll contains information about a poll.
|
||||||
type Poll struct {
|
type Poll struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Question string `json:"question"`
|
Question string `json:"question"`
|
||||||
Options []PollOption `json:"options"`
|
Options []PollOption `json:"options"`
|
||||||
IsClosed bool `json:"is_closed"`
|
IsClosed bool `json:"is_closed"`
|
||||||
|
IsAnonymous bool `json:"is_anonymous"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
AllowsMultipleAnswers bool `json:"allows_multiple_answers"`
|
||||||
|
CorrectOptionID int `json:"correct_option_id"` // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserProfilePhotos contains a set of user profile photos.
|
// UserProfilePhotos contains a set of user profile photos.
|
||||||
|
@ -459,9 +475,16 @@ type ReplyKeyboardMarkup struct {
|
||||||
|
|
||||||
// KeyboardButton is a button within a custom keyboard.
|
// KeyboardButton is a button within a custom keyboard.
|
||||||
type KeyboardButton struct {
|
type KeyboardButton struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
RequestContact bool `json:"request_contact"`
|
RequestContact bool `json:"request_contact"`
|
||||||
RequestLocation bool `json:"request_location"`
|
RequestLocation bool `json:"request_location"`
|
||||||
|
RequestPoll KeyboardButtonPollType `json:"request_poll"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyboardButtonPollType represents type of a poll, which is allowed to
|
||||||
|
// be created and sent when the corresponding button is pressed.
|
||||||
|
type KeyboardButtonPollType struct {
|
||||||
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
|
// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
|
||||||
|
|
Loading…
Reference in New Issue