/
notify.go
78 lines (71 loc) · 2.1 KB
/
notify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package notify
import (
"github.com/Khan/genqlient/graphql"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/golang-module/carbon/v2"
"github.com/grassrootseconomics/celoutils"
hasura "github.com/grassrootseconomics/cic-notify/internal/graphql"
"github.com/grassrootseconomics/cic-notify/internal/locale"
"github.com/grassrootseconomics/cic-notify/internal/store"
"github.com/grassrootseconomics/cic-notify/internal/tasker"
"github.com/kamikazechaser/africastalking"
"github.com/redis/go-redis/v9"
"github.com/zerodha/logf"
)
type (
Opts struct {
AtApiKey string
AtUsername string
AtSandbox bool
AtShortCode string
CeloProvider *celoutils.Provider
DisablePush bool
HasuraAdminSecret string
HasuraEndpoint string
Logg logf.Logger
RedisClient *redis.Client
Store store.Store
TaskerClient *tasker.TaskerClient
TgBotToken string
Timezone string
}
Notify struct {
AtClient *africastalking.AtClient
AtShortCode string
CeloProvider *celoutils.Provider
DisablePush bool
GraphQLClient graphql.Client
Logg logf.Logger
RedisClient *redis.Client
Store store.Store
TaskerClient *tasker.TaskerClient
TgClient *tgbotapi.BotAPI
Timezone string
Templates *locale.Templates
}
)
func New(o Opts) (*Notify, error) {
localizedTemplates, err := locale.InitTemplates()
if err != nil {
return nil, err
}
notifyContainer := Notify{
AtClient: africastalking.New(o.AtApiKey, o.AtUsername, o.AtSandbox),
AtShortCode: o.AtShortCode,
CeloProvider: o.CeloProvider,
DisablePush: o.DisablePush,
GraphQLClient: hasura.NewHasuraGraphQLClient(o.HasuraAdminSecret, o.HasuraEndpoint),
Logg: o.Logg,
RedisClient: o.RedisClient,
Store: o.Store,
TaskerClient: o.TaskerClient,
Timezone: carbon.Moscow,
Templates: localizedTemplates,
}
bot, err := tgbotapi.NewBotAPI(o.TgBotToken)
if err != nil {
return nil, err
}
notifyContainer.TgClient = bot
return ¬ifyContainer, nil
}