From 955a2e8b5f05c54878ef65e84aa5a61b7bf4530c Mon Sep 17 00:00:00 2001 From: slaventius Date: Thu, 9 Feb 2023 10:16:49 +0300 Subject: [PATCH] * --- .vscode/launch.json | 2 ++ internal/authPostman.go | 11 ++++++----- internal/config/config.go | 20 +++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 2dbdff6..2821ce0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,6 +18,8 @@ "SMTP_PASSWORD":"hwNhMgPyBzMjwCj3hFPp", "KAFKA_PORT":"9092", "KAFKA_HOST":"37.143.12.169", + "CHAT_ID":"150697696", + "CHAT_TOKEN":"5960577375:AAEZYPZV4-ErxQbX6yP084pIzCB0BPxN7ig", }, "args": [] } diff --git a/internal/authPostman.go b/internal/authPostman.go index e5de5d9..8a12a28 100644 --- a/internal/authPostman.go +++ b/internal/authPostman.go @@ -14,8 +14,6 @@ import ( ) const ( - chatID int64 = 150697696 - token string = "5944264850:AAHaikh8r8NYciybnOpqEvFQpSYgr6JHDZc" topicRegistrations string = "registrations" // Топик для регистраций ) @@ -66,8 +64,9 @@ func (s *AuthPostmanServer) ReadMessage(offset int64) error { log.Printf("send code %s to %s ...", amsg.Code, amsg.Email) // - postman := telegram.NewService(token) - message := postman.NewMessage(chatID, fmt.Sprintf("Confirmation code %v", amsg.Code)) + text := fmt.Sprintf("Confirmation code %v", amsg.Code) + postman := telegram.NewService(s.config.Telegram.ChatToken) + message := postman.NewMessage(s.config.Telegram.ChatID, text) ers := postman.SendMessage(message) if ers != nil { log.Print(ers) @@ -76,7 +75,7 @@ func (s *AuthPostmanServer) ReadMessage(offset int64) error { } // // - // message := smtp.NewMessage("Confirmation code", amsg.Code) + // message := smtp.NewMessage("Confirmation code", text) // message.AppendRecipient(amsg.Email) // // @@ -84,6 +83,8 @@ func (s *AuthPostmanServer) ReadMessage(offset int64) error { // ers := smtpSender.Send(message) // if ers != nil { // log.Print(ers) + // } else { + // log.Printf("send code %s to %s completed", amsg.Code, amsg.Email) // } } } diff --git a/internal/config/config.go b/internal/config/config.go index 8d6c4d7..0f7efb6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -6,11 +6,16 @@ import ( "github.com/kelseyhightower/envconfig" ) -type smtpConfig struct { - Port int `envconfig:"SMTP_PORT"` - Host string `envconfig:"SMTP_HOST"` - Sender string `envconfig:"SMTP_SENDER"` - Password string `envconfig:"SMTP_PASSWORD"` +// type smtpConfig struct { +// Port int `envconfig:"SMTP_PORT"` +// Host string `envconfig:"SMTP_HOST"` +// Sender string `envconfig:"SMTP_SENDER"` +// Password string `envconfig:"SMTP_PASSWORD"` +// } + +type telegramConfig struct { + ChatID int64 `envconfig:"CHAT_ID"` + ChatToken string `envconfig:"CHAT_TOKEN"` } type kafkaConfig struct { @@ -20,8 +25,9 @@ type kafkaConfig struct { // ... type Config struct { - Smtp smtpConfig - Kafka kafkaConfig + // Smtp smtpConfig + Kafka kafkaConfig + Telegram telegramConfig } func NewConfig() *Config {