Chore: Routine Bugfixes and enhancements (#979)

- Fix slack scopes
- Docs for authentication
Fixes: #704 , #973
This commit is contained in:
Sojan Jose
2020-06-25 23:35:16 +05:30
committed by GitHub
parent 0aab717bb3
commit 4f83d5451e
32 changed files with 254 additions and 147 deletions

View File

@@ -17,10 +17,7 @@ class Integrations::Slack::ChannelBuilder
end
def slack_client
Slack.configure do |config|
config.token = hook.access_token
end
Slack::Web::Client.new
@slack_client ||= Slack::Web::Client.new(token: hook.access_token)
end
def find_or_create_channel
@@ -29,6 +26,7 @@ class Integrations::Slack::ChannelBuilder
end
def update_reference_id
@hook.update(reference_id: channel['id'])
slack_client.conversations_join(channel: channel[:id])
@hook.update(reference_id: channel[:id])
end
end

View File

@@ -89,9 +89,6 @@ class Integrations::Slack::IncomingMessageBuilder
end
def slack_client
Slack.configure do |config|
config.token = integration_hook.access_token
end
Slack::Web::Client.new
@slack_client ||= Slack::Web::Client.new(token: @integration_hook.access_token)
end
end

View File

@@ -1,30 +1,23 @@
class Integrations::Slack::OutgoingMessageBuilder
attr_reader :hook, :message
def self.perform(hook, message)
new(hook, message).perform
end
def initialize(hook, message)
@hook = hook
@message = message
end
class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
pattr_initialize [:message!, :hook!]
def perform
return if message.source_id.present?
# overriding the base class logic since the validations are different in this case.
# FIXME: for now we will only send messages from widget to slack
return unless channel.is_a?(Channel::WebWidget)
# we don't want message loop in slack
return if message.source_id.try(:starts_with?, 'slack_')
# we don't want to start slack thread from agent conversation as of now
return if message.outgoing? && conversation.identifier.blank?
send_message
update_reference_id
perform_reply
end
private
def conversation
@conversation ||= message.conversation
end
def contact
@contact ||= conversation.contact
def perform_reply
send_message
update_reference_id
end
def agent
@@ -32,8 +25,9 @@ class Integrations::Slack::OutgoingMessageBuilder
end
def message_content
private_indicator = message.private? ? 'private: ' : ''
if conversation.identifier.present?
message.content
"#{private_indicator}#{message.content}"
else
"*Inbox: #{message.inbox.name}* \n\n #{message.content}"
end
@@ -59,14 +53,10 @@ class Integrations::Slack::OutgoingMessageBuilder
def update_reference_id
return if conversation.identifier
conversation.identifier = @slack_message['ts']
conversation.save!
conversation.update!(identifier: @slack_message['ts'])
end
def slack_client
Slack.configure do |config|
config.token = hook.access_token
end
Slack::Web::Client.new
@slack_client ||= Slack::Web::Client.new(token: hook.access_token)
end
end