Added multiple greetings. Improved tests.
This commit is contained in:
parent
fab440e219
commit
af944eea2f
6 changed files with 149 additions and 43 deletions
|
@ -278,7 +278,9 @@ class ChatWindow extends App.Controller
|
||||||
if preferences.chat && preferences.chat.phrase
|
if preferences.chat && preferences.chat.phrase
|
||||||
phrases = preferences.chat.phrase[@session.chat_id]
|
phrases = preferences.chat.phrase[@session.chat_id]
|
||||||
if phrases
|
if phrases
|
||||||
@input.html(phrases)
|
phrasesArray = phrases.split(';')
|
||||||
|
phrase = phrasesArray[_.random(0, phrasesArray.length-1)]
|
||||||
|
@input.html(phrase)
|
||||||
@sendMessage()
|
@sendMessage()
|
||||||
|
|
||||||
focus: =>
|
focus: =>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%- @T('Topic') %>
|
<th><%- @T('Topic') %>
|
||||||
<th width="100%"><%- @T('Greeting') %>
|
<th width="100%"><%- @T('Greeting') %> (<%- @T('Separate multiple values by ;') %>)
|
||||||
<th><%- @T('Enabled') %>
|
<th><%- @T('Enabled') %>
|
||||||
</th></tr>
|
</th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
|
@ -85,15 +85,7 @@ do($ = window.jQuery, window) ->
|
||||||
for key, value of params
|
for key, value of params
|
||||||
@options[key] = value
|
@options[key] = value
|
||||||
|
|
||||||
detectHost: ->
|
|
||||||
protocol = 'ws://'
|
|
||||||
if window.location.protocol is 'https:'
|
|
||||||
protocol = 'wss://'
|
|
||||||
@options.host = "#{ protocol }#{ scriptHost }/ws"
|
|
||||||
|
|
||||||
connect: =>
|
connect: =>
|
||||||
@detectHost() if !@options.host
|
|
||||||
|
|
||||||
@log.debug "Connecting to #{@options.host}"
|
@log.debug "Connecting to #{@options.host}"
|
||||||
@ws = new window.WebSocket("#{@options.host}")
|
@ws = new window.WebSocket("#{@options.host}")
|
||||||
@ws.onopen = (e) =>
|
@ws.onopen = (e) =>
|
||||||
|
@ -232,6 +224,9 @@ do($ = window.jQuery, window) ->
|
||||||
@options.lang = @options.lang.replace(/-.+?$/, '') # replace "-xx" of xx-xx
|
@options.lang = @options.lang.replace(/-.+?$/, '') # replace "-xx" of xx-xx
|
||||||
@log.debug "lang: #{@options.lang}"
|
@log.debug "lang: #{@options.lang}"
|
||||||
|
|
||||||
|
# detect host
|
||||||
|
@detectHost() if !@options.host
|
||||||
|
|
||||||
@loadCss()
|
@loadCss()
|
||||||
|
|
||||||
@io = new Io(@options)
|
@io = new Io(@options)
|
||||||
|
@ -543,7 +538,6 @@ do($ = window.jQuery, window) ->
|
||||||
# delay initial queue position, show connecting first
|
# delay initial queue position, show connecting first
|
||||||
show = =>
|
show = =>
|
||||||
@onQueue data
|
@onQueue data
|
||||||
console.log('onQueueScreen')
|
|
||||||
@waitingListTimeout.start()
|
@waitingListTimeout.start()
|
||||||
|
|
||||||
if @initialQueueDelay && !@onInitialQueueDelayId
|
if @initialQueueDelay && !@onInitialQueueDelayId
|
||||||
|
@ -624,19 +618,19 @@ do($ = window.jQuery, window) ->
|
||||||
scrollToBottom: ->
|
scrollToBottom: ->
|
||||||
@el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'))
|
@el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'))
|
||||||
|
|
||||||
detectHost: ->
|
|
||||||
protocol = 'ws://'
|
|
||||||
if window.location.protocol is 'https:'
|
|
||||||
protocol = 'wss://'
|
|
||||||
@options.host = "#{ protocol }#{ scriptHost }/ws"
|
|
||||||
|
|
||||||
destroy: (params = {}) =>
|
destroy: (params = {}) =>
|
||||||
@log.debug 'destroy widget'
|
@log.debug 'destroy widget'
|
||||||
console.log('el', @el)
|
|
||||||
if params.hide
|
if params.hide
|
||||||
if @el
|
if @el
|
||||||
@el.remove()
|
@el.remove()
|
||||||
|
|
||||||
|
# stop all timer
|
||||||
|
@waitingListTimeout.stop()
|
||||||
|
@inactiveTimeout.stop()
|
||||||
|
@idleTimeout.stop()
|
||||||
@wsReconnectStop()
|
@wsReconnectStop()
|
||||||
|
|
||||||
|
# stop ws connection
|
||||||
@io.close()
|
@io.close()
|
||||||
|
|
||||||
wsReconnectStart: =>
|
wsReconnectStart: =>
|
||||||
|
@ -732,6 +726,12 @@ do($ = window.jQuery, window) ->
|
||||||
.attr('data-status', state)
|
.attr('data-status', state)
|
||||||
.text @T(capitalizedState)
|
.text @T(capitalizedState)
|
||||||
|
|
||||||
|
detectHost: ->
|
||||||
|
protocol = 'ws://'
|
||||||
|
if window.location.protocol is 'https:'
|
||||||
|
protocol = 'wss://'
|
||||||
|
@options.host = "#{ protocol }#{ scriptHost }/ws"
|
||||||
|
|
||||||
loadCss: ->
|
loadCss: ->
|
||||||
return if !@options.cssAutoload
|
return if !@options.cssAutoload
|
||||||
url = @options.cssUrl
|
url = @options.cssUrl
|
||||||
|
|
|
@ -159,19 +159,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
Io.prototype.detectHost = function() {
|
|
||||||
var protocol;
|
|
||||||
protocol = 'ws://';
|
|
||||||
if (window.location.protocol === 'https:') {
|
|
||||||
protocol = 'wss://';
|
|
||||||
}
|
|
||||||
return this.options.host = "" + protocol + scriptHost + "/ws";
|
|
||||||
};
|
|
||||||
|
|
||||||
Io.prototype.connect = function() {
|
Io.prototype.connect = function() {
|
||||||
if (!this.options.host) {
|
|
||||||
this.detectHost();
|
|
||||||
}
|
|
||||||
this.log.debug("Connecting to " + this.options.host);
|
this.log.debug("Connecting to " + this.options.host);
|
||||||
this.ws = new window.WebSocket("" + this.options.host);
|
this.ws = new window.WebSocket("" + this.options.host);
|
||||||
this.ws.onopen = (function(_this) {
|
this.ws.onopen = (function(_this) {
|
||||||
|
@ -398,6 +386,9 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
this.options.lang = this.options.lang.replace(/-.+?$/, '');
|
this.options.lang = this.options.lang.replace(/-.+?$/, '');
|
||||||
this.log.debug("lang: " + this.options.lang);
|
this.log.debug("lang: " + this.options.lang);
|
||||||
}
|
}
|
||||||
|
if (!this.options.host) {
|
||||||
|
this.detectHost();
|
||||||
|
}
|
||||||
this.loadCss();
|
this.loadCss();
|
||||||
this.io = new Io(this.options);
|
this.io = new Io(this.options);
|
||||||
this.io.set({
|
this.io.set({
|
||||||
|
@ -749,7 +740,6 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
show = (function(_this) {
|
show = (function(_this) {
|
||||||
return function() {
|
return function() {
|
||||||
_this.onQueue(data);
|
_this.onQueue(data);
|
||||||
console.log('onQueueScreen');
|
|
||||||
return _this.waitingListTimeout.start();
|
return _this.waitingListTimeout.start();
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
@ -837,26 +827,19 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
return this.el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'));
|
return this.el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'));
|
||||||
};
|
};
|
||||||
|
|
||||||
ZammadChat.prototype.detectHost = function() {
|
|
||||||
var protocol;
|
|
||||||
protocol = 'ws://';
|
|
||||||
if (window.location.protocol === 'https:') {
|
|
||||||
protocol = 'wss://';
|
|
||||||
}
|
|
||||||
return this.options.host = "" + protocol + scriptHost + "/ws";
|
|
||||||
};
|
|
||||||
|
|
||||||
ZammadChat.prototype.destroy = function(params) {
|
ZammadChat.prototype.destroy = function(params) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
params = {};
|
params = {};
|
||||||
}
|
}
|
||||||
this.log.debug('destroy widget');
|
this.log.debug('destroy widget');
|
||||||
console.log('el', this.el);
|
|
||||||
if (params.hide) {
|
if (params.hide) {
|
||||||
if (this.el) {
|
if (this.el) {
|
||||||
this.el.remove();
|
this.el.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.waitingListTimeout.stop();
|
||||||
|
this.inactiveTimeout.stop();
|
||||||
|
this.idleTimeout.stop();
|
||||||
this.wsReconnectStop();
|
this.wsReconnectStop();
|
||||||
return this.io.close();
|
return this.io.close();
|
||||||
};
|
};
|
||||||
|
@ -967,6 +950,15 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
return this.el.find('.zammad-chat-agent-status').attr('data-status', state).text(this.T(capitalizedState));
|
return this.el.find('.zammad-chat-agent-status').attr('data-status', state).text(this.T(capitalizedState));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ZammadChat.prototype.detectHost = function() {
|
||||||
|
var protocol;
|
||||||
|
protocol = 'ws://';
|
||||||
|
if (window.location.protocol === 'https:') {
|
||||||
|
protocol = 'wss://';
|
||||||
|
}
|
||||||
|
return this.options.host = "" + protocol + scriptHost + "/ws";
|
||||||
|
};
|
||||||
|
|
||||||
ZammadChat.prototype.loadCss = function() {
|
ZammadChat.prototype.loadCss = function() {
|
||||||
var newSS, styles, url;
|
var newSS, styles, url;
|
||||||
if (!this.options.cssAutoload) {
|
if (!this.options.cssAutoload) {
|
||||||
|
|
4
public/assets/chat/chat.min.js
vendored
4
public/assets/chat/chat.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -389,6 +389,118 @@ class ChatTest < TestCase
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_basic_usecase3
|
||||||
|
agent = browser_instance
|
||||||
|
login(
|
||||||
|
browser: agent,
|
||||||
|
username: 'master@example.com',
|
||||||
|
password: 'test',
|
||||||
|
url: browser_url,
|
||||||
|
)
|
||||||
|
tasks_close_all(
|
||||||
|
browser: agent,
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: agent,
|
||||||
|
css: 'a[href="#customer_chat"]',
|
||||||
|
)
|
||||||
|
agent.find_elements( { css: '.active .chat-window .js-close' } ).each(&:click)
|
||||||
|
|
||||||
|
# set chat preferences
|
||||||
|
click(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .js-settings',
|
||||||
|
)
|
||||||
|
set(
|
||||||
|
browser: agent,
|
||||||
|
css: '.modal [name="chat::phrase::1"]',
|
||||||
|
value: 'Hi Stranger!;My Greeting',
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: agent,
|
||||||
|
css: '.modal .js-submit',
|
||||||
|
)
|
||||||
|
|
||||||
|
customer = browser_instance
|
||||||
|
location(
|
||||||
|
browser: customer,
|
||||||
|
url: "#{browser_url}/assets/chat/znuny.html?port=#{ENV['WS_PORT']}",
|
||||||
|
)
|
||||||
|
watch_for(
|
||||||
|
browser: customer,
|
||||||
|
css: '.zammad-chat',
|
||||||
|
timeout: 5,
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: customer,
|
||||||
|
css: '.js-chat-open',
|
||||||
|
)
|
||||||
|
exists(
|
||||||
|
browser: customer,
|
||||||
|
css: '.zammad-chat-is-shown',
|
||||||
|
)
|
||||||
|
watch_for(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .js-badgeWaitingCustomers',
|
||||||
|
value: '1',
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .js-acceptChat',
|
||||||
|
)
|
||||||
|
watch_for(
|
||||||
|
browser: customer,
|
||||||
|
css: '.zammad-chat',
|
||||||
|
value: 'Hi Stranger|My Greeting',
|
||||||
|
)
|
||||||
|
watch_for(
|
||||||
|
browser: customer,
|
||||||
|
css: '.zammad-chat .zammad-chat-agent-status',
|
||||||
|
value: 'online',
|
||||||
|
)
|
||||||
|
set(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .chat-window .js-customerChatInput',
|
||||||
|
value: 'my name is me',
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .chat-window .js-send',
|
||||||
|
)
|
||||||
|
watch_for(
|
||||||
|
browser: customer,
|
||||||
|
css: '.zammad-chat',
|
||||||
|
value: 'my name is me',
|
||||||
|
)
|
||||||
|
set(
|
||||||
|
browser: customer,
|
||||||
|
css: '.zammad-chat .zammad-chat-input',
|
||||||
|
value: 'my name is customer',
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: customer,
|
||||||
|
css: '.zammad-chat .zammad-chat-send',
|
||||||
|
)
|
||||||
|
watch_for(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .chat-window',
|
||||||
|
value: 'my name is customer',
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .chat-window .js-customerChatInput',
|
||||||
|
)
|
||||||
|
click(
|
||||||
|
browser: customer,
|
||||||
|
css: '.js-chat-close',
|
||||||
|
)
|
||||||
|
watch_for(
|
||||||
|
browser: agent,
|
||||||
|
css: '.active .chat-window',
|
||||||
|
value: 'has left the conversation',
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def test_timeouts
|
def test_timeouts
|
||||||
customer = browser_instance
|
customer = browser_instance
|
||||||
location(
|
location(
|
||||||
|
|
Loading…
Reference in a new issue