Skip to content

slasher makes it easy to write http servers that respond to slack slash commands

Notifications You must be signed in to change notification settings

autom8ter/slasher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slasher

-- import "github.com/autom8ter/slasher"

Usage

func ExampleHandler

func ExampleHandler()

type HandlerFunc

type HandlerFunc func(s *Slasher, client *slack.Client, command *slack.SlashCommand) (interface{}, error)

A handler func is run against an incoming slack slash command. It is up to the user of this library to define their own handlers

type Slasher

type Slasher struct {
}

Slasher holds a slack client, a map of functions map[string]HandlerFunc and an array of allowed users

func NewSlasher

func NewSlasher(token string) *Slasher

Creates a newe slasher instance

func (*Slasher) AddHandler

func (s *Slasher) AddHandler(command string, function HandlerFunc)

Adds a slack slash command handler

func (*Slasher) BashScipt

func (s *Slasher) BashScipt(script string) ([]byte, error)

runs exec.Command("/bin/sh", "-c", script)

func (*Slasher) CommandHandlers

func (s *Slasher) CommandHandlers() []string

Names of all supported slash commands

func (*Slasher) DeleteHandler

func (s *Slasher) DeleteHandler(command string)

Deletes a handler delete(s.functions, command)

func (*Slasher) Error

func (s *Slasher) Error(w http.ResponseWriter, err error)

Writes a wrapped Slasher error to the response

func (*Slasher) Exec

func (s *Slasher) Exec(args ...string) ([]byte, error)

runs exec.Command(args[0], args[1:]...)

func (*Slasher) Exists

func (s *Slasher) Exists(command string) bool

Checks if a function exists for the command

func (*Slasher) HandlerFunc

func (s *Slasher) HandlerFunc() http.HandlerFunc

func (*Slasher) JSON

func (s *Slasher) JSON(w http.ResponseWriter, obj interface{})

Writes pretty json to the response

func (*Slasher) Python3Script

func (s *Slasher) Python3Script(cmd string) ([]byte, error)

runs exec.Command("python3", "-c", cmd)

func (*Slasher) ShellScript

func (s *Slasher) ShellScript(script string) ([]byte, error)

exec.Command("/bin/sh", "-c", script)

func (*Slasher) String

func (s *Slasher) String(w http.ResponseWriter, response string)

Writes the string to the response

About

slasher makes it easy to write http servers that respond to slack slash commands

Topics

Resources

Stars

Watchers

Forks

Packages