-
Notifications
You must be signed in to change notification settings - Fork 59
/
outputs.go
63 lines (60 loc) · 1.87 KB
/
outputs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package core
import (
"strings"
"github.com/target/flottbot/models"
"github.com/target/flottbot/remote/cli"
"github.com/target/flottbot/remote/discord"
"github.com/target/flottbot/remote/slack"
"github.com/target/flottbot/remote/telegram"
)
// Outputs determines where messages are output based on fields set in the bot.yml
// TODO: Refactor to keep remote specifics in remote/
func Outputs(outputMsgs <-chan models.Message, hitRule <-chan models.Rule, bot *models.Bot) {
for {
message := <-outputMsgs
rule := <-hitRule
service := message.Service
switch service {
case models.MsgServiceChat, models.MsgServiceScheduler:
chatApp := strings.ToLower(bot.ChatApplication)
switch chatApp {
case "discord":
if service == models.MsgServiceScheduler {
bot.Log.Warn().Msg("Scheduler does not currently support Discord")
break
}
remoteDiscord := &discord.Client{Token: bot.DiscordToken}
remoteDiscord.Reaction(message, rule, bot)
remoteDiscord.Send(message, bot)
case "slack":
// Create Slack client
remoteSlack := &slack.Client{
ListenerPort: bot.SlackListenerPort,
Token: bot.SlackToken,
SigningSecret: bot.SlackSigningSecret,
}
if service == models.MsgServiceChat {
if bot.InteractiveComponents {
remoteSlack.InteractiveComponents(nil, &message, rule, bot)
}
remoteSlack.Reaction(message, rule, bot)
}
remoteSlack.Send(message, bot)
case "telegram":
remoteTelegram := &telegram.Client{
Token: bot.TelegramToken,
}
remoteTelegram.Send(message, bot)
default:
bot.Log.Debug().Msgf("Chat application %s is not supported", chatApp)
}
case models.MsgServiceCLI:
remoteCLI := &cli.Client{}
remoteCLI.Send(message, bot)
case models.MsgServiceUnknown:
bot.Log.Error().Msg("Found unknown service")
default:
bot.Log.Error().Msg("No service found")
}
}
}