Changed WEBHOOK_PORT to PORT

This commit is contained in:
Pavel 2019-06-09 13:24:05 +03:00
parent 04e287ee17
commit 0c9a399451
4 changed files with 9 additions and 4 deletions

View File

@ -1,7 +1,7 @@
TG_BOT_TOKEN=token # Telegram Bot API Token TG_BOT_TOKEN=token # Telegram Bot API Token
POLL_TIMEOUT=30 # Poll timeout (in seconds). Default: 30 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="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="cert.pem" # Certificate file name. Provide if you want to use SSL
CERT_KEY="key.pem" # Certificate key. Should be provided with CERT 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. DEBUG=false # Debug mode. This value will be passed to API library, which will log all requests in debug mode.

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"go.formatTool": "goimports"
}

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"strings"
"fmt" "fmt"
"log" "log"
"math/rand" "math/rand"
@ -219,7 +220,7 @@ func initWithWebhook(
log.Printf("Telegram callback failed: %s", info.LastErrorMessage) log.Printf("Telegram callback failed: %s", info.LastErrorMessage)
} }
updates := bot.ListenForWebhook("/" + bot.Token) updates := bot.ListenForWebhook(webhookUrl[strings.LastIndex(webhookUrl, "/"):])
if certFile != "" && certKey != "" { if certFile != "" && certKey != "" {
go http.ListenAndServeTLS(listenAddr, certFile, certKey, nil) go http.ListenAndServeTLS(listenAddr, certFile, certKey, nil)

View File

@ -3,6 +3,7 @@ package main
import ( import (
"log" "log"
"os" "os"
"fmt"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -14,7 +15,7 @@ const envToken = "TG_BOT_TOKEN"
const envPollTimeout = "POLL_TIMEOUT" const envPollTimeout = "POLL_TIMEOUT"
const envListen = "LISTEN_IP" const envListen = "LISTEN_IP"
const envWebhook = "WEBHOOK" const envWebhook = "WEBHOOK"
const envWebhookPort = "WEBHOOK_PORT" const envWebhookPort = "PORT"
const envCert = "CERT" const envCert = "CERT"
const envKey = "CERT_KEY" const envKey = "CERT_KEY"
const envDebug = "DEBUG" const envDebug = "DEBUG"
@ -90,7 +91,7 @@ func LoadConfig() (BotConfig, error) {
Debug: debug, Debug: debug,
PollingTimeout: pollTimeout, PollingTimeout: pollTimeout,
WebhookURL: webhookLink, WebhookURL: webhookLink,
ListenAddr: listenAddr, ListenAddr: fmt.Sprintf("%s:%d", listenAddr, webhookPort),
CertificateFile: certFile, CertificateFile: certFile,
CertificateKey: certKey, CertificateKey: certKey,
} }