Beispiel #1
0
func main() {
	slackToken := getToken()

	text, err := ioutil.ReadFile("message.txt")
	if err != nil {
		log.Panic(fmt.Sprintf("Error opening message.txt for canned response: %s", err))
	}

	conn, err := slack.Connect(slackToken)

	if err != nil {
		log.Fatal(err)
	}

	slack.EventProcessor(conn,
		func(message *slack.Message) {
			message.Respond(string(text))
		},
		nil)
}
Beispiel #2
0
func Run(slackscot Slackscot, config config.Configuration) (err error) {
	conn, err := slack.Connect(config.Token)
	if err != nil {
		log.Fatal(err)
	}

	// Register all commands and listeners

	var commands []Action
	var listeners []Action

	for _, b := range slackscot.bundles {
		c, l, err := b.Init(config)
		if err != nil {
			return err
		}

		commands = append(commands, c...)
		listeners = append(listeners, l...)
	}

	// Register the close of resources when the process terminates
	defer Close(slackscot)

	for _, c := range commands {
		registerCommand(c)
	}

	for _, l := range listeners {
		registerAction(l)
	}

	slack.EventProcessor(conn, onAskedMessage, onHeardMessage)

	return nil
}