Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --telegram-bot-token-file to read token from file #47

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions smtp_to_telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
units "github.com/docker/go-units"
"github.com/flashmob/go-guerrilla"
"github.com/flashmob/go-guerrilla/backends"
"github.com/flashmob/go-guerrilla/log"
"github.com/flashmob/go-guerrilla/mail"
"github.com/jhillyerd/enmime"
"github.com/urfave/cli/v2"
"io/ioutil"
"mime"
"mime/multipart"
Expand All @@ -23,6 +16,14 @@ import (
"strings"
"syscall"
"time"

units "github.com/docker/go-units"
"github.com/flashmob/go-guerrilla"
"github.com/flashmob/go-guerrilla/backends"
"github.com/flashmob/go-guerrilla/log"
"github.com/flashmob/go-guerrilla/mail"
"github.com/jhillyerd/enmime"
"github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -94,6 +95,20 @@ func main() {
"all incoming Email messages to Telegram."
app.Version = Version
app.Action = func(c *cli.Context) error {
var telegramBotToken string
if c.String("telegram-bot-token") == "" {
if c.String("telegram-bot-token-file") == "" {
return fmt.Errorf("either --telegram-bot-token or --telegram-bot-token-file is required")
} else {
bytes, err := ioutil.ReadFile(c.String("telegram-bot-token-file"))
if err != nil {
return err
}
telegramBotToken = strings.TrimSpace(string(bytes))
}
} else {
telegramBotToken = c.String("telegram-bot-token")
}
smtpMaxEnvelopeSize, err := units.FromHumanSize(c.String("smtp-max-envelope-size"))
if err != nil {
fmt.Printf("%s\n", err)
Expand All @@ -116,7 +131,7 @@ func main() {
}
telegramConfig := &TelegramConfig{
telegramChatIds: c.String("telegram-chat-ids"),
telegramBotToken: c.String("telegram-bot-token"),
telegramBotToken: telegramBotToken,
telegramApiPrefix: c.String("telegram-api-prefix"),
telegramApiTimeoutSeconds: c.Float64("telegram-api-timeout-seconds"),
messageTemplate: c.String("message-template"),
Expand Down Expand Up @@ -158,10 +173,15 @@ func main() {
Required: true,
},
&cli.StringFlag{
Name: "telegram-bot-token",
Usage: "Telegram: bot token",
EnvVars: []string{"ST_TELEGRAM_BOT_TOKEN"},
Required: true,
Name: "telegram-bot-token",
Usage: "Telegram: bot token",
EnvVars: []string{"ST_TELEGRAM_BOT_TOKEN"},
},
&cli.StringFlag{
Name: "telegram-bot-token-file",
Usage: "Telegram: file containing bot token",
TakesFile: true,
EnvVars: []string{"ST_TELEGRAM_BOT_TOKEN_FILE"},
},
&cli.StringFlag{
Name: "telegram-api-prefix",
Expand Down