forked from shomali11/slacker
/
main.go
49 lines (41 loc) · 1.25 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
package main
import (
"context"
"log"
"os"
"github.com/shomali11/slacker/v2"
)
// Showcase the ability to define Cron Jobs
func main() {
bot := slacker.NewClient(os.Getenv("SLACK_BOT_TOKEN"), os.Getenv("SLACK_APP_TOKEN"))
bot.AddCommand(&slacker.CommandDefinition{
Command: "ping",
Handler: func(ctx *slacker.CommandContext) {
ctx.Response().Reply("pong")
},
})
// ┌───────────── minute (0 - 59)
// │ ┌───────────── hour (0 - 23)
// │ │ ┌───────────── day of the month (1 - 31)
// │ │ │ ┌───────────── month (1 - 12)
// │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
// │ │ │ │ │
// │ │ │ │ │
// │ │ │ │ │
// * * * * * (cron expression)
// Run every minute
bot.AddJob(&slacker.JobDefinition{
CronExpression: "*/1 * * * *",
Name: "SomeJob",
Description: "A cron job that runs every minute",
Handler: func(ctx *slacker.JobContext) {
ctx.Response().Post("#test", "Hello!")
},
})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := bot.Listen(ctx)
if err != nil {
log.Fatal(err)
}
}