Exemple #1
0
func processIncomingSlack(ctx context.Context, commandrouter *commandrouter.Router,
	command string, user string, inChannel string, toBot bool, responseChan chan string) {

	msg := model.ChatMessage{
		FromUser: user,
		Channel:  inChannel,
		Text:     strings.TrimSpace(command),
		ToBot:    toBot,
	}

	handled, err := commandrouter.Route(ctx, &msg, responseChan)
	if err != nil {
		logIn.Errorf("commandrouter: %s", err.Error())
		// TODO Make this message configurable?
		select {
		case responseChan <- "Internal error, please see bot logs":
		default:
		}
	} else if !handled {
		responseChan <- "I didn't recognize that command"
	}
}
Exemple #2
0
// Start the Jira client goroutine
func Start(config *model.Config, wg *sync.WaitGroup,
	commandrouter *commandrouter.Router,
	outChan chan *model.ChatMessage, done chan struct{}) {

	wg.Add(1)

	httpClient := http.Client{}
	httpClient.Timeout = time.Duration(config.RequestTimeout) * time.Millisecond
	jiraClient, err := jira.NewClient(nil, config.JiraUrl)
	if err != nil {
		panic(err)
	}

	processor := &JiraCommands{
		Client: jiraClient,
	}

	incoming, err := commandrouter.AddDestination("JiraCommands", commands)
	if err != nil {
		panic(err)
	}

	go func() {
	Loop:
		for {
			select {
			case match := <-incoming:
				match.Response <- processor.Process(match.Tag, match.Message)
			case <-done:
				break Loop
			}
		}
		wg.Done()
	}()

}