-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathoutput.go
39 lines (32 loc) · 1.32 KB
/
output.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
package sarah
// Output defines an interface that each outgoing message must satisfy.
type Output interface {
// Destination returns the destination the output is to be sent.
Destination() OutputDestination
// Content returns the sending payload.
Content() interface{}
}
// OutputMessage represents an outgoing message.
type OutputMessage struct {
destination OutputDestination
content interface{}
}
var _ Output = (*OutputMessage)(nil)
// NewOutputMessage creates a new instance of an Output implementation -- OutputMessage -- with the given OutputDestination and the payload.
func NewOutputMessage(destination OutputDestination, content interface{}) Output {
return &OutputMessage{
destination: destination,
content: content,
}
}
// Destination returns its destination in a form of OutputDestination.
// Each Bot/Adapter implementation must explicitly define an OutputDestination implementation
// so that Bot.SendMessage and Adapter.SendMessage can specify where the message should be directed to.
func (output *OutputMessage) Destination() OutputDestination {
return output.destination
}
// Content returns a sending payload.
// Each Bot/Adapter must be capable of properly handling the payload and sending the message to the given destination.
func (output *OutputMessage) Content() interface{} {
return output.content
}