diff options
author | terminaldweller <thabogre@gmail.com> | 2021-12-14 16:21:49 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2021-12-14 16:21:49 +0000 |
commit | 472923260ae9a266bf118b76feac17689bf70172 (patch) | |
tree | 529853dfc6bf39b91bc1015b9b1f78c5c094f3a0 | |
parent | grpc for telebot. untested. [WIP] (diff) | |
download | hived-472923260ae9a266bf118b76feac17689bf70172.tar.gz hived-472923260ae9a266bf118b76feac17689bf70172.zip |
grpc for telebot. untested. [WIP]telebot
-rw-r--r-- | docker-compose-test.yaml | 3 | ||||
-rw-r--r-- | docker-compose.yaml | 3 | ||||
-rw-r--r-- | hived/Dockerfile | 7 | ||||
-rw-r--r-- | hived/hived.go | 69 | ||||
-rw-r--r-- | telebot/Dockerfile | 9 |
5 files changed, 52 insertions, 39 deletions
diff --git a/docker-compose-test.yaml b/docker-compose-test.yaml index a58d904..8213acb 100644 --- a/docker-compose-test.yaml +++ b/docker-compose-test.yaml @@ -7,6 +7,7 @@ services: secrets: - ch_api_key - ch_api_secret + - tg_bot_token networks: - mainnet - telenet @@ -49,7 +50,7 @@ networks: mainnet: driver: bridge telenet: - driver: brige + driver: bridge secrets: tg_bot_token: file: ./tgtoken diff --git a/docker-compose.yaml b/docker-compose.yaml index 81ce000..ac9ef5e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,6 +7,7 @@ services: secrets: - ch_api_key - ch_api_secret + - tg_bot_token networks: - mainnet - telenet @@ -54,7 +55,7 @@ networks: mainnet: driver: bridge telenet: - driver: brige + driver: bridge secrets: tg_bot_token: file: ./tgtoken diff --git a/hived/Dockerfile b/hived/Dockerfile index 0a9e3e2..da91fb7 100644 --- a/hived/Dockerfile +++ b/hived/Dockerfile @@ -6,13 +6,14 @@ RUN cd /hived && go mod download COPY *.go /hived/ RUN cd /hived && go build -FROM node:lts-alpine3.13 AS certbuilder +FROM node:lts-alpine3.13 as certbuilder RUN apk add openssl WORKDIR /certs RUN openssl req -nodes -new -x509 -subj="/C=US/ST=Denial/L=springfield/O=Dis/CN=localhost" -keyout server.key -out server.cert -FROM gcr.io/distroless/static-debian10 -COPY --from=certbuilder /cert/ /cert/ +# FROM gcr.io/distroless/static-debian10 +FROM alpine:3.13 +COPY --from=certbuilder /certs /certs COPY --from=builder /hived/hived /hived/ COPY ./docker-entrypoint.sh /hived/ ENTRYPOINT ["/hived/docker-entrypoint.sh"] diff --git a/hived/hived.go b/hived/hived.go index ca2e6a4..b955986 100644 --- a/hived/hived.go +++ b/hived/hived.go @@ -22,7 +22,6 @@ import ( "github.com/Knetic/govaluate" "github.com/go-redis/redis/v8" - tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api" "github.com/gorilla/mux" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -49,7 +48,7 @@ const ( SERVER_DEPLOYMENT_TYPE = "SERVER_DEPLOYMENT_TYPE" ) -func sendToTg(address string) { +func sendToTg(address, msg string, channelId int64) { conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { log.Fatal().Err(err) @@ -61,7 +60,7 @@ func sendToTg(address string) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() - r, err := c.Notify(ctx, &pb.NotificationRequest{}) + r, err := c.Notify(ctx, &pb.NotificationRequest{NotificationText: address, ChannelId: channelId}) if err != nil { log.Fatal().Err(err) } @@ -69,36 +68,36 @@ func sendToTg(address string) { log.Info().Msg(fmt.Sprintf("%v", r)) } -func runTgBot() { - // bot := getTgBot() - token := os.Getenv(TELEGRAM_BOT_TOKEN_ENV_VAR) - bot, err := tgbotapi.NewBotAPI(token[1 : len(token)-1]) - if err != nil { - log.Error().Err(err) - } - log.Debug().Msg("authorized on account bot_bloodstalker") +// func runTgBot() { +// // bot := getTgBot() +// token := os.Getenv(TELEGRAM_BOT_TOKEN_ENV_VAR) +// bot, err := tgbotapi.NewBotAPI(token[1 : len(token)-1]) +// if err != nil { +// log.Error().Err(err) +// } +// log.Debug().Msg("authorized on account bot_bloodstalker") - update := tgbotapi.NewUpdate(0) - update.Timeout = 60 +// update := tgbotapi.NewUpdate(0) +// update.Timeout = 60 - updates, err := bot.GetUpdatesChan(update) - if err != nil { - log.Error().Err(err) - } +// updates, err := bot.GetUpdatesChan(update) +// if err != nil { +// log.Error().Err(err) +// } - for update := range updates { - if update.Message == nil { - continue - } +// for update := range updates { +// if update.Message == nil { +// continue +// } - log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) +// log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) - msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) - msg.ReplyToMessageID = update.Message.MessageID +// msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) +// msg.ReplyToMessageID = update.Message.MessageID - bot.Send(msg) - } -} +// bot.Send(msg) +// } +// } type priceChanStruct struct { name string @@ -374,15 +373,19 @@ func alertManager() { log.Info().Msg(fmt.Sprintf("result: %v", result)) resultBool = result.(bool) if resultBool == true { - // bot := getTgBot() token := os.Getenv(TELEGRAM_BOT_TOKEN_ENV_VAR) - bot, err := tgbotapi.NewBotAPI(token[1 : len(token)-1]) + // bot, err := tgbotapi.NewBotAPI(token[1 : len(token)-1]) + // if err != nil { + // log.Error().Err(err) + // } + msgText := "notification " + alerts.Alerts[i].Expr + " has been triggered" + // msg := tgbotapi.NewMessage(*botChannelID, msgText) + // bot.Send(msg) + tokenInt, err := strconv.ParseInt(token[1:len(token)-1], 10, 64) if err != nil { - log.Error().Err(err) + log.Fatal().Err(err) } - msgText := "notification " + alerts.Alerts[i].Expr + " has been triggered" - msg := tgbotapi.NewMessage(*botChannelID, msgText) - bot.Send(msg) + sendToTg("telebot:9009", msgText, tokenInt) } } diff --git a/telebot/Dockerfile b/telebot/Dockerfile index 6051f08..8259880 100644 --- a/telebot/Dockerfile +++ b/telebot/Dockerfile @@ -6,7 +6,14 @@ RUN cd /telebot && go mod download COPY *.go /telebot/ RUN cd /telebot && go build -FROM gcr.io/distroless/static-debian10 +FROM node:lts-alpine3.13 as certbuilder +RUN apk add openssl +WORKDIR /certs +RUN openssl req -nodes -new -x509 -subj="/C=US/ST=Denial/L=springfield/O=Dis/CN=localhost" -keyout server.key -out server.cert + +# FROM gcr.io/distroless/static-debian10 +FROM alpine:3.13 +COPY --from=certbuilder /certs /certs COPY --from=builder /telebot/telebot /telebot/ COPY ./docker-entrypoint.sh /telebot/ ENTRYPOINT ["/telebot/docker-entrypoint.sh"] |