Skip to content

Commit

Permalink
feat: slog and client name refactor and example binary
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcguire1 committed Dec 7, 2023
1 parent cde5f8a commit 90f90b6
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 58 deletions.
6 changes: 5 additions & 1 deletion cmd/alexa/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log/slog"
"os"
"strconv"

Expand All @@ -11,8 +12,10 @@ import (
)

func main() {
jsonLogH := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})
logger := slog.New(jsonLogH)
svc := chatgpt.NewClient(&chatgpt.Resources{
Api: chatgpt.NewChatGptClient(os.Getenv("OPENAI_API_KEY")),
Api: chatgpt.NewOpenAiApiClient(os.Getenv("OPENAI_API_KEY")),
})

pollDelay, _ := strconv.Atoi(os.Getenv("POLL_DELAY"))
Expand All @@ -22,6 +25,7 @@ func main() {
RequestsQueue: queue.NewQueue(os.Getenv("REQUESTS_QUEUE_URI")),
ResponsesQueue: queue.NewQueue(os.Getenv("RESPONSES_QUEUE_URI")),
PollDelay: pollDelay,
Logger: logger,
}
lambda.Start(h.Invoke)
}
20 changes: 20 additions & 0 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"context"
"log"
"os"

"github.com/jackmcguire1/alexa-chatgpt/internal/dom/chatgpt"
)

