diff --git a/.env.dist b/.env.dist index 72d0876..4249ddb 100644 --- a/.env.dist +++ b/.env.dist @@ -1,7 +1,7 @@ TG_BOT_TOKEN=token # Telegram Bot API Token POLL_TIMEOUT=30 # Poll timeout (in seconds). Default: 30 WEBHOOK="https://www.google.com:{PORT}/{TOKEN}" # Webhook URL (don't provide if you want to use polling). {PORT} and {TOKEN} will be replaced automatically. -WEBHOOK_PORT=8000 # Webhook port. Ignored if webhook URL is not provided. Default: 8000 +PORT=8000 # Webhook port. Ignored if webhook URL is not provided. Default: 8000 CERT="cert.pem" # Certificate file name. Provide if you want to use SSL CERT_KEY="key.pem" # Certificate key. Should be provided with CERT DEBUG=false # Debug mode. This value will be passed to API library, which will log all requests in debug mode. \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ae67a14 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "go.formatTool": "goimports" +} \ No newline at end of file diff --git a/src/bot.go b/src/bot.go index b3dd7ef..d098f29 100644 --- a/src/bot.go +++ b/src/bot.go @@ -1,6 +1,7 @@ package main import ( + "strings" "fmt" "log" "math/rand" @@ -219,7 +220,7 @@ func initWithWebhook( log.Printf("Telegram callback failed: %s", info.LastErrorMessage) } - updates := bot.ListenForWebhook("/" + bot.Token) + updates := bot.ListenForWebhook(webhookUrl[strings.LastIndex(webhookUrl, "/"):]) if certFile != "" && certKey != "" { go http.ListenAndServeTLS(listenAddr, certFile, certKey, nil) diff --git a/src/config.go b/src/config.go index 9ae1f0e..a11a50c 100644 --- a/src/config.go +++ b/src/config.go @@ -3,6 +3,7 @@ package main import ( "log" "os" + "fmt" "path/filepath" "strconv" "strings" @@ -14,7 +15,7 @@ const envToken = "TG_BOT_TOKEN" const envPollTimeout = "POLL_TIMEOUT" const envListen = "LISTEN_IP" const envWebhook = "WEBHOOK" -const envWebhookPort = "WEBHOOK_PORT" +const envWebhookPort = "PORT" const envCert = "CERT" const envKey = "CERT_KEY" const envDebug = "DEBUG" @@ -90,7 +91,7 @@ func LoadConfig() (BotConfig, error) { Debug: debug, PollingTimeout: pollTimeout, WebhookURL: webhookLink, - ListenAddr: listenAddr, + ListenAddr: fmt.Sprintf("%s:%d", listenAddr, webhookPort), CertificateFile: certFile, CertificateKey: certKey, }