chat_session_message.rb 916 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. class Sessions::Event::ChatSessionMessage < Sessions::Event::ChatBase
  2. def run
  3. return super if super
  4. return if !check_chat_session_exists
  5. chat_session = current_chat_session
  6. user_id = nil
  7. if @session
  8. user_id = @session['id']
  9. end
  10. chat_message = Chat::Message.create(
  11. chat_session_id: chat_session.id,
  12. content: @payload['data']['content'],
  13. created_by_id: user_id,
  14. )
  15. message = {
  16. event: 'chat_session_message',
  17. data: {
  18. session_id: chat_session.session_id,
  19. message: chat_message,
  20. },
  21. }
  22. # send to participents
  23. chat_session.send_to_recipients(message, @client_id)
  24. # send chat_session_init to agent
  25. {
  26. event: 'chat_session_message',
  27. data: {
  28. session_id: chat_session.session_id,
  29. message: chat_message,
  30. self_written: true,
  31. },
  32. }
  33. end
  34. end