func main() {
svc := chatgpt.NewClient(&chatgpt.Resources{
Api: chatgpt.NewOpenAiApiClient(os.Getenv("OPENAI_API_KEY")),
})
resp, err := svc.AutoComplete(context.Background(), "tell me a random fact")
if err != nil {
log.Fatal(err)
}
log.Println(resp)
}
2 changes: 1 addition & 1 deletion cmd/sqs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (handler *SqsHandler) ProcessSQS(ctx context.Context, event events.SQSEvent
func main() {
h := &SqsHandler{
ChatGptSvc: chatgpt.NewClient(&chatgpt.Resources{
Api: chatgpt.NewChatGptClient(os.Getenv("OPENAI_API_KEY")),
Api: chatgpt.NewOpenAiApiClient(os.Getenv("OPENAI_API_KEY")),
}),
ResponseQueue: queue.NewQueue(os.Getenv("RESPONSES_QUEUE_URI")),
}
Expand Down
23 changes: 12 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ module github.com/jackmcguire1/alexa-chatgpt
go 1.19

require (
github.com/aws/aws-lambda-go v1.39.1
github.com/aws/aws-sdk-go-v2/config v1.18.19
github.com/aws/aws-lambda-go v1.41.0
github.com/aws/aws-sdk-go-v2/config v1.25.12
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.3
github.com/sashabaranov/go-openai v1.5.7
github.com/sashabaranov/go-openai v1.17.9
github.com/stretchr/testify v1.8.4
)

require (
github.com/aws/aws-sdk-go-v2 v1.23.5 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.18 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.16.10 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.8 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.32 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.25 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.6 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.18.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.26.3 // indirect
github.com/aws/smithy-go v1.18.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
54 changes: 25 additions & 29 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,57 +1,53 @@
github.com/aws/aws-lambda-go v1.39.1 h1:UcuX9O3JqhQyP/rxPJEpTUUSehzqkNpwKKRFa9N+ozk=
github.com/aws/aws-lambda-go v1.39.1/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
github.com/aws/aws-sdk-go-v2 v1.17.7/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
github.com/aws/aws-sdk-go-v2 v1.23.5 h1:xK6C4udTyDMd82RFvNkDQxtAd00xlzFUtX4fF2nMZyg=
github.com/aws/aws-sdk-go-v2 v1.23.5/go.mod h1:t3szzKfP0NeRU27uBFczDivYJjsmSnqI8kIvKyWb9ds=
github.com/aws/aws-sdk-go-v2/config v1.18.19 h1:AqFK6zFNtq4i1EYu+eC7lcKHYnZagMn6SW171la0bGw=
github.com/aws/aws-sdk-go-v2/config v1.18.19/go.mod h1:XvTmGMY8d52ougvakOv1RpiTLPz9dlG/OQHsKU/cMmY=
github.com/aws/aws-sdk-go-v2/credentials v1.13.18 h1:EQMdtHwz0ILTW1hoP+EwuWhwCG1hD6l3+RWFQABET4c=
github.com/aws/aws-sdk-go-v2/credentials v1.13.18/go.mod h1:vnwlwjIe+3XJPBYKu1et30ZPABG3VaXJYr8ryohpIyM=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.1 h1:gt57MN3liKiyGopcqgNzJb2+d9MJaKT/q1OksHNXVE4=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.1/go.mod h1:lfUx8puBRdM5lVVMQlwt2v+ofiG/X6Ms+dy0UkG/kXw=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.31/go.mod h1:QT0BqUvX1Bh2ABdTGnjqEjvjzrCfIniM9Sc8zn9Yndo=
github.com/aws/aws-sdk-go-v2/config v1.25.12 h1:mF4cMuNh/2G+d19nWnm1vJ/ak0qK6SbqF0KtSX9pxu0=
github.com/aws/aws-sdk-go-v2/config v1.25.12/go.mod h1:lOvvqtZP9p29GIjOTuA/76HiVk0c/s8qRcFRq2+E2uc=
github.com/aws/aws-sdk-go-v2/credentials v1.16.10 h1:VmRkuoKaGl2ZDNGkkRQgw80Hxj1Bb9a+bsT5shqlCwo=
github.com/aws/aws-sdk-go-v2/credentials v1.16.10/go.mod h1:WEn22lpd50buTs/TDqywytW5xQ2zPOMbYipIlqI6xXg=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.9 h1:FZVFahMyZle6WcogZCOxo6D/lkDA2lqKIn4/ueUmVXw=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.9/go.mod h1:kjq7REMIkxdtcEC9/4BVXjOsNY5isz6jQbEgk6osRTU=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.8 h1:8GVZIR0y6JRIUNSYI1xAMF4HDfV8H/bOsZ/8AD/uY5Q=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.8/go.mod h1:rwBfu0SoUkBUZndVgPZKAD9Y2JigaZtRP68unRiYToQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.25/go.mod h1:zBHOPwhBc3FlQjQJE/D3IfPWiWaQmT06Vq9aNukDo0k=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.8 h1:ZE2ds/qeBkhk3yqYvS3CDCFNvd9ir5hMjlVStLZWrvM=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.8/go.mod h1:/lAPPymDYL023+TS6DJmjuL42nxix2AvEvfjqOBRODk=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.32 h1:p5luUImdIqywn6JpQsW3tq5GNOxKmOnEpybzPx+d1lk=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.32/go.mod h1:XGhIBZDEgfqmFIugclZ6FU7v75nHhBDtzuB4xB/tEi4=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.25 h1:5LHn8JQ0qvjD9L9JhMtylnkcw7j05GDZqM9Oin6hpr0=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.25/go.mod h1:/95IA+0lMnzW6XzqYJRpjjsAbKEORVeO0anQqjd2CNU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1 h1:uR9lXYjdPX0xY+NhvaJ4dD8rpSRz5VY81ccIIoNG+lw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.3 h1:e3PCNeEaev/ZF01cQyNZgmYE9oYYePIMJs2mWSKG514=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.3/go.mod h1:gIeeNyaL8tIEqZrzAnTeyhHcE0yysCtcaP+N9kxLZ+E=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.8 h1:EamsKe+ZjkOQjDdHd86/JCEucjFKQ9T0atWKO4s2Lgs=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.8/go.mod h1:Q0vV3/csTpbkfKLI5Sb56cJQTCTtJ0ixdb7P+Wedqiw=
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.3 h1:l4llGwoF3wWh90bxIFSqCqp9gFRnF8UzqAgJ+A43U2U=
github.com/aws/aws-sdk-go-v2/service/sqs v1.29.3/go.mod h1:enJbiMvMXQCop6h23PU+Q1bJiDPUqnLj670Bm1zjdLM=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.6 h1:5V7DWLBd7wTELVz5bPpwzYy/sikk0gsgZfj40X+l5OI=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.6/go.mod h1:Y1VOmit/Fn6Tz1uFAeCO6Q7M2fmfXSCLeL5INVYsLuY=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.6 h1:B8cauxOH1W1v7rd8RdI/MWnoR4Ze0wIHWrb90qczxj4=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.6/go.mod h1:Lh/bc9XUf8CfOY6Jp5aIkQtN+j1mc+nExc+KXj9jx2s=
github.com/aws/aws-sdk-go-v2/service/sts v1.18.7 h1:bWNgNdRko2x6gqa0blfATqAZKZokPIeM1vfmQt2pnvM=
github.com/aws/aws-sdk-go-v2/service/sts v1.18.7/go.mod h1:JuTnSoeePXmMVe9G8NcjjwgOKEfZ4cOjMuT2IBT/2eI=
github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/aws-sdk-go-v2/service/sso v1.18.3 h1:wKspi1zc2ZVcgZEu3k2Mt4zGKQSoZTftsoUTLsYPcVo=
github.com/aws/aws-sdk-go-v2/service/sso v1.18.3/go.mod h1:zxk6y1X2KXThESWMS5CrKRvISD8mbIMab6nZrCGxDG0=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.3 h1:CxAHBS0BWSUqI7qzXHc2ZpTeHaM9JNnWJ9BN6Kmo2CY=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.3/go.mod h1:7Lt5mjQ8x5rVdKqg+sKKDeuwoszDJIIPmkd8BVsEdS0=
github.com/aws/aws-sdk-go-v2/service/sts v1.26.3 h1:KfREzajmHCSYjCaMRtdLr9boUMA7KPpoPApitPlbNeo=
github.com/aws/aws-sdk-go-v2/service/sts v1.26.3/go.mod h1:7Ld9eTqocTvJqqJ5K/orbSDwmGcpRdlDiLjz2DO+SL8=
github.com/aws/smithy-go v1.18.1 h1:pOdBTUfXNazOlxLrgeYalVnuTpKreACHtc62xLwIB3c=
github.com/aws/smithy-go v1.18.1/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sashabaranov/go-openai v1.5.7 h1:8DGgRG+P7yWixte5j720y6yiXgY3Hlgcd0gcpHdltfo=
github.com/sashabaranov/go-openai v1.5.7/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/sashabaranov/go-openai v1.17.9 h1:QEoBiGKWW68W79YIfXWEFZ7l5cEgZBV4/Ow3uy+5hNY=
github.com/sashabaranov/go-openai v1.17.9/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
36 changes: 27 additions & 9 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"log/slog"

Check failure on line 8 in internal/api/handler.go

View workflow job for this annotation

GitHub Actions / build-deploy

package log/slog is not in GOROOT (/opt/hostedtoolcache/go/1.20.11/x64/src/log/slog)
"time"

"github.com/jackmcguire1/alexa-chatgpt/internal/dom/chatgpt"
Expand All @@ -15,6 +15,7 @@ import (
)

type Handler struct {
Logger *slog.Logger
ChatGptService chatgpt.Service
lastResponse *chatgpt.LastResponse
ResponsesQueue queue.PullPoll
Expand All @@ -30,7 +31,7 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
switch req.Body.Intent.Name {
case alexa.AutoCompleteIntent:
prompt := req.Body.Intent.Slots["prompt"].Value
log.Println("found phrase to autocomplete", prompt)
h.Logger.With("prompt", prompt).Info("found phrase to autocomplete")

err = h.RequestsQueue.PushMessage(ctx, &chatgpt.Request{Prompt: prompt})
if err != nil {
Expand All @@ -47,7 +48,10 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
var response *chatgpt.LastResponse
err = json.Unmarshal(data, &response)
if err != nil {
log.Println("failed to unmarshal response", string(data), err)
h.Logger.
With("error", err).
With("data", string(data)).
Error("failed to unmarshal chatgpt response")
return
}
res = alexa.NewResponse("Autocomplete", response.Response, false)
Expand All @@ -57,6 +61,7 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
}
res = alexa.NewResponse("Autocomplete", "your response will be available momentarily", false)
case alexa.RandomFactIntent:
h.Logger.Debug("random fact")
var randomFact string

execTime := time.Now().UTC()
Expand All @@ -69,7 +74,7 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
h.lastResponse = &chatgpt.LastResponse{Response: randomFact, TimeDiff: time.Since(execTime).String()}

case alexa.LastResponseIntent:
log.Println("fetching last response")
h.Logger.Debug("fetching last response")

var data []byte
data, err = h.ResponsesQueue.PullMessage(ctx, h.PollDelay)
Expand All @@ -81,7 +86,7 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
var response *chatgpt.LastResponse
err = json.Unmarshal(data, &response)
if err != nil {
log.Println("failed to unmarshal response", string(data), err)
h.Logger.With("error", err).Error("failed to unmarshal response")
return
}
res = alexa.NewResponse("Last Response",
Expand All @@ -93,7 +98,6 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
false,
)
h.lastResponse = response
return
}

if h.lastResponse != nil {
Expand All @@ -117,24 +121,28 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
false,
)
case alexa.CancelIntent:
h.Logger.Debug("user has invoked cancelled intent")
res = alexa.NewResponse(
"Next Question",
"okay, i'm listening",
false,
)
case alexa.NoIntent, alexa.StopIntent:
h.Logger.Debug("user has invoked no or stop intent")
res = alexa.NewResponse(
"Bye",
"Good bye",
true,
)
case alexa.FallbackIntent:
h.Logger.Debug("user has invoked fallback intent")
res = alexa.NewResponse(
"Try again!",
"Try again!",
false,
)
default:
h.Logger.Error("user has invoked unsupported intent")
res = alexa.NewResponse(
"unsupported intent",
"unsupported intent!",
Expand All @@ -146,11 +154,13 @@ func (h *Handler) DispatchIntents(ctx context.Context, req alexa.Request) (res a
}

func (h *Handler) Invoke(ctx context.Context, req alexa.Request) (resp alexa.Response, err error) {
log.Println(utils.ToJSON(req))
h.Logger.
With("payload", utils.ToJSON(req)).
Debug("lambda invoked")

switch req.Body.Type {
case alexa.LaunchRequestType:
log.Println("launch request type")
h.Logger.Debug("launch request type found")
resp = alexa.NewResponse("chatGPT",
"Hi, lets begin our conversation!",
false,
Expand All @@ -160,12 +170,20 @@ func (h *Handler) Invoke(ctx context.Context, req alexa.Request) (resp alexa.Res
}

if err != nil {
h.Logger.
With("error", err).
Error("there as an error processing the request")

err = nil
resp = alexa.NewResponse("error",
"an error occurred when processing your prompt",
true,
)
}

log.Println(utils.ToJSON(resp))
h.Logger.
With("response", utils.ToJSON(resp)).
Debug("returning response to alexa")

return
}
Loading

0 comments on commit 90f90b6

Please sign in to comment.