Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve BotKube commands without '@' mention in DMs #25

Merged
merged 3 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helm/botkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replicaCount: 1

image:
repository: infracloud/botkube
tag: "0.3"
tag: "0.4"
pullPolicy: Always

nameOverride: ""
Expand Down
36 changes: 33 additions & 3 deletions pkg/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,42 @@ func (b *Bot) Start() {
logging.Logger.Debug("Connection Info: ", ev.Info)

case *slack.MessageEvent:
// Serve only if mentioned
if !strings.HasPrefix(ev.Text, "<@"+botID+"> ") {
// Check if message posted in a channel
chanInfo, _ := api.GetChannelInfo(ev.Channel)

// Check if message posted in a group
groupInfo, _ := api.GetGroupInfo(ev.Channel)
PrasadG193 marked this conversation as resolved.
Show resolved Hide resolved

if chanInfo != nil || groupInfo != nil {
// Message posted in a channel/group
// Serve only if starts with mention
if !strings.HasPrefix(ev.Text, "<@"+botID+"> ") {
continue
}
logging.Logger.Debugf("Slack incoming message: %+v", ev)
msg := strings.TrimPrefix(ev.Text, "<@"+botID+"> ")
PrasadG193 marked this conversation as resolved.
Show resolved Hide resolved
sm := slackMessage{
ChannelID: ev.Channel,
BotID: botID,
InMessage: msg,
RTM: rtm,
}
sm.HandleMessage(b.AllowKubectl)
continue
}

// Message posted as a DM
// Skip if message posted by BotKube
if ev.User == botID {
PrasadG193 marked this conversation as resolved.
Show resolved Hide resolved
continue
}
logging.Logger.Debugf("Slack incoming message: %+v", ev)
msg := strings.TrimPrefix(ev.Text, "<@"+botID+"> ")
msg := ev.Text

// Trim @BotKube prefix if exists
if strings.HasPrefix(ev.Text, "<@"+botID+"> ") {
msg = strings.TrimPrefix(ev.Text, "<@"+botID+"> ")
}
sm := slackMessage{
ChannelID: ev.Channel,
BotID: botID,
Expand Down