2015-11-11 13:10:26 +00:00
|
|
|
class Sessions::Event::ChatAgentState < Sessions::Event::ChatBase
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
def run
|
2015-11-10 14:01:04 +00:00
|
|
|
|
|
|
|
# only agents can do this
|
|
|
|
chat_id = 1
|
|
|
|
chat = Chat.find_by(id: chat_id)
|
2015-11-11 13:10:26 +00:00
|
|
|
if !@session['id']
|
2015-11-10 14:01:04 +00:00
|
|
|
return {
|
|
|
|
event: 'chat_agent_state',
|
|
|
|
data: {
|
|
|
|
state: 'failed',
|
|
|
|
message: 'No such user_id.'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
Chat::Agent.state(@session['id'], @data['data']['active'])
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-15 10:01:48 +00:00
|
|
|
# broadcast new state to agents
|
|
|
|
broadcast_agent_state_update(@session['id'])
|
|
|
|
|
2015-11-10 14:01:04 +00:00
|
|
|
{
|
|
|
|
event: 'chat_agent_state',
|
|
|
|
data: {
|
|
|
|
state: 'ok',
|
2015-11-11 13:10:26 +00:00
|
|
|
active: @data['data']['active'],
|
2015-11-10 14:01:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|