Documentation ¶
Overview ¶
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\"}" } ] }
Example ¶
package main import ( "github.com/mikegrb/slackwatch/pkg/slackwatch" ) func main() { config := slackwatch.Config{ SlackToken: "xoxp-123", Actions: []slackwatch.Action{ slackwatch.CommandAction{Command: "/usr/bin/afplay", Args: "klaxon.wav"}, slackwatch.URLAction{URL: "https://example.com/trigger_action"}, slackwatch.URLAction{URL: "https://example.com/other_endpoint", Body: "Slackwatch Triggered"}, }, } s := slackwatch.New(config) s.Run() }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action interface {
Execute(Message)
}
An Action 's execute method is called when an interesting message is received if armed.
type CommandAction ¶
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 ¶
Config is passed to the New constructor.
func NewConfigFromFile ¶
NewConfigFromFile parses a json formatted config file and returns a Config.
Example ¶
package main import ( "os" "github.com/mikegrb/slackwatch/pkg/slackwatch" ) func main() { config := slackwatch.NewConfigFromFile(os.Getenv("HOME") + "/.slackwatch") s := slackwatch.New(config) s.Run() }
Output:
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 ¶
DetokenizedText replaces user mentions with their name instead of their ID.
func (Message) IsFromMe ¶
IsFromMe returns true if the user our API token belongs to sent the message.
func (Message) IsInteresting ¶
IsInteresting returns true if we were mentioned or this is a DM.
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.