Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Always use the web api to send messages
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jan 27, 2016
1 parent f40290f commit 726f14d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 49 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ gem "lita-slack"
### Optional attributes

* `proxy` (String) – Specify a HTTP proxy URL. (e.g. "http://squid.example.com:3128")
* `send_via_rtm_api` (Symbol) – Defaults to :yes. Whether or not to use the RTM API for sending messages. RTM API does not support advanced formatting (https://api.slack.com/docs/formatting)

**Note**: When using lita-slack, the adapter will overwrite the bot's name and mention name with the values set on the server, so `config.robot.name` and `config.robot.mention_name` will have no effect.

Expand Down
14 changes: 2 additions & 12 deletions lib/lita/adapters/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Slack < Adapter
# Required configuration attributes.
config :token, type: String, required: true
config :proxy, type: String
config :send_via_rtm_api, type: Symbol, default: :yes

# Provides an object for Slack-specific features.
def chat_service
Expand All @@ -29,13 +28,8 @@ def run
end

def send_messages(target, strings)
if send_via_rtm_api?
return unless rtm_connection
rtm_connection.send_messages(channel_for(target), strings)
else
api = API.new(config)
api.send_messages(channel_for(target), strings)
end
api = API.new(config)
api.send_messages(channel_for(target), strings)
end

def set_topic(target, topic)
Expand All @@ -62,10 +56,6 @@ def channel_for(target)
target.room
end
end

def send_via_rtm_api?
config.send_via_rtm_api != :no
end
end

# Register Slack adapter to Lita
Expand Down
36 changes: 0 additions & 36 deletions spec/lita/adapters/slack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,47 +56,11 @@
Lita::Source.new(room: 'C024BE91L', user: user, private_message: true)
end

describe "via the RTM API" do
before do
registry.config.adapters.slack.send_via_rtm_api = :yes
end

it "sends messages to rooms" do
expect(rtm_connection).to receive(:send_messages).with(room_source.room, ['foo'])

subject.run

subject.send_messages(room_source, ['foo'])
end

it "sends messages to users" do
allow(rtm_connection).to receive(:im_for).with(user.id).and_return('D024BFF1M')

expect(rtm_connection).to receive(:send_messages).with('D024BFF1M', ['foo'])

subject.run

subject.send_messages(user_source, ['foo'])
end

it "sends messages to users when the source is marked as a private message" do
allow(rtm_connection).to receive(:im_for).with(user.id).and_return('D024BFF1M')

expect(rtm_connection).to receive(:send_messages).with('D024BFF1M', ['foo'])

subject.run

subject.send_messages(private_message_source, ['foo'])
end
end

describe "via the Web API" do
let(:api) { instance_double('Lita::Adapters::Slack::API') }

before do
allow(Lita::Adapters::Slack::API).to receive(:new).with(subject.config).and_return(api)

registry.config.adapters.slack.send_via_rtm_api = :no
end

it "does not send via the RTM api" do
Expand Down

0 comments on commit 726f14d

Please sign in to comment.