Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SlackApp ¶
type SlackApp struct { *socketmode.Client // contains filtered or unexported fields }
A SlackApp implements Slack's Events API, using Socket Mode. It connects to Slack, listens for incoming events and makes them available using the Event channel.
Example ¶
package main import ( "context" "github.com/clambin/slackapp" "github.com/slack-go/slack" "github.com/slack-go/slack/slackevents" "github.com/slack-go/slack/socketmode" "log/slog" ) func main() { const ( slackToken = "xoxb-token" appToken = "xapp-token" ) c := slack.New(slackToken, slack.OptionAppLevelToken(appToken)) app := slackapp.NewSlackApp(c, slog.Default()) app.AddEventHandler(string(slackevents.AppMention), func(event slackevents.EventsAPIInnerEvent, client *socketmode.Client) { // process the AppMention event. The details are in event.Data.(*slackevents.AppMentionEvent). }) app.AddSlashCommand("/sing", func(command slack.SlashCommand, client *socketmode.Client) { // process the SlackCommand }) _ = app.Run(context.TODO()) }
Output:
func NewSlackApp ¶
NewSlackApp creates a new slackapp for the slack client.
func (*SlackApp) AddEventHandler ¶
func (h *SlackApp) AddEventHandler(eventType string, f func(event slackevents.EventsAPIInnerEvent, client *socketmode.Client))
func (*SlackApp) AddSlashCommand ¶
func (h *SlackApp) AddSlashCommand(cmd string, f func(slack.SlashCommand, *socketmode.Client))
Click to show internal directories.
Click to hide internal directories.