func Start(config *model.Config, wg *sync.WaitGroup, inChan chan *model.ChatMessage, commandrouter *commandrouter.Router, done chan struct{}) { logIn = spacelog.GetLoggerNamed("slack-incoming") logOut = spacelog.GetLoggerNamed("slack-outgoing") api := slack.New(config.SlackKey) StartOutgoing(wg, config, api, inChan, done) // Not ready yet //StartIncomingWebhook(config, commandrouter) }
func StartIncomingRTM(wg *sync.WaitGroup, config *model.Config, api *slack.Client, commandrouter *commandrouter.Router, done chan struct{}) { rtmLogger = spacelog.GetLoggerNamed("slack-rtm") // wg.Add(1) // // go (func() { // rtm := api.NewRTM() // go rtm.ManageConnection() // // for { // select { // case msg := <-rtm.IncomingEvents: // if ev, ok := msg.Data.(*slack.MessageEvent); ok { // // Handle the message // go routeMessage(api, commandrouter, ev) // } // case <-done: // err := rtm.Disconnect() // if err != nil { // rtmLogger.Errorf("Shutting down Slack RTM: %s", err.Error()) // } // wg.Done() // return // } // } // })() }
func Start(config *model.Config, wg *sync.WaitGroup, outChan chan *model.ChatMessage, done chan struct{}) { logger = spacelog.GetLoggerNamed("jira-webhook") replacer = strings.NewReplacer("&", "&", "<", "<", ">", ">") handlers = map[string]WebhookFormatter{ "jira:issue_updated": IssueUpdatedFormatter, // "jira:issue_created": IssueCreatedFormatter, // "jira:issue_deleted": IssueDeletedFormatter, } // Create web server to listen for webhooks http.HandleFunc("/jirahook", func(w http.ResponseWriter, r *http.Request) { handleWebhook(config, outChan, w, r) }) }
func main() { var config *model.Config var err error spacelog.MustSetup("promulgator", spacelog.SetupConfig{Output: "stderr", Stdlevel: "warn"}) mainLogger := spacelog.GetLoggerNamed("main") if config, err = readConfig(); err != nil { mainLogger.Critf("Error reading config: %s\n", err.Error()) os.Exit(1) } // Channel for sending messages out to Slack. slackOutChan := make(chan *model.ChatMessage, 1) // This channel is closed when the server is done. At present, there is no // reason to ever do this, but the option is here. closeChan := make(chan struct{}) wg := &sync.WaitGroup{} // Route incoming messages from Slack to the appropriate destination. router := commandrouter.New() jiraclient.Start(config, wg, router, slackOutChan, closeChan) jirawebhook.Start(config, wg, slackOutChan, closeChan) slackclient.Start(config, wg, slackOutChan, router, closeChan) go func() { // TODO Support TLS. Unimportant for now only because this runs solely // within our own network, using nginx for TLS termination. mainLogger.Noticef("Listening on %s", config.WebHookBind) err := http.ListenAndServe(config.WebHookBind, nil) if err != nil { mainLogger.Crit(err.Error()) os.Exit(1) } }() wg.Wait() router.Close() }
func init() { logRouter = spacelog.GetLoggerNamed("commandrouter") }