-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
951e9b8
commit 4b3f735
Showing
4 changed files
with
50 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,60 @@ | ||
package slack | ||
|
||
// eventer interface represents a pipe along which messages can be sent | ||
type eventer interface { | ||
// Write the message to the specified channel | ||
Write(string, string) error | ||
} | ||
|
||
// Message type represents a message received from Slack | ||
type Message struct { | ||
// a pipe for sending responses to this message | ||
eventStream eventer | ||
|
||
// the strategy for sending the response - depending upon how the message was received e.g. a reply if | ||
// addressed specifically to the bot or a send if not | ||
responseStrategy func(*Message, string) error | ||
|
||
// the text content of the message | ||
Text string | ||
|
||
// the name of the user whom the message is from | ||
From string | ||
|
||
fromId string | ||
// id of the user the message is from | ||
fromId string | ||
|
||
// channel on which the message was received | ||
channel string | ||
} | ||
|
||
//type responder func(string) | ||
|
||
// Send a new message on the specified channel | ||
func (m *Message) Tell(channel string, text string) error { | ||
return m.eventStream.Write(channel, text) | ||
} | ||
|
||
// Send a new message on the channel this message was received on | ||
func (m *Message) Send(text string) error { | ||
return m.eventStream.Write(m.channel, text) | ||
} | ||
|
||
// Send a reply to the user who sent this message on the same channel it was received on | ||
func (m *Message) Reply(text string) error { | ||
return m.Send("<@" + m.fromId + ">: " + text) | ||
} | ||
|
||
// Send a message in a way that matches the way in which this message was received e.g. | ||
// if this message was addressed then send a reply back to person who sent the message. | ||
func (m *Message) Respond(text string) error { | ||
return m.responseStrategy(m, text) | ||
} | ||
|
||
// response strategy for replying | ||
func reply(m *Message, text string) error { | ||
return m.Reply(text) | ||
} | ||
|
||
// response strategy for sending | ||
func send(m *Message, text string) error { | ||
return m.Send(text) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters