Feat: detect language of the message content (#6660)

This commit is contained in:
Tejaswini Chile
2023-04-04 08:57:27 +05:30
committed by GitHub
parent 268eababa3
commit 6a0ca35de4
14 changed files with 178 additions and 7 deletions

View File

@@ -136,6 +136,7 @@ export const getConditionOptions = ({
team_id: teams,
campaigns: generateConditionOptions(campaigns),
browser_language: languages,
conversation_language: languages,
country_code: countries,
message_type: MESSAGE_CONDITION_VALUES,
};

View File

@@ -251,7 +251,7 @@ export default {
},
getActionDropdownValues(type) {
const { agents, labels, teams } = this;
return getActionOptions({ agents, labels, teams, type });
return getActionOptions({ agents, labels, teams, languages, type });
},
manifestCustomAttributes() {
const conversationCustomAttributesRaw = this.$store.getters[

View File

@@ -36,6 +36,13 @@ export const AUTOMATIONS = {
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
{
key: 'conversation_language',
name: 'Conversation Language',
attributeI18nKey: 'CONVERSATION_LANGUAGE',
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
{
key: 'phone_number',
name: 'Phone Number',
@@ -161,6 +168,13 @@ export const AUTOMATIONS = {
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
{
key: 'conversation_language',
name: 'Conversation Language',
attributeI18nKey: 'CONVERSATION_LANGUAGE',
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
],
actions: [
{
@@ -292,6 +306,13 @@ export const AUTOMATIONS = {
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
{
key: 'conversation_language',
name: 'Conversation Language',
attributeI18nKey: 'CONVERSATION_LANGUAGE',
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
],
actions: [
{
@@ -416,6 +437,13 @@ export const AUTOMATIONS = {
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
{
key: 'conversation_language',
name: 'Conversation Language',
attributeI18nKey: 'CONVERSATION_LANGUAGE',
inputType: 'multi_select',
filterOperators: OPERATOR_TYPES_1,
},
],
actions: [
{

View File

@@ -7,6 +7,8 @@ class HookJob < ApplicationJob
process_slack_integration(hook, event_name, event_data)
when 'dialogflow'
process_dialogflow_integration(hook, event_name, event_data)
when 'google_translate'
google_translate_integration(hook, event_name, event_data)
end
rescue StandardError => e
Rails.logger.error e
@@ -27,4 +29,11 @@ class HookJob < ApplicationJob
Integrations::Dialogflow::ProcessorService.new(event_name: event_name, hook: hook, event_data: event_data).perform
end
def google_translate_integration(hook, event_name, event_data)
return unless ['message.created'].include?(event_name)
message = event_data[:message]
Integrations::GoogleTranslate::DetectLanguageService.new(hook: hook, message: message).perform
end
end

View File

@@ -31,7 +31,7 @@ class AutomationRule < ApplicationRecord
scope :active, -> { where(active: true) }
CONDITIONS_ATTRS = %w[content email country_code status message_type browser_language assignee_id team_id referer city company inbox_id
mail_subject phone_number].freeze
mail_subject phone_number conversation_language].freeze
ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_agent send_webhook_event mute_conversation send_attachment
change_status resolve_conversation snooze_conversation send_email_transcript].freeze

View File

@@ -212,12 +212,18 @@ class Conversation < ApplicationRecord
end
def notify_conversation_updation
return unless previous_changes.keys.present? && (previous_changes.keys & %w[team_id assignee_id status snoozed_until
custom_attributes label_list first_reply_created_at]).present?
return unless previous_changes.keys.present? && whitelisted_keys?
dispatcher_dispatch(CONVERSATION_UPDATED, previous_changes)
end
def whitelisted_keys?
(
(previous_changes.keys & %w[team_id assignee_id status snoozed_until custom_attributes label_list first_reply_created_at]).present? ||
(previous_changes['additional_attributes'].present? && (previous_changes['additional_attributes'][1].keys & %w[conversation_language]).present?)
)
end
def self_assign?(assignee_id)
assignee_id.present? && Current.user&.id == assignee_id
end