Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot API 4.6: Polls 2.0, misc. changes #302

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tgbotapi
import (
"io"
"net/url"
"strconv"
)

// Telegram constants
Expand Down Expand Up @@ -503,8 +504,13 @@ func (config ContactConfig) method() string {
// SendPollConfig allows you to send a poll.
type SendPollConfig struct {
BaseChat
Question string
Options []string
Question string
Options []string
IsAnonymous bool
Type string
AllowsMultipleAnswers bool
CorrectOptionID int64
IsClosed bool
}

func (config SendPollConfig) params() (Params, error) {
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,9 @@ func NewPoll(chatID int64, question string, options ...string) SendPollConfig {
BaseChat: BaseChat{
ChatID: chatID,
},
Question: question,
Options: options,
Question: question,
Options: options,
IsAnonymous: true, // This is Telegram's default.
}
}

Expand Down
59 changes: 41 additions & 18 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -52,12 +53,15 @@ func (ch UpdatesChannel) Clear() {

// User is a user on Telegram.
type User struct {
ID int `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"` // optional
UserName string `json:"username"` // optional
LanguageCode string `json:"language_code"` // optional
IsBot bool `json:"is_bot"` // optional
ID int `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"` // optional
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.
Expand Down Expand Up @@ -271,11 +275,12 @@ func (m *Message) CommandArguments() string {

// MessageEntity contains information about data in a Message.
type MessageEntity struct {
Type string `json:"type"`
Offset int `json:"offset"`
Length int `json:"length"`
URL string `json:"url"` // optional
User *User `json:"user"` // optional
Type string `json:"type"`
Offset int `json:"offset"`
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.
Expand Down Expand Up @@ -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"`
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.
Expand Down Expand Up @@ -459,9 +475,16 @@ type ReplyKeyboardMarkup struct {

// KeyboardButton is a button within a custom keyboard.
type KeyboardButton struct {
Text string `json:"text"`
RequestContact bool `json:"request_contact"`
RequestLocation bool `json:"request_location"`
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.
Expand Down