feat(ee): Add transcription support for audio messages (#11670)
<img width="419" alt="Screenshot 2025-06-03 at 4 25 37 PM" src="https://github.com/user-attachments/assets/4b6ddd11-9b91-4981-a571-83746cc4d40b" /> Fixes https://github.com/chatwoot/chatwoot/issues/10182 --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -36,6 +36,7 @@ class Account < ApplicationRecord
|
||||
'auto_resolve_after': { 'type': %w[integer null], 'minimum': 10, 'maximum': 1_439_856 },
|
||||
'auto_resolve_message': { 'type': %w[string null] },
|
||||
'auto_resolve_ignore_waiting': { 'type': %w[boolean null] },
|
||||
'audio_transcriptions': { 'type': %w[boolean null] },
|
||||
'auto_resolve_label': { 'type': %w[string null] }
|
||||
},
|
||||
'required': [],
|
||||
@@ -52,7 +53,8 @@ class Account < ApplicationRecord
|
||||
schema: SETTINGS_PARAMS_SCHEMA,
|
||||
attribute_resolver: ->(record) { record.settings }
|
||||
|
||||
store_accessor :settings, :auto_resolve_after, :auto_resolve_message, :auto_resolve_ignore_waiting, :auto_resolve_label
|
||||
store_accessor :settings, :auto_resolve_after, :auto_resolve_message, :auto_resolve_ignore_waiting
|
||||
store_accessor :settings, :audio_transcriptions, :auto_resolve_label
|
||||
|
||||
has_many :account_users, dependent: :destroy_async
|
||||
has_many :agent_bot_inboxes, dependent: :destroy_async
|
||||
|
||||
@@ -44,11 +44,8 @@ class Attachment < ApplicationRecord
|
||||
|
||||
def push_event_data
|
||||
return unless file_type
|
||||
return base_data.merge(location_metadata) if file_type.to_sym == :location
|
||||
return base_data.merge(fallback_data) if file_type.to_sym == :fallback
|
||||
return base_data.merge(contact_metadata) if file_type.to_sym == :contact
|
||||
|
||||
base_data.merge(file_metadata)
|
||||
base_data.merge(metadata_for_file_type)
|
||||
end
|
||||
|
||||
# NOTE: the URl returned does a 301 redirect to the actual file
|
||||
@@ -76,6 +73,30 @@ class Attachment < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def metadata_for_file_type
|
||||
case file_type.to_sym
|
||||
when :location
|
||||
location_metadata
|
||||
when :fallback
|
||||
fallback_data
|
||||
when :contact
|
||||
contact_metadata
|
||||
when :audio
|
||||
audio_metadata
|
||||
else
|
||||
file_metadata
|
||||
end
|
||||
end
|
||||
|
||||
def audio_metadata
|
||||
audio_file_data = base_data.merge(file_metadata)
|
||||
audio_file_data.merge(
|
||||
{
|
||||
transcribed_text: meta&.[]('transcribed_text') || ''
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def file_metadata
|
||||
metadata = {
|
||||
extension: extension,
|
||||
@@ -149,3 +170,5 @@ class Attachment < ApplicationRecord
|
||||
file_content_type.start_with?('image/', 'video/', 'audio/')
|
||||
end
|
||||
end
|
||||
|
||||
Attachment.include_mod_with('Concerns::Attachment')
|
||||
|
||||
@@ -224,6 +224,11 @@ class Message < ApplicationRecord
|
||||
save!
|
||||
end
|
||||
|
||||
def send_update_event
|
||||
Rails.configuration.dispatcher.dispatch(MESSAGE_UPDATED, Time.zone.now, message: self, performed_by: Current.executed_by,
|
||||
previous_changes: previous_changes)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prevent_message_flooding
|
||||
@@ -313,8 +318,7 @@ class Message < ApplicationRecord
|
||||
# we want to skip the update event if the message is not updated
|
||||
return if previous_changes.blank?
|
||||
|
||||
Rails.configuration.dispatcher.dispatch(MESSAGE_UPDATED, Time.zone.now, message: self, performed_by: Current.executed_by,
|
||||
previous_changes: previous_changes)
|
||||
send_update_event
|
||||
end
|
||||
|
||||
def send_reply
|
||||
|
||||
Reference in New Issue
Block a user