slackbot

package module
v0.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2020 License: MIT Imports: 15 Imported by: 0

README

GitHub Workflow Status Go Report Card GitHub tag (latest SemVer) PkgGoDev

Slackbot

A simple callback-based framework for quickly building Slack Bots in Go built on https://github.com/slack-go/slack.

It supports:

Install

go get github.com/bushelpowered/slackbot

Basic Example

package main

import (
	"github.com/bushelpowered/slackbot"
	"github.com/slack-go/slack"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"
)

// Boot a bot with a slash command that posts "Hello World!" and message listener.
func main() {
	bot := slackbot.NewBot(os.Getenv("SLACK_TOKEN"), os.Getenv("SLACK_SIGNING_SECRET"))

	// register a slash command
	bot.RegisterCommand("myslashcommand", func(bot *slackbot.Bot, command slack.SlashCommand) *slack.Msg {
		log.Println(command.Text)
		return &slack.Msg{Text: "Hello World!"} // return nil for no reply
	})

	// register a message event
	bot.RegisterMessageEvent(func(bot *slackbot.Bot, c slackbot.MessageEventContainer) {
		log.Println(c.Event.Text)
	})

	// boot the bot
	err := bot.Boot(":8000")
	if err != nil {
		log.Println(err)
		return
	}
	defer bot.Shutdown(time.Second * 10)

	// wait for exit
	quit := make(chan os.Signal)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
	<-quit

	log.Print("Shutting down...")
}

See more examples in examples.

Documentation

Overview

Package slackbot is a callback-based Slack Bot framework for Go.

For more information visit https://github.com/bushelpowered/slackbot

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyBooted = errors.New("bot already booted")
View Source
var ErrBadPayload = errors.New("bad payload")
View Source
var ErrEmptyPayload = errors.New("empty payload")
View Source
var ErrUnknownOptionsCallback = errors.New("unknown options callback")

Functions

This section is empty.

Types

type AppHomeOpenedEventCallback

type AppHomeOpenedEventCallback = func(bot *Bot, c AppHomeOpenedEventContainer)

type AppHomeOpenedEventContainer

type AppHomeOpenedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.AppHomeOpenedEvent
}

type AppMentionEventCallback

type AppMentionEventCallback = func(bot *Bot, c AppMentionEventContainer)

type AppMentionEventContainer

type AppMentionEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.AppMentionEvent
}

type AppUninstalledEventCallback

type AppUninstalledEventCallback = func(bot *Bot, c AppUninstalledEventContainer)

type AppUninstalledEventContainer

type AppUninstalledEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.AppUninstalledEvent
}

type BlockActionFilter

type BlockActionFilter struct {
	ActionID string
	BlockID  string
}

Filter for RegisterBlockActionsInteraction

  • specify an ActionID to filter for only certain actions
  • specify a BlockID for filter for only certain blocks

type Bot

type Bot struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBot

func NewBot(token string, signingSecret string) *Bot

Create a new Bot with given bot token and app signing secret

func (*Bot) Api

func (b *Bot) Api() *slack.Client

Get a slack.Client for interacting with the API

func (*Bot) Boot

func (b *Bot) Boot(listenAddr string) error

Start the bot on the given listen address

func (*Bot) BootWithEngine

func (b *Bot) BootWithEngine(listenAddr string, engine *gin.Engine) error

Start the bot on the given listen address with a pre-configured instance of gin.Engine.

func (*Bot) RegisterAppHomeOpenedEvent

func (b *Bot) RegisterAppHomeOpenedEvent(callback AppHomeOpenedEventCallback)

Register a callback for app_home_opened events

func (*Bot) RegisterAppMentionEvent

func (b *Bot) RegisterAppMentionEvent(callback AppMentionEventCallback)

Register a callback for app_mention events

func (*Bot) RegisterAppUninstalledEvent

