Feature: Slack - receive messages, create threads, send replies (#974)

Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
Sojan Jose
2020-06-22 13:19:26 +05:30
committed by GitHub
parent aa8a85b8bd
commit 1ef8d03e18
53 changed files with 815 additions and 188 deletions

View File

@@ -10,7 +10,7 @@ describe Integrations::Slack::HookBuilder do
hooks_count = account.hooks.count
builder = described_class.new(account: account, code: code)
builder.stub(:fetch_access_token) { token }
allow(builder).to receive(:fetch_access_token).and_return(token)
builder.perform
expect(account.hooks.count).to eql(hooks_count + 1)

View File

@@ -5,7 +5,7 @@ describe Integrations::Slack::IncomingMessageBuilder do
let(:message_params) { slack_message_stub }
let(:verification_params) { slack_url_verification_stub }
let(:hook) { create(:integrations_hook, account: account, reference_id: message_params[:event][:channel]) }
let!(:hook) { create(:integrations_hook, account: account, reference_id: message_params[:event][:channel]) }
let!(:conversation) { create(:conversation, identifier: message_params[:event][:thread_ts]) }
describe '#perform' do
@@ -19,8 +19,10 @@ describe Integrations::Slack::IncomingMessageBuilder do
context 'when message creation' do
it 'creates message' do
expect(hook).not_to eq nil
messages_count = conversation.messages.count
builder = described_class.new(message_params)
allow(builder).to receive(:sender).and_return(nil)
builder.perform
expect(conversation.messages.count).to eql(messages_count + 1)
end

View File

@@ -14,15 +14,16 @@ describe Integrations::Slack::OutgoingMessageBuilder do
builder = described_class.new(hook, message)
stub_request(:post, 'https://slack.com/api/chat.postMessage')
.to_return(status: 200, body: '', headers: {})
slack_client = double
expect(builder).to receive(:slack_client).and_return(slack_client)
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Slack::Web::Client).to receive(:chat_postMessage).with(
expect(slack_client).to receive(:chat_postMessage).with(
channel: hook.reference_id,
text: message.content,
username: contact.name,
thread_ts: conversation.identifier
username: "Contact: #{contact.name}",
thread_ts: conversation.identifier,
icon_url: anything
)
# rubocop:enable RSpec/AnyInstance
builder.perform
end