-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from bulletmys/keyboard
Added Button Functionality
- Loading branch information
Showing
10 changed files
with
741 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package botgolang | ||
|
||
//go:generate easyjson -all button.go | ||
|
||
// Button represents a button in inline keyboard | ||
type Button struct { | ||
// Button text | ||
Text string `json:"text"` | ||
|
||
// URL to be opened | ||
// You can't use it with CallbackData | ||
URL string `json:"url,omitempty"` | ||
|
||
// Data that identify the button | ||
// You can't use it with URL | ||
CallbackData string `json:"callbackData,omitempty"` | ||
} | ||
|
||
// NewURLButton returns new button with URL field | ||
func NewURLButton(text string, url string) Button { | ||
return Button{ | ||
Text: text, | ||
URL: url, | ||
} | ||
} | ||
|
||
// NewCallbackButton returns new button with CallbackData field | ||
func NewCallbackButton(text string, callbackData string) Button { | ||
return Button{ | ||
Text: text, | ||
CallbackData: callbackData, | ||
} | ||
} | ||
|
||
// ButtonResponse represents a data that is returned when a button is clicked | ||
type ButtonResponse struct { | ||
client *Client | ||
|
||
// Id of the query | ||
QueryID string `json:"queryId"` | ||
|
||
// Text of the response message | ||
Text string `json:"text"` | ||
|
||
// Display alert? | ||
ShowAlert bool `json:"showAlert"` | ||
|
||
// URL to be opened | ||
URL string `json:"url"` | ||
|
||
// CallbackData of the query (id of the pressed button). | ||
CallbackData string `json:"callbackData"` | ||
} | ||
|
||
// Send method sends your response message. | ||
// Make sure you have QueryID in your ButtonResponse. | ||
func (cl *ButtonResponse) Send() error { | ||
return cl.client.SendAnswerCallbackQuery(cl) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.