all repos — telegram-bot-api @ 99170e2de436c1be90d2ef23dcf533b55a973e56

Golang bindings for the Telegram Bot API

Merge pull request #71 from Eternity-Yarr/upstream

Added max connections configuration option to SetWebHook
Syfaro syfaro@foxpaw.in
Tue, 17 Jan 2017 10:04:37 -0600
commit

99170e2de436c1be90d2ef23dcf533b55a973e56

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{