chat_transfer.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Sessions::Event::ChatTransfer < Sessions::Event::ChatBase
  3. def run # rubocop:disable Metrics/AbcSize
  4. return super if super
  5. return if !permission_check('chat.agent', 'chat')
  6. # find chat session
  7. chat_session = Chat::Session.find_by(id: @payload['session_id'])
  8. if !chat_session
  9. return {
  10. event: 'chat_session_start',
  11. data: {
  12. state: 'failed',
  13. message: __('No session available.'),
  14. },
  15. }
  16. end
  17. chat_ids_to_notify = [chat_session.chat_id, @payload['chat_id']]
  18. chat_session.chat_id = @payload['chat_id']
  19. chat_session.state = 'waiting'
  20. chat_session.save
  21. # send state update with sessions to agents
  22. Chat.broadcast_agent_state_update(chat_ids_to_notify)
  23. # send transfer message to client
  24. message = {
  25. event: 'chat_session_notice',
  26. data: {
  27. session_id: chat_session.session_id,
  28. message: __('Conversation is transferred into another chat. Please stay tuned.'),
  29. },
  30. }
  31. chat_session.send_to_recipients(message, @client_id)
  32. nil
  33. end
  34. end