Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pass a handler to Bot.Command #26

Closed
moos3 opened this issue Aug 1, 2018 · 3 comments
Closed

Can't pass a handler to Bot.Command #26

moos3 opened this issue Aug 1, 2018 · 3 comments

Comments

@moos3
Copy link

moos3 commented Aug 1, 2018

So I have the following code:

func handleHello(request *slacker.Request, response slacker.ResponseWriter) {
	name := request.Param("name")
	if name == "" {
		response.Reply("Usage: @hellobot hello Name")
		return 
	}
	response.Reply("Hey " + name + "!")
}

func main() {
	bot := slacker.NewClient(os.Getenv("API_TOKEN"))
	bot.Command("hello <name>", "Say hello to someone", handleHello)
	err := bot.Listen()
	if err != nil {
		panic(err)
	}
}

but it's throwing an error if I use a function instead of defining a function in the Command call. Thoughts on this?

error is:

cannot use handle (type func(*slacker.Request, slacker.ResponseWriter)) as type func(slacker.Request, slacker.ResponseWriter) in argument to bot.Command
@shomali11
Copy link
Owner

A PR was recently merged to change the slacker.Request object to become an interface.

Try dropping the * in *slacker.Request in your func definition.

@moos3
Copy link
Author

moos3 commented Aug 1, 2018 via email

@shomali11
Copy link
Owner

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants