chat_agent_state.rb 817 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. class Sessions::Event::ChatAgentState < Sessions::Event::ChatBase
  2. =begin
  3. a agent triggers its own chat availability state
  4. payload
  5. {
  6. event: 'chat_agent_state',
  7. data: {
  8. active: true, # true|false
  9. },
  10. }
  11. return is sent as message back to peer
  12. =end
  13. def run
  14. return super if super
  15. # check if user has permissions
  16. return if !permission_check('chat.agent', 'chat')
  17. chat_user = User.lookup(id: @session['id'])
  18. Chat::Agent.state(@session['id'], @payload['data']['active'])
  19. chat_ids = Chat.agent_active_chat_ids(chat_user)
  20. # broadcast new state to agents
  21. Chat.broadcast_agent_state_update(chat_ids, @session['id'])
  22. {
  23. event: 'chat_agent_state',
  24. data: {
  25. state: 'ok',
  26. active: @payload['data']['active'],
  27. },
  28. }
  29. end
  30. end