-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjiphy.go
45 lines (36 loc) · 984 Bytes
/
jiphy.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
package main
import (
"context"
"errors"
"os"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
utils "github.com/jwilsson/go-bot-utils"
)
func handleRequest(ctx context.Context, request events.LambdaFunctionURLRequest) (events.LambdaFunctionURLResponse, error) {
if !utils.VerifySecret(request, os.Getenv("SLACK_SIGNING_SECRET")) {
return utils.CreateResponse(403), errors.New("invalid signature header")
}
s, err := utils.ParseBody(request)
if err != nil {
return utils.CreateResponse(400), err
}
images, err := getImages(ctx, os.Getenv("DYNAMO_TABLE_NAME"))
if err != nil {
return utils.CreateResponse(500), err
}
err = sendMessage(MessageInput{
Command: s.Command,
ImageName: s.Text,
Images: images,
ResponseURL: s.ResponseURL,
UserName: s.UserName,
})
if err != nil {
return utils.CreateResponse(500), err
}
return utils.CreateResponse(200), err
}
func main() {
lambda.Start(handleRequest)
}