aboutsummaryrefslogtreecommitdiff
path: root/telegram_bot.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-05-28 22:14:46 +0700
committerShulhan <m.shulhan@gmail.com>2020-05-28 22:46:08 +0700
commit5d49371ef3f5cc1fa4d4fd6d5d84207520739037 (patch)
tree284cfe0c442788409fbe71a9b950a84a26614355 /telegram_bot.go
parent9ddee4a05e38d0b71b8b2628c0ebba98ad7c5470 (diff)
downloadkamusku-5d49371ef3f5cc1fa4d4fd6d5d84207520739037.tar.xz
server: make the listen port configurable through environment
Deploying to App Engine require the port to be initialized through environment variable PORT.
Diffstat (limited to 'telegram_bot.go')
-rw-r--r--telegram_bot.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/telegram_bot.go b/telegram_bot.go
index e88b123..71adb94 100644
--- a/telegram_bot.go
+++ b/telegram_bot.go
@@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"log"
+ "os"
"strings"
"github.com/shuLhan/share/api/telegram/bot"
@@ -47,12 +48,18 @@ func NewTelegramBot(token, webhookURL string) (tgbot *TelegramBot, err error) {
Handler: tgbot.handleCommandStart,
}}
+ address := defAddress
+ port := os.Getenv(envPort)
+ if len(port) > 0 {
+ address = ":" + port
+ }
+
opts := bot.Options{
Token: token,
HandleUpdate: tgbot.handleUpdate,
Webhook: &bot.Webhook{
URL: webhookURL,
- ListenAddress: defAddress,
+ ListenAddress: address,
},
}