Merge pull request #302 from tjhorner/polls

Bot API 4.6: Polls 2.0, misc. changes
bot-api-6.1
Syfaro 2020-01-26 22:32:56 -06:00 committed by GitHub
commit 3635031d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 22 deletions

View File

@ -3,6 +3,7 @@ package tgbotapi
import (
"io"
"net/url"
"strconv"
)
// Telegram constants
@ -505,6 +506,11 @@ type SendPollConfig struct {
BaseChat
Question string
Options []string
IsAnonymous bool
Type string
AllowsMultipleAnswers bool
CorrectOptionID int64
IsClosed bool
}
func (config SendPollConfig) params() (Params, error) {
@ -515,6 +521,11 @@ func (config SendPollConfig) params() (Params, error) {
params["question"] = config.Question
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.AddBool("is_closed", config.IsClosed)
return params, err
}

2
go.mod
View File

@ -1,3 +1,5 @@
module github.com/go-telegram-bot-api/telegram-bot-api/v5
require github.com/technoweenie/multipartstreamer v1.0.1
go 1.13

View File

@ -823,6 +823,7 @@ func NewPoll(chatID int64, question string, options ...string) SendPollConfig {
},
Question: question,
Options: options,
IsAnonymous: true, // This is Telegram's default.
}
}

View File

@ -38,6 +38,7 @@ type Update struct {
ShippingQuery *ShippingQuery `json:"shipping_query"`
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query"`
Poll *Poll `json:"poll"`
PollAnswer *PollAnswer `json:"poll_answer"`
}
// UpdatesChannel is the channel for getting updates.
@ -58,6 +59,9 @@ type User struct {
UserName string `json:"username"` // optional
LanguageCode string `json:"language_code"` // 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.
@ -276,6 +280,7 @@ type MessageEntity struct {
Length int `json:"length"`
URL string `json:"url"` // optional
User *User `json:"user"` // optional
Language string `json:"language"` // optional
}
// ParseURL attempts to parse a URL contained within a MessageEntity.
@ -420,12 +425,23 @@ type PollOption struct {
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.
type Poll struct {
ID string `json:"id"`
Question string `json:"question"`
Options []PollOption `json:"options"`
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.
@ -462,6 +478,13 @@ type KeyboardButton struct {
Text string `json:"text"`
RequestContact bool `json:"request_contact"`
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.