-
Notifications
You must be signed in to change notification settings - Fork 45
/
slackbot-robot-standalone.sublime-snippit
57 lines (51 loc) · 2.25 KB
/
slackbot-robot-standalone.sublime-snippit
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
<snippet>
<content>
<![CDATA[
package ${1:${TM_FILENAME/(.*?)(\..+)/$1/}}
import (
"github.com/trinchan/slackbot/robots"
"github.com/trinchan/slackbot/server"
)
type bot struct{}
// Starts the server with a bot for command /${1/(.+)/\L\1/g}.
func main() {
bots := map[string][]robots.Robot{"${1/(.+)/\L\1/g}": []robots.Robot{&bot{}}}
server.Main(bots)
}
// All Robots must implement a Run command to be executed when the registered command is received.
func (r bot) Run(p *robots.Payload) string {
// If you (optionally) want to do some asynchronous work (like sending API calls to slack)
// you can put it in a go routine like this
go r.DeferredAction(p)
// The string returned here will be shown only to the user who executed the command
// and will show up as a message from slackbot.
return "Text to be returned only to the user who made the command."
}
func (r bot) DeferredAction(p *robots.Payload) {
// Let's use the IncomingWebhook struct defined in payload.go to form and send an
// IncomingWebhook message to slack that can be seen by everyone in the room. You can
// read the Slack API Docs (https://api.slack.com/) to know which fields are required, etc.
// You can also see what data is available from the command structure in definitions.go
//
// Alternatively, you can make a SlashCommandResponse, with the same fields, and call
// reponse.Send(p)
response := &robots.IncomingWebhook{
Channel: p.ChannelID,
Username: "${TM_FILENAME/(.*?)(\..+)/\u$1/} Bot",
Text: "Hi there!",
IconEmoji: ":ghost:",
UnfurlLinks: true,
Parse: robots.ParseStyleFull,
}
response.Send()
}
func (r bot) Description() string {
// In addition to a Run method, each Robot must implement a Description method which
// is just a simple string describing what the Robot does. This is used in the included
// /c command which gives users a list of commands and descriptions
return "This is a description for ${TM_FILENAME/(.*?)(\..+)/\u$1/}Bot which will be displayed on /help"
}]]>
</content>
<scope>source.go</scope>
<description>Slackbot Robot: Inserts a Slackbot Robot template based on the current filename.</description>
</snippet>