Added max connections configuration option to SetWebHook
Dmitry V savraz@gmail.com
Tue, 17 Jan 2017 17:18:26 +0300
3 files changed,
23 insertions(+),
0 deletions(-)
M
bot.go
→
bot.go
@@ -409,15 +409,22 @@ //
// 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 {
M
configs.go
→
configs.go
@@ -770,6 +770,7 @@ // WebhookConfig contains information about a SetWebhook request.
type WebhookConfig struct { URL *url.URL Certificate interface{} + MaxConnections int } // FileBytes contains information about a set of bytes to upload
M
helpers.go
→
helpers.go
@@ -318,6 +318,21 @@ Certificate: file,
} } +// 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{