Use generic ‘conversations’ API endpoint to enable transcripts for slack IMs and groups

This commit is contained in:
David Taylor 2018-04-08 02:27:49 +01:00
parent 180011c097
commit 427cfc2305
3 changed files with 7 additions and 7 deletions

View File

@ -201,12 +201,12 @@ module DiscourseChat::Provider::SlackProvider
http = Net::HTTP.new("slack.com", 443) http = Net::HTTP.new("slack.com", 443)
http.use_ssl = true http.use_ssl = true
req = Net::HTTP::Post.new(URI('https://slack.com/api/channels.history')) req = Net::HTTP::Post.new(URI('https://slack.com/api/conversations.history'))
data = { data = {
token: SiteSetting.chat_integration_slack_access_token, token: SiteSetting.chat_integration_slack_access_token,
channel: @channel_id, channel: @channel_id,
count: count limit: count
} }
req.set_form_data(data) req.set_form_data(data)

View File

@ -196,7 +196,7 @@ describe 'Slack Command Controller', type: :request do
context "with valid slack responses" do context "with valid slack responses" do
before do before do
stub_request(:post, "https://slack.com/api/users.list").to_return(body: '{"ok":true,"members":[{"id":"U5Z773QLS","name":"david","profile":{"icon_24":"https://example.com/avatar"}}]}') stub_request(:post, "https://slack.com/api/users.list").to_return(body: '{"ok":true,"members":[{"id":"U5Z773QLS","name":"david","profile":{"icon_24":"https://example.com/avatar"}}]}')
stub_request(:post, "https://slack.com/api/channels.history").to_return(body: { ok: true, messages: messages_fixture }.to_json) stub_request(:post, "https://slack.com/api/conversations.history").to_return(body: { ok: true, messages: messages_fixture }.to_json)
end end
it 'generates the transcript UI properly' do it 'generates the transcript UI properly' do

View File

@ -105,7 +105,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
describe 'loading history' do describe 'loading history' do
it 'loads messages correctly' do it 'loads messages correctly' do
stub_request(:post, "https://slack.com/api/channels.history") stub_request(:post, "https://slack.com/api/conversations.history")
.with(body: hash_including(token: "abcde", channel: 'G1234')) .with(body: hash_including(token: "abcde", channel: 'G1234'))
.to_return(status: 200, body: { ok: true, messages: messages_fixture }.to_json) .to_return(status: 200, body: { ok: true, messages: messages_fixture }.to_json)
@ -113,14 +113,14 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
end end
it 'handles failed connection' do it 'handles failed connection' do
stub_request(:post, "https://slack.com/api/channels.history") stub_request(:post, "https://slack.com/api/conversations.history")
.to_return(status: 500, body: {}.to_json) .to_return(status: 500, body: {}.to_json)
expect(transcript.load_chat_history).to be_falsey expect(transcript.load_chat_history).to be_falsey
end end
it 'handles slack failure' do it 'handles slack failure' do
stub_request(:post, "https://slack.com/api/channels.history") stub_request(:post, "https://slack.com/api/conversations.history")
.to_return(status: 200, body: { ok: false }.to_json) .to_return(status: 200, body: { ok: false }.to_json)
expect(transcript.load_chat_history).to be_falsey expect(transcript.load_chat_history).to be_falsey
@ -129,7 +129,7 @@ RSpec.describe DiscourseChat::Provider::SlackProvider::SlackTranscript do
context 'with loaded messages' do context 'with loaded messages' do
before do before do
stub_request(:post, "https://slack.com/api/channels.history") stub_request(:post, "https://slack.com/api/conversations.history")
.with(body: hash_including(token: "abcde", channel: 'G1234')) .with(body: hash_including(token: "abcde", channel: 'G1234'))
.to_return(status: 200, body: { ok: true, messages: messages_fixture }.to_json) .to_return(status: 200, body: { ok: true, messages: messages_fixture }.to_json)
transcript.load_chat_history transcript.load_chat_history