Skip to content

Commit

Permalink
api 6.5: implement request_user and request_chat support params in Re…
Browse files Browse the repository at this point in the history
…plyButton
  • Loading branch information
demget committed Nov 19, 2023
1 parent cd009a6 commit 7861084
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
38 changes: 34 additions & 4 deletions markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ func (r *ReplyMarkup) WebApp(text string, app *WebApp) Btn {
type ReplyButton struct {
Text string `json:"text"`

Contact bool `json:"request_contact,omitempty"`
Location bool `json:"request_location,omitempty"`
Poll PollType `json:"request_poll,omitempty"`
WebApp *WebApp `json:"web_app,omitempty"`
Contact bool `json:"request_contact,omitempty"`
Location bool `json:"request_location,omitempty"`
Poll PollType `json:"request_poll,omitempty"`
User *ReplyRecipient `json:"request_user,omitempty"`
Chat *ReplyRecipient `json:"request_chat,omitempty"`
WebApp *WebApp `json:"web_app,omitempty"`
}

// MarshalJSON implements json.Marshaler. It allows passing PollType as a
Expand All @@ -223,6 +225,34 @@ func (pt PollType) MarshalJSON() ([]byte, error) {
})
}

// ReplyRecipient combines both KeyboardButtonRequestUser
// and KeyboardButtonRequestChat objects. Use inside ReplyButton
// to request the user or chat sharing with respective settings.
//
// To pass the pointers to bool use a special tele.Flag function,
// that way you will be able to reflect the three-state bool (nil, false, true).
type ReplyRecipient struct {
ID int32 `json:"request_id"`

Bot *bool `json:"user_is_bot,omitempty"` // user only, optional
Premium *bool `json:"user_is_premium,omitempty"` // user only, optional

Channel bool `json:"chat_is_channel,omitempty"` // chat only, required
Forum *bool `json:"chat_is_forum,omitempty"` // chat only, optional
WithUsername *bool `json:"chat_has_username,omitempty"` // chat only, optional
Created *bool `json:"chat_is_created,omitempty"` // chat only, optional
UserRights *Rights `json:"user_administrator_rights,omitempty"` // chat only, optional
BotRights *Rights `json:"bot_administrator_rights,omitempty"` // chat only, optional
BotMember *bool `json:"bot_is_member,omitempty"` // chat only, optional
}

// RecipientShared combines both UserShared and ChatShared objects.
type RecipientShared struct {
ID int32 `json:"request_id"`
UserID int64 `json:"user_id"`
ChatID int64 `json:"chat_id"`
}

// InlineButton represents a button displayed in the message.
type InlineButton struct {
// Unique slagish name for this kind of button,
Expand Down
6 changes: 6 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ type Message struct {
// Message is a service message about a successful payment.
Payment *Payment `json:"successful_payment"`

// For a service message, a user was shared with the bot.
UserShared *RecipientShared `json:"user_shared,omitempty"`

// For a service message, a chat was shared with the bot.
ChatShared *RecipientShared `json:"chat_shared,omitempty"`

// The domain name of the website on which the user has logged in.
ConnectedWebsite string `json:"connected_website,omitempty"`

Expand Down
13 changes: 11 additions & 2 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
OnAddedToGroup = "\aadded_to_group"
OnUserJoined = "\auser_joined"
OnUserLeft = "\auser_left"
OnUserShared = "\auser_shared"
OnChatShared = "\achat_shared"
OnNewGroupTitle = "\anew_chat_title"
OnNewGroupPhoto = "\anew_chat_photo"
OnGroupPhotoDeleted = "\achat_photo_deleted"
Expand Down Expand Up @@ -136,6 +138,13 @@ const (
ModeHTML ParseMode = "HTML"
)

// M is a shortcut for map[string]interface{}. Use it for passing
// arguments to the layout functions.
// M is a shortcut for map[string]interface{}.
// Useful for passing arguments to the layout functions.
type M = map[string]interface{}

// Flag returns a pointer to the given bool.
// Useful for passing the three-state flags to a Bot API.
// For example, see ReplyRecipient type.
func Flag(b bool) *bool {
return &b
}
10 changes: 10 additions & 0 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ func (b *Bot) ProcessUpdate(u Update) {
return
}

if m.UserShared != nil {
b.handle(OnUserShared, c)
return
}

if m.ChatShared != nil {
b.handle(OnChatShared, c)
return
}

if m.NewGroupTitle != "" {
b.handle(OnNewGroupTitle, c)
return
Expand Down

0 comments on commit 7861084

Please sign in to comment.