summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <alexander@kiryukhin.su>2019-02-01 01:20:38 +0300
committerAlexander Kiryukhin <alexander@kiryukhin.su>2019-02-01 01:20:38 +0300
commit8c499a32b7bb614814da84bace3f3e924be92465 (patch)
tree3bc9d97a01fdb6e4bf219d5de81f1873232fe696 /main.go
parentfc9aefc97d872ec8faed767a7b9e2a89ee8630f0 (diff)
fixes
Diffstat (limited to 'main.go')
-rw-r--r--main.go98
1 files changed, 28 insertions, 70 deletions
diff --git a/main.go b/main.go
index e3d2228..9632cf0 100644
--- a/main.go
+++ b/main.go
@@ -1,92 +1,50 @@
package main
import (
- "bytes"
+ "crypto/tls"
"encoding/json"
- "errors"
+ "fmt"
"github.com/labstack/echo"
- "io/ioutil"
"log"
"net/http"
)
-type event struct {
- Payload string `form:"payload"`
-}
-
-type payload struct {
- Type string `json:"type" form:"type"`
- Token string `json:"token"`
- ActionTS string `json:"action_ts"`
-
- Team struct {
- ID string `json:"id"`
- Domain string `json:"domain"`
- }
- User struct {
- ID string `json:"id"`
- Name string `json:"name"`
- } `json:"user"`
- Channel struct {
- ID string `json:"id"`
- Name string `json:"name"`
- } `json:"channel"`
- CallbackID string `json:"callback_id"`
- TriggerID string `json:"trigger_id"`
- MessageTS string `json:"message_ts"`
- Message struct {
- ClientMsgID string `json:"client_msg_id"`
- Type string `json:"type"`
- Text string `json:"text"`
- User string `json:"user"`
- TS string `json:"ts"`
- } `json:"message"`
- ResponseUrl string `json:"response_url"`
-}
-
-type message struct {
- Text string `json:"text"`
- ResponseType string `json:"response_type"`
- Attachments []Attachment `json:"attachments"`
-}
-type Attachment struct {
- Color string `json:"color"`
- Text string `json:"text"`
-}
-
func main() {
+ //token := os.Getenv("TOKEN")
e := echo.New()
e.POST("/events-endpoint", func(c echo.Context) error {
- ev := &event{}
- c.Bind(ev)
+ ev := struct {
+ Payload string `form:"payload"`
+ }{}
+ c.Bind(&ev)
pl := &payload{}
if err := json.Unmarshal([]byte(ev.Payload), pl); err != nil {
- log.Println(err)
return err
}
-
- member := getRandomMember()
- text := "Назначен: " + member
- jm := message{
- Text: pl.Message.Text,
- ResponseType: "in_channel",
- Attachments: []Attachment{{Text: text, Color: "#36a64f"}},
- }
- b, _ := json.Marshal(jm)
- resp, err := http.DefaultClient.Post(pl.ResponseUrl, "application/json", bytes.NewReader(b))
- if err != nil {
- return err
- }
- if resp.StatusCode >= 300 || resp.StatusCode < 200 {
- return errors.New("unexpected status " + resp.Status)
+ // TODO how to get members???
+ //members, err := getUsers(token, pl.Channel.ID)
+ //if err != nil {
+ // return err
+ //}
+ members := []string{
+ "U8UJT0UJX",
+ "UCF7JA5CZ",
+ "UC86HMG1G",
+ "UCFHM9G04",
+ "UC9GZ0C2J",
}
- defer resp.Body.Close()
- s, _ := ioutil.ReadAll(resp.Body)
- log.Println(string(s))
-
- return nil
+ 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}
+}