Skip to content

Commit

Permalink
SlackClient: allow returning raw text to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Jul 3, 2017
1 parent ad634a5 commit d34fc7d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SlackBot extends Adapter
Message received from Slack
###
message: (message) =>
{text, rawText, user, channel, subtype, topic, bot} = message
{text, rawText, returnRawText, user, channel, subtype, topic, bot} = message

return if user && (user.id == @self.id) # Ignore anything we sent, or anything from an unknown user
return if bot && (bot.id == @self.bot_id) # Ignore anything we sent, or anything from an unknown bot
Expand All @@ -174,7 +174,10 @@ class SlackBot extends Adapter

when 'message', 'bot_message'
@robot.logger.debug "Received message: '#{text}' in channel: #{channel.name}, from: #{user.name}"
textMessage = new SlackTextMessage(user, text, rawText, message)
if returnRawText
textMessage = new SlackTextMessage(user, text, rawText, message)
else
textMessage = new TextMessage(user, text, message.ts)
textMessage.thread_ts = message.thread_ts
@receive textMessage

Expand Down
3 changes: 3 additions & 0 deletions src/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SlackClient
# Track listeners for easy clean-up
@listeners = []

@returnRawText = !options.noRawText

###
Open connection to the Slack RTM API
###
Expand All @@ -44,6 +46,7 @@ class SlackClient
{user, channel, bot_id} = message

message.rawText = message.text
message.returnRawText = @returnRawText
message.text = @format.incoming(message)
message.user = @rtm.dataStore.getUserById(user) if user
message.bot = @rtm.dataStore.getBotById(bot_id) if bot_id
Expand Down
5 changes: 3 additions & 2 deletions test/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ describe 'Handling incoming messages', ->
user: @stubs.user,
channel: @stubs.channel,
text: 'foo http://www.example.com bar',
rawText: 'foo <http://www.example.com> bar'
rawText: 'foo <http://www.example.com> bar',
returnRawText: true
}
@slackbot.message messageData
should.equal (@stubs._received instanceof SlackTextMessage), true
Expand Down Expand Up @@ -203,7 +204,7 @@ describe 'Handling incoming messages', ->
should.equal (@stubs._received instanceof CatchAllMessage), true

it 'Should not crash with bot messages', ->
@slackbot.message { subtype: 'bot_message', bot: @stubs.bot, channel: @stubs.channel, text: 'Pushing is the answer' }
@slackbot.message { subtype: 'bot_message', bot: @stubs.bot, channel: @stubs.channel, text: 'Pushing is the answer', returnRawText: true }
should.equal (@stubs._received instanceof SlackTextMessage), true

it 'Should ignore messages it sent itself', ->
Expand Down

0 comments on commit d34fc7d

Please sign in to comment.