chat_session_message.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Sessions::Event::ChatSessionMessage < Sessions::Event::ChatBase
  3. =begin
  4. a agent or customer creates a new chat session message
  5. payload
  6. {
  7. event: 'chat_session_message',
  8. data: {
  9. content: 'some message',
  10. },
  11. }
  12. return is sent as message back to peer
  13. =end
  14. def run
  15. return super if super
  16. return if !check_chat_session_exists
  17. chat_session = current_chat_session
  18. user_id = nil
  19. if @session
  20. user_id = @session['id']
  21. end
  22. chat_message = Chat::Message.create(
  23. chat_session_id: chat_session.id,
  24. content: @payload['data']['content'],
  25. created_by_id: user_id,
  26. )
  27. message = {
  28. event: 'chat_session_message',
  29. data: {
  30. session_id: chat_session.session_id,
  31. message: chat_message,
  32. },
  33. }
  34. # send to participents
  35. chat_session.send_to_recipients(message, @client_id)
  36. # send chat_session_init to agent
  37. {
  38. event: 'chat_session_message',
  39. data: {
  40. session_id: chat_session.session_id,
  41. message: chat_message,
  42. self_written: true,
  43. },
  44. }
  45. end
  46. end