https://github.com/dutchcoders/slackbot
Slackbot implementation library for Go. Easy creation of new SlashCommands and Bots.
https://github.com/dutchcoders/slackbot
Last synced: 3 months ago
JSON representation
Slackbot implementation library for Go. Easy creation of new SlashCommands and Bots.
- Host: GitHub
- URL: https://github.com/dutchcoders/slackbot
- Owner: dutchcoders
- License: mit
- Created: 2015-03-02T20:36:25.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-21T06:50:10.000Z (about 10 years ago)
- Last Synced: 2025-03-25T12:12:55.965Z (3 months ago)
- Language: Go
- Homepage:
- Size: 180 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slackbot
Slackbot implementation library for Go. Easy creation of new SlackCommands and Bots.```
package mainimport (
"errors"
"log"
"math/rand"
"os"
"strings"
"sync"
"time"slackbot "github.com/dutchcoders/slackbot"
"github.com/nlopes/slack"
)func main() {
engine := slackbot.NewEngine(slackbot.Config{
PayloadToken: os.Getenv("SLACK_PAYLOAD_TOKEN"),
})engine.AddCommand("/pick", pick)
go func() {
bot, err := slackbot.NewBot(slackbot.Config{
Token: os.Getenv("SLACK_TOKEN"),
Origin: "http://localhost",
})if err != nil {
log.Println(err)
return
}bot.SetMessageHandler(func(b *slackbot.Bot, message *slackbot.Message) error {
log.Println(message.Text)
return nil
})err = bot.Run()
if err != nil {
log.Println(err)
}
}()addr := ":" + os.Getenv("PORT")
if err := engine.ListenAndServe(addr); err != nil {
panic(err)
}}
func pick(sc *slackbot.Context, w http.ResponseWriter) {
choices := strings.Split(sc.Text, ",")
choice := choices[rand.Intn(len(choices))]
choice = strings.Trim(choice, " ")
fmt.Fprintf(w, "Hmmm, I'd say pick %s.", choice)
}
```## Testing
```
curl -X POST --data "text=test&trigger_word={word}&command={/command}" http://127.0.0.1:5100/
```## Contributions
Contributions are welcome.
## Creators
**Remco Verhoef**
-
-## Copyright and license
Code and documentation copyright 2011-2014 Remco Verhoef.
Code released under [the MIT license](LICENSE).