Version: v0.1.0 Latest Latest

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 11 Imported by: 0



Package slackwatch preforms configured actions when DMed on Slack. Out of the box, it expects a JSON formatted config file named .slackwatch in your home directory.

  "SlackToken": "xoxp-123-543",
  "Actions": [
    { "Command": "/usr/bin/afplay", "Args": "klaxon.wav" },
    { "URL": "https://hassio.local/api/services/homeassistant/turn_on?api_password=letmein",
      "Body": "{\"entity_id\":\"switch.bat_signal\"}"
package main

import (

func main() {
	config := slackwatch.Config{
		SlackToken: "xoxp-123",
		Actions: []slackwatch.Action{
			slackwatch.CommandAction{Command: "/usr/bin/afplay", Args: "klaxon.wav"},
			slackwatch.URLAction{URL: ""},
			slackwatch.URLAction{URL: "", Body: "Slackwatch Triggered"},

	s := slackwatch.New(config)




This section is empty.


This section is empty.


This section is empty.


type Action

type Action interface {

An Action 's execute method is called when an interesting message is received if armed.

type CommandAction

type CommandAction struct {
	Command string
	Args    string

CommandAction specifies a command to execute on Alert

func (CommandAction) Execute

func (c CommandAction) Execute(m Message)

Execute is called to run the command.

type Config

type Config struct {
	SlackToken string
	Actions    []Action

Config is passed to the New constructor.

func NewConfigFromFile

func NewConfigFromFile(path string) Config

NewConfigFromFile parses a json formatted config file and returns a Config.

package main

import (


func main() {
	config := slackwatch.NewConfigFromFile(os.Getenv("HOME") + "/.slackwatch")
	s := slackwatch.New(config)

type Message

type Message struct {
	Timestamp string
	ChannelID string // of the form C02G9FMGB
	Channel   string // without preceeding #
	UserID    string // of the form U3L6DT8P3
	User      string
	Text      string // raw text of the message, you probably want DetokenizedText()
	// contains filtered or unexported fields

Message represents an incomming message

func (Message) DetokenizedText

func (m Message) DetokenizedText() string

DetokenizedText replaces user mentions with their name instead of their ID.

func (Message) IsFromMe

func (m Message) IsFromMe() bool

IsFromMe returns true if the user our API token belongs to sent the message.

func (Message) IsInteresting

func (m Message) IsInteresting() bool

IsInteresting returns true if we were mentioned or this is a DM.

func (Message) String

func (m Message) String() string

type Slackwatch

type Slackwatch struct {
	// contains filtered or unexported fields

Slackwatch struct holds state. You should call New(config) rather than creating it yourself.

func New

func New(config Config) *Slackwatch

New creates a slackwatch instance and returns a pointer to it.

func (*Slackwatch) Run

func (s *Slackwatch) Run()

Run is a blocking call that makes the connection to Slack and handles incoming events.

type URLAction

type URLAction struct {
	URL  string
	Body string

URLAction specifies an HTTP request to make on Alert

func (URLAction) Execute

func (u URLAction) Execute(m Message)

Execute is called to make the HTTP request

Jump to

Keyboard shortcuts

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