Merge pull request #71 from Eternity-Yarr/upstream

Added max connections configuration option to SetWebHook
bot-api-6.1
Syfaro 2017-01-17 10:04:37 -06:00 committed by GitHub
commit 99170e2de4
3 changed files with 23 additions and 0 deletions

7
bot.go
View File

@ -409,15 +409,22 @@ func (bot *BotAPI) RemoveWebhook() (APIResponse, error) {
// If you do not have a legitimate TLS certificate, you need to include
// your self signed certificate with the config.
func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
if config.Certificate == nil {
v := url.Values{}
v.Add("url", config.URL.String())
if config.MaxConnections != 0 {
v.Add("max_connections", strconv.Itoa(config.MaxConnections))
}
return bot.MakeRequest("setWebhook", v)
}
params := make(map[string]string)
params["url"] = config.URL.String()
if config.MaxConnections != 0 {
params["max_connections"] = strconv.Itoa(config.MaxConnections)
}
resp, err := bot.UploadFile("setWebhook", params, "certificate", config.Certificate)
if err != nil {

View File

@ -770,6 +770,7 @@ type UpdateConfig struct {
type WebhookConfig struct {
URL *url.URL
Certificate interface{}
MaxConnections int
}
// FileBytes contains information about a set of bytes to upload

View File

@ -318,6 +318,21 @@ func NewWebhookWithCert(link string, file interface{}) WebhookConfig {
}
}
// NewWebhookWithCert creates a new webhook with a certificate and max_connections.
//
// link is the url you wish to get webhooks,
// file contains a string to a file, FileReader, or FileBytes.
// maxConnections defines maximum number of connections from telegram to your server
func NewWebhookWithCertAndMaxConnections(link string, file interface{}, maxConnections int) WebhookConfig {
u, _ := url.Parse(link)
return WebhookConfig{
URL: u,
Certificate: file,
MaxConnections: maxConnections,
}
}
// NewInlineQueryResultArticle creates a new inline query article.
func NewInlineQueryResultArticle(id, title, messageText string) InlineQueryResultArticle {
return InlineQueryResultArticle{