Skip to content

Commit

Permalink
docs: Add slash command example
Browse files Browse the repository at this point in the history
  • Loading branch information
arusso committed Mar 29, 2023
1 parent 4163d7e commit 8a7ea74
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/slash-cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"context"
"log"
"os"

"github.com/shomali11/slacker"
)

// Implements a simple slash command. Assumes you have the slash command
// `/ping` defined for your app.

func main() {
bot := slacker.NewClient(
os.Getenv("SLACK_BOT_TOKEN"),
os.Getenv("SLACK_APP_TOKEN"),
slacker.WithDebug(true),
)

bot.Command("ping", &slacker.CommandDefinition{
Handler: func(botCtx slacker.BotContext, request slacker.Request, response slacker.ResponseWriter) {
response.Reply("pong")
},
HideHelp: true,
})

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

err := bot.Listen(ctx)
if err != nil {
log.Fatal(err)
}

}

0 comments on commit 8a7ea74

Please sign in to comment.