chat_session_init.rb 820 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. class Sessions::Event::ChatSessionInit < Sessions::Event::ChatBase
  2. def run
  3. return super if super
  4. return if !check_chat_exists
  5. # geo ip lookup
  6. geo_ip = nil
  7. if @remote_ip
  8. geo_ip = Service::GeoIp.location(@remote_ip)
  9. end
  10. # create chat session
  11. chat_session = Chat::Session.create(
  12. chat_id: @payload['data']['chat_id'],
  13. name: '',
  14. state: 'waiting',
  15. preferences: {
  16. participants: [@client_id],
  17. remote_ip: @remote_ip,
  18. geo_ip: geo_ip,
  19. },
  20. )
  21. # send broadcast to agents
  22. Chat.broadcast_agent_state_update
  23. # return new session
  24. {
  25. event: 'chat_session_queue',
  26. data: {
  27. state: 'queue',
  28. position: Chat.waiting_chat_count,
  29. session_id: chat_session.session_id,
  30. },
  31. }
  32. end
  33. end