diff --git a/cmd/delegatebot/service/slack/message_parser.go b/cmd/delegatebot/service/slack/message_parser.go index 46e4cb3..f4b6f93 100644 --- a/cmd/delegatebot/service/slack/message_parser.go +++ b/cmd/delegatebot/service/slack/message_parser.go @@ -49,8 +49,17 @@ func (p *MessageParser) ParseMessage(msg slack.Msg) (*message.Message, error) { Text: msg.Text, } + // include attachments + for _, attachment := range msg.Attachments { + if attachment.Fallback == "" { + continue + } + + incoming.Text = fmt.Sprintf("%s\n\n---\n\n%s", incoming.Text, attachment.Fallback) + } + if msg.Channel[0] == 'D' { // TODO better way to detect if this is our bot DM? - matches := reChannelMention.FindStringSubmatch(msg.Text) + matches := reChannelMention.FindStringSubmatch(incoming.Text) if len(matches) > 0 { incoming.InterruptTarget = matches[1] } @@ -58,11 +67,11 @@ func (p *MessageParser) ParseMessage(msg slack.Msg) (*message.Message, error) { incoming.OriginType = message.DirectMessageOriginType return incoming, nil - } else if !p.reMention.MatchString(msg.Text) { + } else if !p.reMention.MatchString(incoming.Text) { return nil, nil } - matches := p.reChannelMention.FindStringSubmatch(msg.Text) + matches := p.reChannelMention.FindStringSubmatch(incoming.Text) if len(matches) > 0 { incoming.InterruptTarget = matches[1] } diff --git a/cmd/delegatebot/service/slack/message_parser_test.go b/cmd/delegatebot/service/slack/message_parser_test.go index 6976878..b65d813 100644 --- a/cmd/delegatebot/service/slack/message_parser_test.go +++ b/cmd/delegatebot/service/slack/message_parser_test.go @@ -69,6 +69,21 @@ var _ = Describe("MessageParser", func() { Expect(res).To(BeNil()) }) + It("parses attachment fallback", func() { + msg.Attachments = []slack.Attachment{ + { + Fallback: msg.Text, + }, + } + + msg.Text = "something else entirely" + + res, err := subject.ParseMessage(msg) + Expect(err).NotTo(HaveOccurred()) + Expect(res).ToNot(BeNil()) + Expect(res.Text).To(Equal("something else entirely\n\n---\n\nhelp me, <@U1234567> you're my only hope.")) + }) + Context("direct messages", func() { BeforeEach(func() { msg.Channel = "D1234567"