diff --git a/config/config.go b/config/config.go index e4a4516..df35ce2 100644 --- a/config/config.go +++ b/config/config.go @@ -39,6 +39,7 @@ const ( var cfg *BotConfig type BotConfig struct { + Env string Token string Mode string BaseUrl string @@ -105,6 +106,7 @@ func readBlacklist(path string) []string { func Get() *BotConfig { if cfg == nil { + envPtr := flag.String("env", "production", "Environment to run in (dev or production)") tokenPtr := flag.String("token", "", "Your Telegram Bot Token from Botfather") modePtr := flag.String("mode", "poll", "Update mode ('poll' for development, 'webhook' for production)") baseUrlPtr := flag.String("baseUrl", "", "A relative URL different from '/', required to run the bot on a subpath. E.g. to run bot under 'https://exmaple.org/wh2tg' set baseUrl to '/wh2tg'") @@ -134,6 +136,7 @@ func Get() *BotConfig { } cfg = &BotConfig{ + Env: *envPtr, Token: *tokenPtr, Mode: *modePtr, BaseUrl: *baseUrlPtr + "/", diff --git a/handlers/index.go b/handlers/index.go index 568b379..0ce434c 100644 --- a/handlers/index.go +++ b/handlers/index.go @@ -15,12 +15,18 @@ type indexData struct { } func NewIndexHandler() *IndexHandler { - return &IndexHandler{ - Tpl: template.Must(template.ParseFiles("views/index.tpl.html")), - Config: config.Get(), - } + h := &IndexHandler{Config: config.Get()} + h.loadTemplates() + return h } func (h *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if h.Config.Env == "dev" { + h.loadTemplates() + } h.Tpl.Execute(w, indexData{Config: h.Config}) } + +func (h *IndexHandler) loadTemplates() { + h.Tpl = template.Must(template.ParseFiles("views/index.tpl.html")) +} diff --git a/views/index.tpl.html b/views/index.tpl.html index 6ff465f..c0e53be 100644 --- a/views/index.tpl.html +++ b/views/index.tpl.html @@ -3,6 +3,7 @@
Send Telegram push notifications easily via HTTP
+ + + +Step 1: Get a token
++ Start a chat with TelepushBot (or your own bot) and type /start to obtain a recipient token. +
+Step 2: Send your message
+ +
+ curl -XPOST \
+ -d '{ "text": "Hello there" }' \
+ api/messages
+