forked from shomali11/slacker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
48 lines (39 loc) · 1.1 KB
/
context.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
package slacker
import (
"context"
"github.com/slack-go/slack"
"github.com/slack-go/slack/socketmode"
)
// A BotContext interface is used to respond to an event
type BotContext interface {
Context() context.Context
Event() *MessageEvent
SocketMode() *socketmode.Client
Client() *slack.Client
}
// NewBotContext creates a new bot context
func NewBotContext(ctx context.Context, client *slack.Client, socketmode *socketmode.Client, evt *MessageEvent) BotContext {
return &botContext{ctx: ctx, event: evt, client: client, socketmode: socketmode}
}
type botContext struct {
ctx context.Context
event *MessageEvent
client *slack.Client
socketmode *socketmode.Client
}
// Context returns the context
func (r *botContext) Context() context.Context {
return r.ctx
}
// Event returns the slack message event
func (r *botContext) Event() *MessageEvent {
return r.event
}
// SocketMode returns the SocketMode client
func (r *botContext) SocketMode() *socketmode.Client {
return r.socketmode
}
// Client returns the slack client
func (r *botContext) Client() *slack.Client {
return r.client
}