feat: Custom attributes in automations and refactor (#4548)

* Custom attributes

* Custom Attrs Manifest

* Fix dropdown values for custom attributes

* Handle edit mode for custom attributes

* Ported duplicate logic to a mixin

* fix Code climate issue

* Fix Codeclimate complexity warning

* Bug fix - Custom attributes getting duplicated

* Bug fixes and Code Climate issue fix

* Code Climate Issues Breakdown

* Fix test spec

* Add labels for Custom attributes in dropdown

* Refactor

* Refactor Automion mixin

* Refactor Mixin

* Refactor getOperator

* Fix getOperatorType

* File name method refactor

* Refactor appendNewCondition

* spec update

* Refactor methods

* Mixin Spec update

* Automation Mixins Test Specs

* Mixin Spec Rerun

* Automation validations mixin spec

* Automation helper test spec

* Send custom_attr key

* Fix spec fixtures

* fix: Changes for custom attribute type and lower case search

* fix: Specs

* fix: Specs

* fix: Ruby version change

* fix: Ruby version change

* Removes Lowercased values and fix label value in api payload

* Fix specs

* Fixed Query Spec

* Removed disabled labels if no attributes are present

* Code Climate Fixes

* fix: custom attribute with indifferent access

* fix: custom attribute with indifferent access

* Fix specs

* Minor label fix

* REtrigger circle ci build

* Update app/javascript/shared/mixins/specs/automationMixin.spec.js

* Update app/javascript/shared/mixins/specs/automationMixin.spec.js

* fix: Custom attribute case insensitivity search

* Add missing reset action method to input

* Set team_input to single select instead of multiple

* fix: remove value case check for date,boolean and number data type

* fix: cognitive complexity

* fix: cognitive complexity

* fix: Fixed activity message for automation system

* fix: Fixed activity message for automation system

* fix: Fixed activity message for automation system

* fix: codeclimate

* fix: codeclimate

* fix: action cable events for label update

* fix: codeclimate, conversation modela number of methods

* fix: codeclimate, conversation modela number of methods

* fix: codeclimate, conversation modela number of methods

* fix: codeclimate, conversation modela number of methods

* Fix margin bottom for attachment button

* Remove margin bottom to avoid conflict from macros

* Fix automation action query generator using the right key

* fix: not running message created event for activity message

* fix: not running message created event for activity message

* codeclimate fix

* codeclimate fix

* codeclimate fix

* Update app/javascript/dashboard/mixins/automations/methodsMixin.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

* Update app/javascript/shared/mixins/specs/automationHelper.spec.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

* Update app/javascript/dashboard/helper/automationHelper.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

* Update app/javascript/dashboard/mixins/automations/methodsMixin.js

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Fayaz Ahmed
2022-11-10 10:53:29 +05:30
committed by GitHub
parent 3184c8964d
commit 9eb861a3b7
30 changed files with 2413 additions and 704 deletions

View File

@@ -1,6 +1,6 @@
class ActionService
def initialize(conversation)
@conversation = conversation
@conversation = conversation.reload
end
def mute_conversation(_params)
@@ -22,7 +22,7 @@ class ActionService
def add_label(labels)
return if labels.empty?
@conversation.add_labels(labels)
@conversation.reload.add_labels(labels)
end
def assign_best_agent(agent_ids = [])

View File

@@ -8,6 +8,7 @@ class AutomationRules::ActionService < ActionService
def perform
@rule.actions.each do |action|
@conversation.reload
action = action.with_indifferent_access
begin
send(action[:action_name], action[:action_params])

View File

@@ -54,6 +54,14 @@ class FilterService
query_hash['values'].map { |x| Message.message_types[x.to_sym] }
when 'content'
string_filter_values(query_hash)
else
case_insensitive_values(query_hash)
end
end
def case_insensitive_values(query_hash)
if query_hash['custom_attribute_type'].present? && query_hash['values'][0].is_a?(String)
string_filter_values(query_hash)
else
query_hash['values']
end
@@ -91,23 +99,39 @@ class FilterService
end
def custom_attribute_query(query_hash, custom_attribute_type, current_index)
attribute_key = query_hash[:attribute_key]
query_operator = query_hash[:query_operator]
attribute_model = custom_attribute_type.presence || self.class::ATTRIBUTE_MODEL
@attribute_key = query_hash[:attribute_key]
@custom_attribute_type = custom_attribute_type
attribute_type = custom_attribute(attribute_key, @account, attribute_model).try(:attribute_display_type)
filter_operator_value = filter_operation(query_hash, current_index)
attribute_data_type = self.class::ATTRIBUTE_TYPES[attribute_type]
attribute_data_type
return ' ' if @custom_attribute.blank?
table_name = attribute_model == 'conversation_attribute' ? 'conversations' : 'contacts'
" LOWER(#{table_name}.custom_attributes ->> '#{attribute_key}')::#{attribute_data_type} #{filter_operator_value} #{query_operator} "
build_custom_attr_query(query_hash, current_index)
end
private
def attribute_model
@attribute_model = @custom_attribute_type.presence || self.class::ATTRIBUTE_MODEL
end
def attribute_data_type
attribute_type = custom_attribute(@attribute_key, @account, attribute_model).try(:attribute_display_type)
@attribute_data_type = self.class::ATTRIBUTE_TYPES[attribute_type]
end
def build_custom_attr_query(query_hash, current_index)
filter_operator_value = filter_operation(query_hash, current_index)
query_operator = query_hash[:query_operator]
table_name = attribute_model == 'conversation_attribute' ? 'conversations' : 'contacts'
if attribute_data_type == 'text'
" LOWER(#{table_name}.custom_attributes ->> '#{@attribute_key}')::#{attribute_data_type} #{filter_operator_value} #{query_operator} "
else
" (#{table_name}.custom_attributes ->> '#{@attribute_key}')::#{attribute_data_type} #{filter_operator_value} #{query_operator} "
end
end
def custom_attribute(attribute_key, account, custom_attribute_type)
current_account = account || Current.account
attribute_model = custom_attribute_type.presence || self.class::ATTRIBUTE_MODEL