feat: Improve Captain interactions, activity messages (#11493)

Show captain messages under the name of the assistant which generated
the message.

- Add support for `Captain::Assistant` sender type
- Add push_event_data for captain_assistants
- Add activity message handler for captain_assistants
- Update UI to show captain messages under the name of the assistant
- Fix the issue where openAI errors when image is sent
- Add support for custom name of the assistant

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Pranav
2025-05-16 19:27:57 -07:00
committed by GitHub
parent a295d5b61d
commit cbdac45824
15 changed files with 143 additions and 24 deletions

View File

@@ -6,11 +6,15 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
@inbox = conversation.inbox
@assistant = assistant
Current.executed_by = @assistant
ActiveRecord::Base.transaction do
generate_and_process_response
end
rescue StandardError => e
handle_error(e)
ensure
Current.executed_by = nil
end
private
@@ -37,13 +41,23 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
.where(private: false)
.map do |message|
{
content: message.content,
content: message_content(message),
role: determine_role(message)
}
end
end
def message_content(message)
return message.content if message.content.present?
'User has shared an attachment' if message.attachments.any?
'User has shared a message without content'
end
def determine_role(message)
return 'system' if message.content.blank?
message.message_type == 'incoming' ? 'user' : 'system'
end
@@ -54,13 +68,15 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
def process_action(action)
case action
when 'handoff'
create_handoff_message
@conversation.bot_handoff!
I18n.with_locale(@assistant.account.locale) do
create_handoff_message
@conversation.bot_handoff!
end
end
end
def create_handoff_message
create_outgoing_message(@assistant.config['handoff_message'] || 'Transferring to another agent for further assistance.')
create_outgoing_message(@assistant.config['handoff_message'].presence || I18n.t('conversations.captain.handoff'))
end
def create_messages
@@ -77,6 +93,7 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
message_type: :outgoing,
account_id: account.id,
inbox_id: inbox.id,
sender: @assistant,
content: message_content
)
end