func (b *Bot) RegisterAppUninstalledEvent(callback AppUninstalledEventCallback)

Register a callback for app_uninstalled events

func (*Bot) RegisterBlockActionsInteraction

func (b *Bot) RegisterBlockActionsInteraction(filter BlockActionFilter, callback InteractionCallback)

Register a callback for block_actions interactions with a specified BlockActionFilter

func (*Bot) RegisterCommand

func (b *Bot) RegisterCommand(name string, callback CommandCallback)

Register a slash command callback

func (*Bot) RegisterGridMigrationFinishedEvent

func (b *Bot) RegisterGridMigrationFinishedEvent(callback GridMigrationFinishedEventCallback)

Register a callback for grid_migration_finished events

func (*Bot) RegisterGridMigrationStartedEvent

func (b *Bot) RegisterGridMigrationStartedEvent(callback GridMigrationStartedEventCallback)

Register a callback for grid_migration_started events

func (*Bot) RegisterKeyword

func (b *Bot) RegisterKeyword(regex *regexp.Regexp, callback KeywordCallback)

Register a message event keyword regex callback.

func (*Bot) RegisterLinkSharedEvent

func (b *Bot) RegisterLinkSharedEvent(callback LinkSharedEventCallback)

Register a callback for link_shared events

func (*Bot) RegisterMemberJoinedChannelEvent

func (b *Bot) RegisterMemberJoinedChannelEvent(callback MemberJoinedChannelEventCallback)

Register a callback for member_joined_channel events

func (*Bot) RegisterMemberLeftChannelEvent

func (b *Bot) RegisterMemberLeftChannelEvent(callback MemberLeftChannelEventCallback)

Register a callback for member_left_channel events

func (*Bot) RegisterMessageActionInteraction

func (b *Bot) RegisterMessageActionInteraction(callbackId string, callback InteractionCallback)

Register a callback for message_action interactions with a specific callbackId

func (*Bot) RegisterMessageEvent

func (b *Bot) RegisterMessageEvent(callback MessageEventCallback)

Register a callback for message events

func (*Bot) RegisterPinAddedEvent

func (b *Bot) RegisterPinAddedEvent(callback PinAddedEventCallback)

Register a callback for pin_added events

func (*Bot) RegisterPinRemovedEvent

func (b *Bot) RegisterPinRemovedEvent(callback PinRemovedEventCallback)

Register a callback for pin_removed events

func (*Bot) RegisterReactionAddedEvent

func (b *Bot) RegisterReactionAddedEvent(callback ReactionAddedEventCallback)

Register a callback for reaction_added events

func (*Bot) RegisterReactionRemovedEvent

func (b *Bot) RegisterReactionRemovedEvent(callback ReactionRemovedEventCallback)

Register a callback for reaction_removed events

func (*Bot) RegisterSelectOptionGroups

func (b *Bot) RegisterSelectOptionGroups(callbackId string, callback SelectMenuOptionsGroupCallback)

Register a select option groups callback

func (*Bot) RegisterSelectOptions

func (b *Bot) RegisterSelectOptions(callbackId string, callback SelectMenuOptionsCallback)

Register a select options callback

func (*Bot) RegisterShortcutInteraction

func (b *Bot) RegisterShortcutInteraction(callbackId string, callback InteractionCallback)

Register a callback for shortcut interactions with a specific callbackId

func (*Bot) RegisterTokensRevokedEvent

func (b *Bot) RegisterTokensRevokedEvent(callback TokensRevokedEventCallback)

Register a callback for tokens_revoked events

func (*Bot) RegisterViewClosedInteraction

func (b *Bot) RegisterViewClosedInteraction(callbackId string, callback InteractionCallback)

Register a callback for view_closed interactions with a specific callbackId

func (*Bot) RegisterViewSubmissionInteraction

func (b *Bot) RegisterViewSubmissionInteraction(callbackId string, callback ViewSubmissionInteractionCallback)

