Skip to content

Commit a2b375f

Browse files
committed
feat: improve notification format and add proxy/timezone support
- Add emoji tags for event types (PUSH, RELEASE, ISSUE, PR) - Strip markdown formatting from issue/PR body for cleaner display - Add proxy support for Telegram API (HTTP/SOCKS5) - Add timezone configuration for notification timestamps - Add /test command to preview all notification formats - Add inline keyboard buttons for subscription management - Fix unchecked error returns (lint errors)
1 parent 21db97a commit a2b375f

9 files changed

Lines changed: 504 additions & 72 deletions

File tree

cmd/bot/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
cfg, err := config.Load(*configPath)
2929
if err != nil {
3030
// Try to initialize basic logger for error output
31-
logger.Init(true, "")
31+
_ = logger.Init(true, "")
3232
logger.Fatal().Err(err).Msg("Failed to load configuration")
3333
}
3434

@@ -41,6 +41,13 @@ func main() {
4141
logger.Info().Msg("Starting GitHub Telegram Bot")
4242
logger.Info().Str("mode", cfg.GitHub.Mode).Msg("GitHub monitoring mode")
4343

44+
// Set timezone
45+
if err := github.SetTimezone(cfg.Timezone); err != nil {
46+
logger.Warn().Err(err).Str("timezone", cfg.Timezone).Msg("Invalid timezone, using UTC")
47+
} else {
48+
logger.Info().Str("timezone", cfg.Timezone).Msg("Timezone configured")
49+
}
50+
4451
// Initialize database
4552
db, err := storage.NewDatabase(cfg.Database.Path)
4653
if err != nil {
@@ -55,7 +62,7 @@ func main() {
5562
ghClient := github.NewClient(cfg.GitHub.Token)
5663

5764
// Initialize Telegram bot
58-
bot, err := telegram.NewBot(cfg.Telegram.Token, cfg.Telegram.Debug, store, ghClient)
65+
bot, err := telegram.NewBot(cfg.Telegram.Token, cfg.Telegram.Debug, cfg.Telegram.Proxy, store, ghClient)
5966
if err != nil {
6067
logger.Fatal().Err(err).Msg("Failed to initialize Telegram bot")
6168
}
@@ -95,7 +102,7 @@ func main() {
95102
// Health check endpoint
96103
r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
97104
w.WriteHeader(http.StatusOK)
98-
w.Write([]byte("OK"))
105+
_, _ = w.Write([]byte("OK"))
99106
})
100107

101108
// GitHub webhook endpoint (if webhook or both mode)

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/mattn/go-sqlite3 v1.14.32
1111
github.com/rs/zerolog v1.34.0
1212
github.com/spf13/viper v1.21.0
13+
golang.org/x/net v0.49.0
1314
golang.org/x/oauth2 v0.34.0
1415
)
1516

@@ -27,6 +28,6 @@ require (
2728
github.com/spf13/pflag v1.0.10 // indirect
2829
github.com/subosito/gotenv v1.6.0 // indirect
2930
go.yaml.in/yaml/v3 v3.0.4 // indirect
30-
golang.org/x/sys v0.29.0 // indirect
31-
golang.org/x/text v0.28.0 // indirect
31+
golang.org/x/sys v0.40.0 // indirect
32+
golang.org/x/text v0.33.0 // indirect
3233
)

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
6767
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
6868
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
6969
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
70+
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
71+
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
7072
golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
7173
golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
7274
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7375
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7476
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
75-
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
76-
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
77-
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
78-
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
77+
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
78+
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
79+
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
80+
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
7981
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8082
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8183
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=

internal/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ type Config struct {
1515
Database DatabaseConfig `mapstructure:"database"`
1616
Server ServerConfig `mapstructure:"server"`
1717
Log LogConfig `mapstructure:"log"`
18+
Timezone string `mapstructure:"timezone"` // Timezone for notifications, e.g., "Asia/Shanghai", "UTC"
1819
}
1920

2021
// TelegramConfig holds Telegram bot configuration.
2122
type TelegramConfig struct {
2223
Token string `mapstructure:"token"`
2324
Debug bool `mapstructure:"debug"`
25+
Proxy string `mapstructure:"proxy"` // HTTP/SOCKS5 proxy URL, e.g., "socks5://127.0.0.1:1080" or "http://127.0.0.1:7890"
2426
}
2527

2628
// GitHubConfig holds GitHub API configuration.
@@ -60,6 +62,7 @@ func Load(configPath string) (*Config, error) {
6062
v.SetDefault("telegram.debug", false)
6163
v.SetDefault("github.mode", "polling") // Default to polling for monitoring any repo
6264
v.SetDefault("github.poll_interval", 300) // 5 minutes default
65+
v.SetDefault("timezone", "UTC") // Default timezone
6366

6467
// Read config file
6568
if configPath != "" {

0 commit comments

Comments
 (0)