Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbstjn/hanu
Golang Framework for writing Slack bots
https://github.com/sbstjn/hanu
chat chatops communication framework go golang slack slackbot
Last synced: 14 days ago
JSON representation
Golang Framework for writing Slack bots
- Host: GitHub
- URL: https://github.com/sbstjn/hanu
- Owner: sbstjn
- License: mit
- Created: 2016-09-16T07:10:42.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T05:57:29.000Z (over 1 year ago)
- Last Synced: 2024-07-31T20:36:11.310Z (3 months ago)
- Topics: chat, chatops, communication, framework, go, golang, slack, slackbot
- Language: Go
- Homepage: https://sbstjn.com/host-golang-slackbot-on-heroku-with-hanu.html
- Size: 74.2 KB
- Stars: 154
- Watchers: 8
- Forks: 25
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-go - hanu - Framework for writing Slack bots. (Bot Building)
- awesome-Char - hanu - Framework for writing Slack bots. (Bot Building / Contents)
- awesome-go - hanu - Framework for writing Slack bots. (Bot Building)
- fucking-awesome-go - hanu - Framework for writing Slack bots. (Bot Building)
- awesome-go - hanu - Framework for writing Slack bots. (Bot Building)
- awesome-go - hanu
- awesome-go - hanu - Framework for writing Slack bots. (Bot Building)
- awesome-go - hanu - Framework for writing Slack bots. - :arrow_down:3 - :star:5 (Bot Building)
- awesome-go - hanu - Golang Framework for writing Slack bots - ★ 76 (Miscellaneous)
- awesome-go-cn - hanu
- awesome-go-extra - hanu - 09-16T07:10:42Z|2021-06-16T04:18:00Z| (Bot Building / Free e-books)
- awesome-go-with-stars - hanu - Framework for writing Slack bots. (Bot Building)
- awesome-go-zh - hanu
- awesome-go-plus - hanu - Framework for writing Slack bots. ![stars](https://img.shields.io/badge/stars-154-blue) ![forks](https://img.shields.io/badge/forks-25-blue) (Bot Building)
- awesome-go-plus - hanu - Framework for writing Slack bots. (Bot Building)
README
# hanu - Go for Slack Bots!
[![Current Release](https://badgen.now.sh/github/release/sbstjn/hanu)](https://github.com/sbstjn/hanu/releases)
[![MIT License](https://badgen.now.sh/badge/License/MIT/blue)](https://github.com/sbstjn/hanu/blob/master/LICENSE.md)
[![Read Tutorial](https://badgen.now.sh/badge/Read/Tutorial/orange)](https://sbstjn.com/host-golang-slackbot-on-heroku-with-hanu.html)
[![Code Example](https://badgen.now.sh/badge/Code/Example/cyan)](https://github.com/sbstjn/hanu-example)The `Go` framework **hanu** is your best friend to create [Slack](https://slackhq.com) bots! **hanu** uses [allot](https://github.com/sbstjn/allot) for easy command and request parsing (e.g. `whisper `) and runs fine as a [Heroku worker](https://devcenter.heroku.com/articles/background-jobs-queueing). All you need is a [Slack API token](https://api.slack.com/bot-users) and you can create your first bot within seconds! Just have a look at the [hanu-example](https://github.com/sbstjn/hanu-example) bot or [read my tutorial](https://sbstjn.com/host-golang-slackbot-on-heroku-with-hanu.html) …
### Features
- Respond to **mentions**
- Respond to **direct messages**
- Auto-Generated command list for `help`
- Works fine as a **worker** on Heroku## Usage
Use the following example code or the [hanu-example](https://github.com/sbstjn/hanu-example) bot to get started.
```go
package mainimport (
"log"
"strings""github.com/sbstjn/hanu"
)func main() {
slack, err := hanu.New("SLACK_BOT_API_TOKEN")if err != nil {
log.Fatal(err)
}Version := "0.0.1"
slack.Command("shout ", func(conv hanu.ConversationInterface) {
str, _ := conv.String("word")
conv.Reply(strings.ToUpper(str))
})slack.Command("whisper ", func(conv hanu.ConversationInterface) {
str, _ := conv.String("word")
conv.Reply(strings.ToLower(str))
})slack.Command("version", func(conv hanu.ConversationInterface) {
conv.Reply("Thanks for asking! I'm running `%s`", Version)
})slack.Listen()
}
```The example code above connects to Slack using `SLACK_BOT_API_TOKEN` as the bot's token and can respond to direct messages and mentions for the commands `shout ` , `whisper ` and `version`.
You don't have to care about `help` requests, **hanu** has it built in and will respond with a list of all defined commands on direct messages like this:
```
/msg @hanu help
```Of course this works fine with mentioning you bot's username as well:
```
@hanu help
```### Slack
Use direct messages for communication:
```
/msg @hanu version
```Or use the bot in a public channel:
```
@hanu version
```## Dependencies
- [github.com/sbstjn/allot](https://github.com/sbstjn/allot) for parsing `cmd ` strings
- [golang.org/x/net/websocket](http://golang.org/x/net/websocket) for websocket communication with Slack## Credits
- [Host Go Slackbot on Heroku](https://sbstjn.com/host-golang-slackbot-on-heroku-with-hanu.html)
- [OpsDash article about Slack Bot](https://www.opsdash.com/blog/slack-bot-in-golang.html)