Register a callback for view_submission interactions with a specific callbackId Callback may return a slack.ViewSubmissionResponse or nil for no response

func (*Bot) SetLogger

func (b *Bot) SetLogger(logger *logrus.Logger)

Set a pre-configured logrus.Logger to provide a consistent logging experience in your bot.

func (*Bot) Shutdown

func (b *Bot) Shutdown(timeout time.Duration)

Shutdown the bot gracefully with a given timeout

type CommandCallback

type CommandCallback = func(bot *Bot, command slack.SlashCommand) *slack.Msg

type GridMigrationFinishedEventCallback

type GridMigrationFinishedEventCallback = func(bot *Bot, c GridMigrationFinishedEventContainer)

type GridMigrationFinishedEventContainer

type GridMigrationFinishedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.GridMigrationFinishedEvent
}

type GridMigrationStartedEventCallback

type GridMigrationStartedEventCallback = func(bot *Bot, c GridMigrationStartedEventContainer)

type GridMigrationStartedEventContainer

type GridMigrationStartedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.GridMigrationStartedEvent
}

type InteractionCallback

type InteractionCallback = func(bot *Bot, event slack.InteractionCallback)

type KeywordCallback

type KeywordCallback = func(bot *Bot, container MessageEventContainer)

type LinkSharedEventCallback

type LinkSharedEventCallback = func(bot *Bot, c LinkSharedEventContainer)

type LinkSharedEventContainer

type LinkSharedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.LinkSharedEvent
}

type MemberJoinedChannelEventCallback

type MemberJoinedChannelEventCallback = func(bot *Bot, c MemberJoinedChannelEventContainer)

type MemberJoinedChannelEventContainer

type MemberJoinedChannelEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.MemberJoinedChannelEvent
}

type MemberLeftChannelEventCallback

type MemberLeftChannelEventCallback = func(bot *Bot, c MemberLeftChannelEventContainer)

type MemberLeftChannelEventContainer

type MemberLeftChannelEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.MemberLeftChannelEvent
}

type MessageEventCallback

type MessageEventCallback = func(bot *Bot, c MessageEventContainer)

type MessageEventContainer

type MessageEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.MessageEvent
}

type PinAddedEventCallback

type PinAddedEventCallback = func(bot *Bot, c PinAddedEventContainer)

type PinAddedEventContainer

type PinAddedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.PinAddedEvent
}

type PinRemovedEventCallback

type PinRemovedEventCallback = func(bot *Bot, c PinRemovedEventContainer)

type PinRemovedEventContainer

type PinRemovedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.PinRemovedEvent
}

type ReactionAddedEventCallback

type ReactionAddedEventCallback = func(bot *Bot, c ReactionAddedEventContainer)

type ReactionAddedEventContainer

type ReactionAddedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.ReactionAddedEvent
}

type ReactionRemovedEventCallback

type ReactionRemovedEventCallback = func(bot *Bot, c ReactionRemovedEventContainer)

type ReactionRemovedEventContainer

type ReactionRemovedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.ReactionRemovedEvent
}

type SelectMenuOptionsCallback

type SelectMenuOptionsCallback = func(bot *Bot, interaction slack.InteractionCallback) slack.OptionsResponse

type SelectMenuOptionsGroupCallback

type SelectMenuOptionsGroupCallback = func(bot *Bot, interaction slack.InteractionCallback) slack.OptionGroupsResponse

type TokensRevokedEventCallback

type TokensRevokedEventCallback = func(bot *Bot, c TokensRevokedEventContainer)

type TokensRevokedEventContainer

type TokensRevokedEventContainer struct {
	APIEvent slackevents.EventsAPIEvent
	Event    slackevents.TokensRevokedEvent
}

type ViewSubmissionInteractionCallback

type ViewSubmissionInteractionCallback = func(bot *Bot, event slack.InteractionCallback) *slack.ViewSubmissionResponse

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL