2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-12-03 06:29:02 +00:00
|
|
|
class Sessions::Event::ChatTransfer < Sessions::Event::ChatBase
|
|
|
|
|
2021-11-15 15:58:19 +00:00
|
|
|
def run # rubocop:disable Metrics/AbcSize
|
2019-12-03 06:29:02 +00:00
|
|
|
return super if super
|
|
|
|
return if !permission_check('chat.agent', 'chat')
|
|
|
|
|
|
|
|
# find chat session
|
|
|
|
chat_session = Chat::Session.find_by(id: @payload['session_id'])
|
|
|
|
if !chat_session
|
|
|
|
return {
|
|
|
|
event: 'chat_session_start',
|
|
|
|
data: {
|
|
|
|
state: 'failed',
|
2021-11-15 15:58:19 +00:00
|
|
|
message: __('No session available.'),
|
2019-12-03 06:29:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
chat_ids_to_notify = [chat_session.chat_id, @payload['chat_id']]
|
|
|
|
chat_session.chat_id = @payload['chat_id']
|
|
|
|
chat_session.state = 'waiting'
|
|
|
|
chat_session.save
|
|
|
|
|
|
|
|
# send state update with sessions to agents
|
|
|
|
Chat.broadcast_agent_state_update(chat_ids_to_notify)
|
|
|
|
|
|
|
|
# send transfer message to client
|
|
|
|
message = {
|
|
|
|
event: 'chat_session_notice',
|
|
|
|
data: {
|
|
|
|
session_id: chat_session.session_id,
|
2022-01-18 12:52:57 +00:00
|
|
|
message: __('Conversation is transferred into another chat. Please stay tuned.'),
|
2019-12-03 06:29:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
chat_session.send_to_recipients(message, @client_id)
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|