-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 1.18 KB
/
main.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
package main
import (
"context"
"fmt"
"log"
"os"
"strconv"
"github.com/shomali11/slacker"
)
func printCommandEvents(analyticsChannel <-chan *slacker.CommandEvent) {
for event := range analyticsChannel {
fmt.Println("Command Evenets")
fmt.Println(event.Timestamp)
fmt.Println(event.Command)
fmt.Println(event.Parameters)
fmt.Println(event.Event)
fmt.Println()
}
}
func main() {
os.Setenv("SLACK_BOT_TOKEN", "") //check tokens file
os.Setenv("SLACK_APP_TOKEN", "") //check tokens file
bot := slacker.NewClient(os.Getenv("SLACK_BOT_TOKEN"), os.Getenv("SLACK_APP_TOKEN"))
go printCommandEvents(bot.CommandEvents())
bot.Command("my yob is <year>", &slacker.CommandDefinition{
Description: "yob calculator",
//Example: "my yob is 2020",
Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) {
year := request.Param("year")
yob, err := strconv.Atoi(year)
if err != nil {
println("error")
}
age := 2021 - yob
r := fmt.Sprintf("age is %d", age)
response.Reply(r)
},
})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := bot.Listen(ctx)
if err != nil {
log.Fatal(err)
}
}