diff --git a/addons/im_livechat/controllers/main.py b/addons/im_livechat/controllers/main.py
index 1524a4dc8d4..7ee18094ce3 100644
--- a/addons/im_livechat/controllers/main.py
+++ b/addons/im_livechat/controllers/main.py
@@ -113,7 +113,7 @@ class LivechatController(http.Controller):
).get_response()
@http.route('/im_livechat/get_session', type="json", auth='public', cors="*")
- def get_session(self, channel_id, anonymous_name, previous_operator_id=None, chatbot_script_id=None, **kwargs):
+ def get_session(self, channel_id, anonymous_name, previous_operator_id=None, chatbot_script_id=None, persisted=True, **kwargs):
user_id = None
country_id = None
# if the user is identifiy (eg: portal user on the frontend), don't use the anonymous name. The user will be added to session.
@@ -141,7 +141,9 @@ class LivechatController(http.Controller):
previous_operator_id=previous_operator_id,
chatbot_script=chatbot_script,
user_id=user_id,
- country_id=country_id)
+ country_id=country_id,
+ persisted=persisted
+ )
@http.route('/im_livechat/feedback', type='json', auth='public', cors="*")
def feedback(self, uuid, rate, reason=None, **kwargs):
diff --git a/addons/im_livechat/i18n/im_livechat.pot b/addons/im_livechat/i18n/im_livechat.pot
index 22466060e1a..17d3fcb924d 100644
--- a/addons/im_livechat/i18n/im_livechat.pot
+++ b/addons/im_livechat/i18n/im_livechat.pot
@@ -1177,6 +1177,13 @@ msgstr ""
msgid "No history found"
msgstr ""
+#. module: im_livechat
+#. odoo-javascript
+#: code:addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.xml:0
+#, python-format
+msgid "No operator available"
+msgstr ""
+
#. module: im_livechat
#. openerp-web
#: code:addons/im_livechat/static/src/legacy/widgets/public_livechat_view/public_livechat_view.xml:0
diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py
index 5ed749c10f5..9e8fa540626 100644
--- a/addons/im_livechat/models/im_livechat_channel.py
+++ b/addons/im_livechat/models/im_livechat_channel.py
@@ -161,14 +161,15 @@ class ImLivechatChannel(models.Model):
'name': name,
}
- def _open_livechat_mail_channel(self, anonymous_name, previous_operator_id=None, chatbot_script=None, user_id=None, country_id=None):
- """ Return a mail.channel given a livechat channel. It creates one with a connected operator or with Odoobot as
+ def _open_livechat_mail_channel(self, anonymous_name, previous_operator_id=None, chatbot_script=None, user_id=None, country_id=None, persisted=True):
+ """ Return a livechat session. If the session is persisted, creates a mail.channel record with a connected operator or with Odoobot as
an operator if a chatbot has been configured, or return false otherwise
- :param anonymous_name : the name of the anonymous person of the channel
+ :param anonymous_name : the name of the anonymous person of the session
:param previous_operator_id : partner_id.id of the previous operator that this visitor had in the past
:param chatbot_script : chatbot script if there is one configured
:param user_id : the id of the logged in visitor, if any
- :param country_code : the country of the anonymous person of the channel
+ :param country_code : the country of the anonymous person of the session
+ :param persisted: whether or not the session should be persisted
:type anonymous_name : str
:return : channel header
:rtype : dict
@@ -192,13 +193,23 @@ class ImLivechatChannel(models.Model):
if not user_operator and not chatbot_script:
# no one available
return False
-
- # create the session, and add the link with the given channel
mail_channel_vals = self._get_livechat_mail_channel_vals(anonymous_name, user_operator, chatbot_script, user_id=user_id, country_id=country_id)
- mail_channel = self.env["mail.channel"].with_context(mail_create_nosubscribe=False).sudo().create(mail_channel_vals)
- if user_operator:
- mail_channel._broadcast([user_operator.partner_id.id])
- return mail_channel.sudo().channel_info()[0]
+ if persisted:
+ # create the session, and add the link with the given channel
+ mail_channel = self.env["mail.channel"].with_context(mail_create_nosubscribe=False).sudo().create(mail_channel_vals)
+ if user_operator:
+ mail_channel._broadcast([user_operator.partner_id.id])
+ return mail_channel.sudo().channel_info()[0]
+ else:
+ operator_partner_id = user_operator.partner_id if user_operator else chatbot_script.operator_partner_id
+ display_name = operator_partner_id.user_livechat_username or operator_partner_id.display_name
+ return {
+ 'name': mail_channel_vals['name'],
+ 'chatbot_current_step_id': mail_channel_vals['chatbot_current_step_id'],
+ 'state': 'open',
+ 'operator_pid': (operator_partner_id.id, display_name.replace(',', '')),
+ 'chatbot_script_id': chatbot_script.id if chatbot_script else None
+ }
def _get_random_operator(self):
""" Return a random operator from the available users of the channel that have the lowest number of active livechats.
diff --git a/addons/im_livechat/static/src/legacy/models/public_livechat.js b/addons/im_livechat/static/src/legacy/models/public_livechat.js
index fc2349c413c..aaeb6abc95b 100644
--- a/addons/im_livechat/static/src/legacy/models/public_livechat.js
+++ b/addons/im_livechat/static/src/legacy/models/public_livechat.js
@@ -289,6 +289,7 @@ const PublicLivechat = Class.extend(Mixins.EventDispatcherMixin, {
*/
toData() {
return {
+ chatbot_script_id: this.messaging.publicLivechatGlobal.publicLivechat.data.chatbot_script_id,
folded: this.messaging.publicLivechatGlobal.publicLivechat.isFolded,
id: this.messaging.publicLivechatGlobal.publicLivechat.id,
message_unread_counter: this.messaging.publicLivechatGlobal.publicLivechat.unreadCounter,
@@ -338,6 +339,11 @@ const PublicLivechat = Class.extend(Mixins.EventDispatcherMixin, {
* otherwise
*/
_notifyMyselfTyping(params) {
+ if (this.messaging.publicLivechatGlobal.publicLivechat.isTemporary) {
+ // channel is not created yet, it will be when first message is
+ // sent. Until then, do not notify visitor is typing.
+ return;
+ }
return session.rpc('/im_livechat/notify_typing', {
uuid: this.messaging.publicLivechatGlobal.publicLivechat.uuid,
is_typing: params.typing,
diff --git a/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js b/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js
index 7bb6e80181d..bc0e9df8477 100644
--- a/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js
+++ b/addons/im_livechat/static/src/legacy/public_livechat_chatbot.js
@@ -27,7 +27,12 @@ import LivechatButton from '@im_livechat/legacy/widgets/livechat_button';
_prepareGetSessionParameters() {
const parameters = this._super(...arguments);
- if (this.messaging.publicLivechatGlobal.chatbot.isActive) {
+ const { publicLivechat } = this.messaging.publicLivechatGlobal;
+ if (publicLivechat && publicLivechat.isTemporary && !publicLivechat.data.chatbot_script_id) {
+ return parameters;
+ } else if (publicLivechat && publicLivechat.data.chatbot_script_id) {
+ parameters.chatbot_script_id = publicLivechat.data.chatbot_script_id;
+ } else if (this.messaging.publicLivechatGlobal.chatbot.isActive) {
parameters.chatbot_script_id = this.messaging.publicLivechatGlobal.chatbot.scriptId;
}
diff --git a/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.js b/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.js
index b1bae5d5f27..10a27b45aa9 100644
--- a/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.js
+++ b/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.js
@@ -52,10 +52,6 @@ const PublicLivechatWindow = Widget.extend({
} else {
this._focusInput();
}
- if (!config.device.isMobile) {
- const margin_dir = _t.database.parameters.direction === "rtl" ? "margin-left" : "margin-right";
- this.$el.css(margin_dir, $.position.scrollbarWidth());
- }
const def = this.messaging.publicLivechatGlobal.chatWindow.publicLivechatView.widget.replace(this.$('.o_thread_window_content')).then(() => {
this.messaging.publicLivechatGlobal.chatWindow.publicLivechatView.widget.$el.on('scroll', this, this._debouncedOnScroll);
});
@@ -115,6 +111,29 @@ const PublicLivechatWindow = Widget.extend({
renderHeader() {
this.$header.html(qweb.render('im_livechat.legacy.PublicLivechatWindow.HeaderContent', { widget: this }));
},
+
+ /**
+ * Render the chat window itself.
+ */
+ renderChatWindow() {
+ this.renderElement();
+ this.adjustPosition();
+ },
+
+ /**
+ * Compute position of this chat window and apply corresponding styles to
+ * the underlying widget.
+ */
+ adjustPosition() {
+ const cssProps = { bottom: 0 };
+ cssProps[this.messaging.locale.textDirection === 'rtl' ? 'left' : 'right'] = 0;
+ if (!config.device.isMobile) {
+ const margin_dir = _t.database.parameters.direction === "rtl" ? "margin-left" : "margin-right";
+ cssProps[margin_dir] = $.position.scrollbarWidth();
+ }
+ this.$el.css(cssProps);
+ },
+
/**
* Replace the thread content with provided new content
*
@@ -138,7 +157,9 @@ const PublicLivechatWindow = Widget.extend({
folded = !this.messaging.publicLivechatGlobal.publicLivechat.isFolded;
}
this.messaging.publicLivechatGlobal.publicLivechat.update({ isFolded: folded });
- setCookie('im_livechat_session', unaccent(JSON.stringify(this.messaging.publicLivechatGlobal.publicLivechat.widget.toData()), true), 60 * 60, 'required');
+ if (this.messaging.publicLivechatGlobal.publicLivechat.operator) {
+ setCookie('im_livechat_session', unaccent(JSON.stringify(this.messaging.publicLivechatGlobal.publicLivechat.widget.toData()), true), 60 * 60, 'required');
+ }
this.updateVisualFoldState();
},
/**
@@ -198,6 +219,9 @@ const PublicLivechatWindow = Widget.extend({
} catch {
await this.messaging.publicLivechatGlobal.livechatButtonView.sendMessage(messageData); // try again just in case
}
+ if (!this.messaging.publicLivechatGlobal.publicLivechat.operator) {
+ return;
+ }
this.messaging.publicLivechatGlobal.publicLivechat.widget.postMessage(messageData)
.then(() => {
this.messaging.publicLivechatGlobal.chatWindow.publicLivechatView.widget.scrollToBottom();
diff --git a/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.xml b/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.xml
index 335101276b6..9beadceb47e 100644
--- a/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.xml
+++ b/addons/im_livechat/static/src/legacy/widgets/public_livechat_window/public_livechat_window.xml
@@ -16,14 +16,19 @@
No operator available