From 833e457376ad3684b25c0376c9fbdcaa72f70575 Mon Sep 17 00:00:00 2001 From: Dmitry V Date: Tue, 17 Jan 2017 17:18:26 +0300 Subject: [PATCH] Added max connections configuration option to SetWebHook --- bot.go | 7 +++++++ configs.go | 1 + helpers.go | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/bot.go b/bot.go index b8bd419..60519cd 100644 --- a/bot.go +++ b/bot.go @@ -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 { diff --git a/configs.go b/configs.go index aff0cd9..68c14e9 100644 --- a/configs.go +++ b/configs.go @@ -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 diff --git a/helpers.go b/helpers.go index 476eeeb..4ca56fb 100644 --- a/helpers.go +++ b/helpers.go @@ -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{