remove telegram dependency, rely on log alters instead, which indirectly connect to telegram via uptrace

This commit is contained in:
2024-10-31 10:00:39 +03:00
parent 44a9b5cd29
commit 4ba4b72ec6
8 changed files with 11 additions and 89 deletions

View File

@@ -2,10 +2,8 @@ package handler
import (
"context"
"fmt"
"math/big"
"github.com/grassrootseconomics/eth-indexer/internal/telegram"
"github.com/grassrootseconomics/eth-tracker/pkg/event"
"github.com/lmittmann/w3"
"github.com/lmittmann/w3/module/eth"
@@ -28,7 +26,7 @@ func (h *Handler) FaucetHealthCheck(ctx context.Context, event event.Event) erro
}
if balance.Cmp(new(big.Int).Mul(w3.BigEther, big.NewInt(balanceThreshold))) < 0 {
return h.telegram.Notify(ctx, fmt.Sprintf("%s:\n\n %s", event.ContractAddress, telegram.NOTIFY_LOW_BALANCE_ON_GAS_FAUCET))
h.logg.Warn("faucet balance is less than 5 ether", "faucet", event.ContractAddress)
}
return nil

View File

@@ -5,7 +5,6 @@ import (
"github.com/grassrootseconomics/eth-indexer/internal/cache"
"github.com/grassrootseconomics/eth-indexer/internal/store"
"github.com/grassrootseconomics/eth-indexer/internal/telegram"
"github.com/grassrootseconomics/ethutils"
)
@@ -14,7 +13,6 @@ type (
Store store.Store
Cache *cache.Cache
ChainProvider *ethutils.Provider
Telegram *telegram.Telegram
Logg *slog.Logger
}
@@ -22,7 +20,6 @@ type (
store store.Store
cache *cache.Cache
chainProvider *ethutils.Provider
telegram *telegram.Telegram
logg *slog.Logger
}
)
@@ -32,7 +29,6 @@ func NewHandler(o HandlerOpts) *Handler {
store: o.Store,
cache: o.Cache,
chainProvider: o.ChainProvider,
telegram: o.Telegram,
logg: o.Logg,
}
}

View File

@@ -64,7 +64,7 @@ func NewJetStreamSub(o JetStreamOpts) (*JetStreamSub, error) {
iter, err := consumer.Messages(
jetstream.WithMessagesErrOnMissingHeartbeat(false),
jetstream.PullMaxMessages(100),
jetstream.PullMaxMessages(10),
)
if err != nil {
return nil, err

View File

@@ -1,36 +0,0 @@
package telegram
import (
"context"
"github.com/mr-linch/go-tg"
)
type (
TelegramOpts struct {
BotToken string
NotificationChannel int64
}
Telegram struct {
client *tg.Client
notificationChannel int64
}
)
const (
NOTIFY_LOW_BALANCE_ON_GAS_FAUCET = "Gas faucet balance is low. Top-up is required soon!"
)
func New(o TelegramOpts) *Telegram {
return &Telegram{
client: tg.New(o.BotToken),
notificationChannel: o.NotificationChannel,
}
}
func (t *Telegram) Notify(ctx context.Context, message string) error {
_, err := t.client.SendMessage(tg.ChatID(t.notificationChannel), message).Do(ctx)
return err
}