all repos — telegram-bot-api @ 833e457376ad3684b25c0376c9fbdcaa72f70575

Golang bindings for the Telegram Bot API

Added max connections configuration option to SetWebHook
Dmitry V savraz@gmail.com
Tue, 17 Jan 2017 17:18:26 +0300
commit

833e457376ad3684b25c0376c9fbdcaa72f70575

parent

80bdd621f775d115d6e781d9d2f91e79d0f41169

3 files changed, 23 insertions(+), 0 deletions(-)

jump to
M bot.gobot.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.goconfigs.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.gohelpers.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{