summaryrefslogtreecommitdiff
path: root/main.go
blob: 9632cf005619a667a030e2a4040314f8ded7d003 (plain) (blame)
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
package main

import (
	"crypto/tls"
	"encoding/json"
	"fmt"
	"github.com/labstack/echo"
	"log"
	"net/http"
)

func main() {
	//token := os.Getenv("TOKEN")
	e := echo.New()
	e.POST("/events-endpoint", func(c echo.Context) error {
		ev := struct {
			Payload string `form:"payload"`
		}{}
		c.Bind(&ev)
		pl := &payload{}
		if err := json.Unmarshal([]byte(ev.Payload), pl); err != nil {
			return err
		}
		// TODO how to get members???
		//members, err := getUsers(token, pl.Channel.ID)
		//if err != nil {
		//	return err
		//}
		members := []string{
			"U8UJT0UJX",
			"UCF7JA5CZ",
			"UC86HMG1G",
			"UCFHM9G04",
			"UC9GZ0C2J",
		}
		member := getRandomMember(members, pl.User.ID)
		text := fmt.Sprintf("Назначен: <@%s>", member)
		return sendMessage(pl.ResponseUrl, pl.Message.Text, text)
	})
	if err := e.Start(":3000"); err != nil {
		log.Fatalln(err)
	}
}

func getClient() *http.Client {
	transCfg := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	return &http.Client{Transport: transCfg}
}