Skip to content

ChrisMcKee/hanu

 
 

Repository files navigation

hanu <forked> - Go for Slack Bots!

MIT License

The Go framework hanu is your best friend to create Slack bots! hanu uses allot for easy command and request parsing (e.g. whisper <word>) and runs fine as a Heroku worker. All you need is a Slack API token and you can create your first bot within seconds! Just have a look at the hanu-example bot or read my tutorial

Features

  • Respond to mentions
  • Respond to direct messages
  • Auto-Generated command list for help
  • Works fine as a worker on Heroku

V3 Release Note

  • Swapped RTM for SocketMode

V2 Usage

To use the package import:

import "github.com/ChrisMcKee/hanu"

It is very similar to the above, but there are a few extra things. You can set the command prefix, if you like using those:

slack.SetCommandPrefix("!")
slack.SetReplyOnly(false)

This will make it so you have to type:

!whisper I love turtles

For the command to be recognized. Setting the bot to not reply only means it will listen to all messages in an attempt to find a command (except help will only be printed when bot is mentioned).

Also, the ConversationInterface was changed to just Convo to save your wrists:

	slack.Command("whisper <word>", func(conv hanu.Convo) {
		str, _ := conv.String("word")
		conv.Reply(strings.ToLower(str))
	})

The bot can also now talk arbitrarily:

slack.Say("UGHXISDF324", "I like %s", "turtles")

devops := slack.Channel("UGHXISDF324")
devops.Say("Host called %s is not responding to pings", "bobsburgers01")

You can print the help message whenever you want:

slack.Say("UGHXISDF324", bot.BuildHelpText())

And there is an unknown command handler, but it only works when in reply only mode:

slack.SetReplyOnly(true).UnknownCommand(func(c hanu.Convo) {
	c.Reply(slack.BuildHelpText())
})

Dependencies

Credits

Forked (along with allot) from

  • Read Tutorial
  • Code Example