-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.go
89 lines (72 loc) · 2.4 KB
/
api.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package spanner
import "context"
// App is the top level for a chat application.
// Call Run with an event handling function to start the application.
type App interface {
Run(EventHandlerFunc) error
SendCustom(context.Context, CustomEvent) error
}
// EventHandlerFunc represents a function that processes chat events from Spanner.
// This function will be called multiple times and is responsible both for creating
// UI elements and responding to the input received.
type EventHandlerFunc func(context.Context, Event)
// Event represents an event received from the Slack platform.
// It provides functions representing each type of event that can be received.
// For example, ReceivedMessage will return a message that may have been received in this event.
// Functions will return nil if the current event does not match the type of event.
type Event interface {
ReceiveConnected() bool
ReceiveCustomEvent() CustomEvent
ReceiveMessage() ReceivedMessage
ReceiveSlashCommand(command string) SlashCommand
JoinChannel(channelID string)
SendMessage(channelID string) Message
}
// Metadata provides information common to all events.
type Metadata interface {
User() User
Channel() Channel
}
// ModalCreator is an interface that can be used to create Slack modal views.
type ModalCreator interface {
Modal(title string) Modal
}
// SlashCommand represents a received slash command.
// Messages and modal views may be created in response to the command.
type SlashCommand interface {
EphemeralSender
Metadata
ModalCreator
}
// Modal represents a Slack modal view.
// It can be used to create blocks and handle submission or closing of the modal.
type Modal interface {
BlockUI
SubmitButton(title string) ModalSubmission
CloseButton(title string) bool
}
// ModalSubmission handles a modal being submitted.
// It can be used to send a response message or push a new modal onto the stack.
type ModalSubmission interface {
PushModal(title string) Modal
}
// ReceivedMessage represents a message received from Slack.
type ReceivedMessage interface {
Metadata
Text() string
}
type EphemeralSender interface {
SendEphemeralMessage(text string)
}
// Message represents a message that can be sent to Slack.
// Messages are constructed using BlockUI commands.
type Message interface {
BlockUI
HasError
Channel(channelID string)
}
type NonInteractiveMessage interface {
NonInteractiveBlockUI
HasError
Channel(channelID string)
}