From 8a0f16c5333b431aa0e22273403cb521cd9cce0a Mon Sep 17 00:00:00 2001 From: Venky Date: Wed, 26 Apr 2023 06:45:00 +0100 Subject: [PATCH] Do not strip bot name from messages Engines have access to the bot user ID (`TEABOT_USER_ID`) anyway. They can strip it out if they want to. --- backend/slack_backend.go | 11 ++--------- conversation/manager.go | 7 ++++--- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/backend/slack_backend.go b/backend/slack_backend.go index 94762bf..02f7662 100644 --- a/backend/slack_backend.go +++ b/backend/slack_backend.go @@ -137,14 +137,6 @@ func (s *SlackBackend) Read() { // Set up regex to recognise @mentions of bot s.atMePattern = regexp.MustCompile(fmt.Sprintf(`<@%s>`, s.me)) - // Set up the sanitiser to remove references to bot ID in message - logrus.Debug("Setting up message sanitiser") - re := regexp.MustCompile(fmt.Sprintf(`^\s*<@%s>\s+`, s.me)) - s.sanitiser = func(m *message.Message) *message.Message { - m.Text = re.ReplaceAllString(m.Text, "") - return m - } - case *slack.MessageEvent: if s.me == "" { logrus.Debug("Not connected yet!") @@ -231,5 +223,6 @@ func (s SlackBackend) Post() { } func (s SlackBackend) Sanitize(m *message.Message) *message.Message { - return s.sanitiser(m) + // Do nothing + return m } diff --git a/conversation/manager.go b/conversation/manager.go index 837bff0..7f60494 100644 --- a/conversation/manager.go +++ b/conversation/manager.go @@ -287,16 +287,17 @@ func (cm *Manager) GetConversations(ctx context.Context, m *message.Message) []* if config.Threaded { cm.addThreadedConversation(ctx, &c, m.ThreadId) conversations = append(conversations, &c) + logrus.Debugf("New threaded conversation with %s: %+v", config.Name, c) } else { if cm.addChannelConversation(ctx, &c, m.ChannelId, config.Name) { conversations = append(conversations, &c) + logrus.Debugf("New channel conversation with %s: %+v", config.Name, c) } else { - logrus.Debugf("Ignoring trigger as bot already active on channel: %s: %s: %#v", - c.channelName, m.Text, ef) + logrus.Debugf("Ignoring trigger as bot already active: channel='%s' msg='%s' trigger='%s'", + c.channelName, m.Text, re.String()) } } - logrus.Debugf("New conversation with %s: %+v", config.Name, c) } } }