2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2015-11-11 13:10:26 +00:00
|
|
|
class Sessions::Event::ChatSessionMessage < Sessions::Event::ChatBase
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2019-11-21 07:47:05 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
a agent or customer creates a new chat session message
|
|
|
|
|
|
|
|
payload
|
|
|
|
|
|
|
|
{
|
|
|
|
event: 'chat_session_message',
|
|
|
|
data: {
|
|
|
|
content: 'some message',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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_session_exists
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2015-11-25 09:33:39 +00:00
|
|
|
chat_session = current_chat_session
|
2015-11-10 14:01:04 +00:00
|
|
|
|
|
|
|
user_id = nil
|
2015-11-11 13:10:26 +00:00
|
|
|
if @session
|
|
|
|
user_id = @session['id']
|
2015-11-10 14:01:04 +00:00
|
|
|
end
|
|
|
|
chat_message = Chat::Message.create(
|
|
|
|
chat_session_id: chat_session.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
content: @payload['data']['content'],
|
|
|
|
created_by_id: user_id,
|
2015-11-10 14:01:04 +00:00
|
|
|
)
|
|
|
|
message = {
|
|
|
|
event: 'chat_session_message',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2015-11-10 14:01:04 +00:00
|
|
|
session_id: chat_session.session_id,
|
2018-12-19 17:31:51 +00:00
|
|
|
message: chat_message,
|
2015-11-10 14:01:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
# send to participents
|
2015-11-11 13:10:26 +00:00
|
|
|
chat_session.send_to_recipients(message, @client_id)
|
2015-11-10 14:01:04 +00:00
|
|
|
|
|
|
|
# send chat_session_init to agent
|
|
|
|
{
|
|
|
|
event: 'chat_session_message',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
|
|
|
session_id: chat_session.session_id,
|
|
|
|
message: chat_message,
|
2015-11-10 14:01:04 +00:00
|
|
|
self_written: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
2015-12-09 13:09:37 +00:00
|
|
|
|
2015-11-10 14:01:04 +00:00
|
|
|
end
|