slackcommander

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 10 Imported by: 1

README

Simple mini-framework to create command line applications in Slack.

Usage

package main

import (
   "github.com/mtyurt/slackcommander"
)

func main() {
	mux := &slackcommander.SlackMux{}
	mux.Token = "commaseparatedslacktokenshere"
	helpCommand := slackcommander.CommandDef{Handler: func(args slackcommander.CommandArgs) (*slackcommander.CommandResponse, error) {
		resp := slackcommander.SimpleTextResponse("Hello, " + args.User)
		return &resp, nil

	}}
	mux.RegisterCommandHandler("help", helpCommand)
	http.HandleFunc("/", mux.SlackHandler())
	http.ListenAndServe(":8080", nil)
}

You can register commands like this, this mini-framework handles HTTP request parsing, command matching, invalid commands, and preparing response format with returned string.

Documentation

Index

Constants

View Source
const NullStr = rune(0)

Variables

This section is empty.

Functions

func ParseArgs added in v1.1.0

func ParseArgs(str string) ([]string, error)

Types

type CommandArgs

type CommandArgs struct {
	User        string
	Command     string
	Args        []string
	FullText    string
	ResponseURL string
	ChannelID   string
	UserID      string
}

type CommandDef

type CommandDef struct {
	Handler    CommandHandler
	NoResponse bool
}

type CommandHandler

type CommandHandler func(args CommandArgs) (*CommandResponse, error)

type CommandResponse

type CommandResponse struct {
	Attachments []slack.Attachment `json:"attachments"`
	Markdown    bool               `json:"markdown"`
}

func SimpleTextResponse

func SimpleTextResponse(text string) CommandResponse

type SlackMux

type SlackMux struct {
	Token                 string
	SkipSlackResponse     bool
	IgnoreSlackFormatting bool
	QuoteAwareArgParse    bool
	// contains filtered or unexported fields
}

func (*SlackMux) ClearCommandHandlers

func (mux *SlackMux) ClearCommandHandlers()

func (*SlackMux) RegisterCommandHandler

func (mux *SlackMux) RegisterCommandHandler(command string, cmdDef CommandDef)

func (*SlackMux) RegisterDefaultHandler

func (mux *SlackMux) RegisterDefaultHandler(cmdDef CommandDef)

func (*SlackMux) SlackHandler

func (mux *SlackMux) SlackHandler() func(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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