diff options
Diffstat (limited to 'api/telegram/bot/webhook.go')
| -rw-r--r-- | api/telegram/bot/webhook.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/api/telegram/bot/webhook.go b/api/telegram/bot/webhook.go index 66eda754..5a7387c2 100644 --- a/api/telegram/bot/webhook.go +++ b/api/telegram/bot/webhook.go @@ -4,7 +4,15 @@ package bot -import "crypto/tls" +import ( + "crypto/tls" + "errors" +) + +const ( + defListenAddress = `:80` + defListenAddressTLS = `:443` +) // Webhook contains options to set Webhook to receive updates. type Webhook struct { @@ -43,3 +51,21 @@ type Webhook struct { // values to increase your bot’s throughput. MaxConnections int } + +func (webhook *Webhook) init() (err error) { + if len(webhook.URL) == 0 { + // Even thought empty URL is allowed by API, which + // means to clear the previous setWebhook, use the + // DeleteWebhook instead for consistency. + return errors.New(`empty Webhook URL`) + } + + if len(webhook.ListenAddress) == 0 { + if webhook.ListenCertificate == nil { + webhook.ListenAddress = defListenAddress + } else { + webhook.ListenAddress = defListenAddressTLS + } + } + return nil +} |
