-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslack.go
62 lines (56 loc) · 1.2 KB
/
slack.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
package main
import (
"github.com/slack-go/slack"
"github.com/yuin/gluamapper"
"github.com/yuin/gopher-lua"
"os"
)
func slackWebhookMessage(L *lua.LState) int {
a := L.CheckString(1)
msg := slack.WebhookMessage{
Text: a,
}
token := "https://hooks.slack.com/services/" + os.Getenv("SLACK_WEBHOOK")
err := slack.PostWebhook(token, &msg)
if err != nil {
L.Push(lua.LNil)
L.Push(lua.LString(err.Error()))
return 2
}
L.Push(lua.LTrue)
return 1
}
func slackWebhookAttachment(L *lua.LState) int {
a := L.CheckTable(1)
var gostubs slack.Attachment
{
err := gluamapper.Map(a, &gostubs)
if err != nil {
L.Push(lua.LNil)
L.Push(lua.LString(err.Error()))
return 2
}
}
msg := slack.WebhookMessage{
Attachments: []slack.Attachment{gostubs},
}
token := "https://hooks.slack.com/services/" + os.Getenv("SLACK_WEBHOOK")
err := slack.PostWebhook(token, &msg)
if err != nil {
L.Push(lua.LNil)
L.Push(lua.LString(err.Error()))
return 2
}
L.Push(lua.LTrue)
return 1
}
func slackLoader(L *lua.LState) int {
t := L.NewTable()
L.SetFuncs(t, slackApi)
L.Push(t)
return 1
}
var slackApi = map[string]lua.LGFunction{
"attachment": slackWebhookAttachment,
"message": slackWebhookMessage,
}