Skip to content

Commit

Permalink
ChosenInlineResult.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Byrd committed Dec 26, 2017
1 parent 7d18e51 commit f704eef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ type Update struct {
EditedChannelPost *Message `json:"edited_channel_post,omitempty"`
Callback *Callback `json:"callback_query,omitempty"`
Query *Query `json:"inline_query,omitempty"`

ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty`
}

// ChosenInlineResult represents a result of an inline query that was chosen
// by the user and sent to their chat partner.
type ChosenInlineResult struct {
ResultID string `json:"result_id"`
Query string `json:"query"`
// Inline messages only!
MessageID string `json:"inline_message_id"`

From User `json:"from"`
Location *Location `json:"location,omitempty"`
}

// Handle lets you set the handler for some command name or
Expand Down Expand Up @@ -328,6 +342,24 @@ func (b *Bot) incomingUpdate(upd *Update) {
}
return
}

if upd.ChosenInlineResult != nil {
if handler, ok := b.handlers[OnChosenInlineResult]; ok {
if handler, ok := handler.(func(*ChosenInlineResult)); ok {
// i'm not 100% sure that any of the values
// won't be cached, so I pass them all in:
go func(b *Bot, handler func(*ChosenInlineResult),
r *ChosenInlineResult) {
defer b.deferDebug()
handler(r)
}(b, handler, upd.ChosenInlineResult)

} else {
panic("telebot: chosen inline result handler is bad")
}
}
return
}
}

func (b *Bot) handle(end string, m *Message) bool {
Expand Down
5 changes: 5 additions & 0 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const (
//
// Handler: func(*Query)
OnQuery = "\aquery"

// Will fire on chosen inline results.
//
// Handler: func(*ChosenInlineResult)
OnChosenInlineResult = "\achosen_inline_result"
)

// ChatAction is a client-side status indicating bot activity.
Expand Down

0 comments on commit f704eef

Please sign in to comment.