2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
class Sessions::Event::ChatStatusCustomer < Sessions::Event::ChatBase
|
|
|
|
|
2019-11-21 07:47:05 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
a customer requests the current state of a chat
|
|
|
|
|
|
|
|
payload
|
|
|
|
|
|
|
|
{
|
|
|
|
event: 'chat_status_agent',
|
|
|
|
data: {
|
|
|
|
session_id: 'the id of the current chat session',
|
|
|
|
url: 'optional url', # will trigger a chat_session_notice to agent
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return is sent as message back to peer
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
def run
|
2015-12-09 13:09:37 +00:00
|
|
|
return super if super
|
2015-11-25 09:33:39 +00:00
|
|
|
return if !check_chat_exists
|
2020-02-13 08:27:36 +00:00
|
|
|
return if blocked_ip?
|
|
|
|
return if blocked_country?
|
|
|
|
return if blocked_origin?
|
2015-11-11 13:10:26 +00:00
|
|
|
|
2015-11-12 09:39:14 +00:00
|
|
|
# check if it's a chat sessin reconnect
|
|
|
|
session_id = nil
|
2015-12-09 13:09:37 +00:00
|
|
|
if @payload['data']['session_id']
|
|
|
|
session_id = @payload['data']['session_id']
|
2015-11-12 15:58:47 +00:00
|
|
|
|
|
|
|
# update recipients of existing sessions
|
|
|
|
chat_session = Chat::Session.find_by(session_id: session_id)
|
2018-01-31 09:25:31 +00:00
|
|
|
if chat_session
|
|
|
|
chat_session.add_recipient(@client_id, true)
|
|
|
|
|
|
|
|
# sent url update to agent
|
|
|
|
if @payload['data']['url']
|
|
|
|
message = {
|
|
|
|
event: 'chat_session_notice',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2018-01-31 09:25:31 +00:00
|
|
|
session_id: chat_session.session_id,
|
2018-12-19 17:31:51 +00:00
|
|
|
message: @payload['data']['url'],
|
2018-01-31 09:25:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
chat_session.send_to_recipients(message, @client_id)
|
|
|
|
end
|
2016-03-25 07:45:21 +00:00
|
|
|
end
|
2015-11-12 09:39:14 +00:00
|
|
|
end
|
2016-03-25 07:45:21 +00:00
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
{
|
|
|
|
event: 'chat_status_customer',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: current_chat.customer_state(session_id),
|
2015-11-11 13:10:26 +00:00
|
|
|
}
|
|
|
|
end
|
2015-12-09 13:09:37 +00:00
|
|
|
|
2020-02-13 08:27:36 +00:00
|
|
|
def blocked_ip?
|
|
|
|
return false if !current_chat.blocked_ip?(remote_ip)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2020-02-13 08:27:36 +00:00
|
|
|
send_unavailable
|
|
|
|
true
|
2018-01-28 23:52:02 +00:00
|
|
|
end
|
|
|
|
|
2020-02-13 08:27:36 +00:00
|
|
|
def blocked_country?
|
|
|
|
return false if !current_chat.blocked_country?(remote_ip)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2020-02-13 08:27:36 +00:00
|
|
|
send_unavailable
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def blocked_origin?
|
2021-07-12 13:18:31 +00:00
|
|
|
return false if current_chat.website_allowed?(origin)
|
2020-02-13 08:27:36 +00:00
|
|
|
|
|
|
|
send_unavailable
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_unavailable
|
2018-01-28 23:52:02 +00:00
|
|
|
error = {
|
|
|
|
event: 'chat_error',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2018-01-28 23:52:02 +00:00
|
|
|
state: 'chat_unavailable',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Sessions.send(@client_id, error)
|
|
|
|
end
|
2015-11-11 13:10:26 +00:00
|
|
|
end
|