bot

package
v0.0.0-...-5861b17 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package bot defines a basic slack bot that can listen for app mention events for our bot and send the message to a handler to handle the interaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot provides a slack bot for listening to slack channels.

func New

func New(api *slack.Client, client *socketmode.Client) (*Bot, error)

New creates a new Bot.

func (*Bot) Register

func (b *Bot) Register(r *regexp.Regexp, h HandleFunc)

Register registers a function for handling a message to the bot. The regex is checked in the order that it is added. A nil regexp is considered the default handler. Only 1 default handler can be added and is always the choice of last resort.

func (*Bot) Start

func (b *Bot) Start()

Start starts listening for events from the socket client. This blocks until the client dies or Stop() is called.

func (*Bot) Stop

func (b *Bot) Stop()

Stop stops the bot. The bot cannot be reused after this.

type HandleFunc

type HandleFunc func(ctx context.Context, m Message)

HandleFunc receive the user who sent a message and the message. It can then use api or client to respond to said message.

type Message

type Message struct {
	// User has the user information on who mentioned the bot.
	User *slack.User
	// AppMention gives information on the event.
	AppMention *slackevents.AppMentionEvent
	// Text gives the text of the message without the @User stuff. If you want the full message, see AppMention.
	Text string
}

Message details information about a message that was sent in an AppMention event.

Jump to

Keyboard shortcuts

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