feat: Add send message, fix issues with message conditions (#4423)
Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
This commit is contained in:
@@ -22,8 +22,6 @@ class AutomationRules::ActionService
|
||||
private
|
||||
|
||||
def send_attachments(_file_params)
|
||||
return if @rule.event_name == 'message_created'
|
||||
|
||||
blobs = @rule.files.map { |file, _| file.blob }
|
||||
params = { content: nil, private: false, attachments: blobs }
|
||||
mb = Messages::MessageBuilder.new(nil, @conversation, params)
|
||||
@@ -44,6 +42,10 @@ class AutomationRules::ActionService
|
||||
@conversation.snoozed!
|
||||
end
|
||||
|
||||
def resolve_conversation(_params)
|
||||
@conversation.resolved!
|
||||
end
|
||||
|
||||
def change_status(status)
|
||||
@conversation.update!(status: status[0])
|
||||
end
|
||||
@@ -54,8 +56,6 @@ class AutomationRules::ActionService
|
||||
end
|
||||
|
||||
def send_message(message)
|
||||
return if @rule.event_name == 'message_created'
|
||||
|
||||
params = { content: message[0], private: false }
|
||||
mb = Messages::MessageBuilder.new(nil, @conversation, params)
|
||||
mb.perform
|
||||
@@ -82,15 +82,10 @@ class AutomationRules::ActionService
|
||||
end
|
||||
|
||||
def send_email_to_team(params)
|
||||
team = Team.find(params[:team_ids][0])
|
||||
teams = Team.where(id: params[0][:team_ids])
|
||||
|
||||
case @rule.event_name
|
||||
when 'conversation_created', 'conversation_status_changed'
|
||||
TeamNotifications::AutomationNotificationMailer.conversation_creation(@conversation, team, params[:message])&.deliver_now
|
||||
when 'conversation_updated'
|
||||
TeamNotifications::AutomationNotificationMailer.conversation_updated(@conversation, team, params[:message])&.deliver_now
|
||||
when 'message_created'
|
||||
TeamNotifications::AutomationNotificationMailer.message_created(@conversation, team, params[:message])&.deliver_now
|
||||
teams.each do |team|
|
||||
TeamNotifications::AutomationNotificationMailer.conversation_creation(@conversation, team, params[0][:message])&.deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@ require 'json'
|
||||
class AutomationRules::ConditionsFilterService < FilterService
|
||||
ATTRIBUTE_MODEL = 'contact_attribute'.freeze
|
||||
|
||||
def initialize(rule, conversation = nil)
|
||||
def initialize(rule, conversation = nil, options = {})
|
||||
super([], nil)
|
||||
@rule = rule
|
||||
@conversation = conversation
|
||||
@account = conversation.account
|
||||
file = File.read('./lib/filters/filter_keys.json')
|
||||
@filters = JSON.parse(file)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def perform
|
||||
@@ -41,7 +42,7 @@ class AutomationRules::ConditionsFilterService < FilterService
|
||||
current_filter = message_filters[query_hash['attribute_key']]
|
||||
@query_string += message_query_string(current_filter, query_hash.with_indifferent_access, current_index)
|
||||
end
|
||||
records = Message.where(conversation: @conversation).where(@query_string, @filter_values.with_indifferent_access)
|
||||
records = Message.where(id: @options[:message].id).where(@query_string, @filter_values.with_indifferent_access)
|
||||
records.any?
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user