api 6.5: implement request_user and request_chat support params in ReplyButton

pull/625/head^2
Demian 6 months ago
parent cd009a68b3
commit 78610849e1

@ -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
@ -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,

@ -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"`

@ -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"
@ -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
}

@ -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

Loading…
Cancel
Save