-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (52 loc) · 1.52 KB
/
main.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
package main
import (
"github.com/oliverbenns/whatsapp-chatgpt/internal/env"
"github.com/oliverbenns/whatsapp-chatgpt/internal/prompt"
"github.com/oliverbenns/whatsapp-chatgpt/internal/publish"
"github.com/oliverbenns/whatsapp-chatgpt/internal/service"
"github.com/oliverbenns/whatsapp-chatgpt/internal/subscribe"
"github.com/sashabaranov/go-openai"
"github.com/twilio/twilio-go"
"go.uber.org/zap"
)
func main() {
log, err := zap.NewProduction()
if err != nil {
panic(err)
}
env, err := env.GetEnv()
if err != nil {
log.Fatal("could not get env", zap.Error(err))
}
openAiClient := openai.NewClient(env.OpenAiApiKey)
twilioClient := twilio.NewRestClientWithParams(twilio.ClientParams{
Username: env.TwilioAccountSid,
Password: env.TwilioAuthToken,
})
subscriber := subscribe.NewTwilioSubscriber(&subscribe.NewTwilioSubscriberParams{
Client: twilioClient,
// yes, invert
SendTo: env.TwilioSendFrom,
SendFrom: env.TwilioSendTo,
WebhookPort: 8080,
WebhookPath: "/webhooks/twilio",
})
prompter := prompt.NewOpenAiPrompter(&prompt.NewOpenAiPrompterParams{
Client: openAiClient,
})
publisher := publish.NewTwilioPublisher(&publish.NewTwilioPublisherParams{
Client: twilioClient,
SendTo: env.TwilioSendTo,
SendFrom: env.TwilioSendFrom,
})
svc := service.NewService(&service.NewServiceParams{
Subscriber: subscriber,
Publisher: publisher,
Prompter: prompter,
})
log.Info("starting service")
err = svc.Start()
if err != nil {
log.Fatal("service error", zap.Error(err))
}
}