diff --git a/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js b/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js
index fcd1beddcdc..ca081cd6f6e 100644
--- a/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js
+++ b/addons/im_livechat/static/src/embed/chatbot/chatbot_service.js
@@ -25,6 +25,7 @@ export class ChatBotService {
currentStep;
/** @type {number} */
nextStepTimeout;
+ hasPostedWelcomeSteps = false;
shouldRestore = false;
isTyping = false;
@@ -55,6 +56,16 @@ export class ChatBotService {
this._processUserAnswer.bind(this),
MULTILINE_STEP_DEBOUNCE_DELAY
);
+ if (this.livechatService.options.isTestChatbot) {
+ this.livechatService.rule.chatbot = {
+ ...this.livechatService.options.testChatbotData,
+ welcomeStepIndex: this.livechatService.options.testChatbotData.welcomeSteps.length,
+ };
+ this.currentStep = new ChatbotStep(
+ this.livechatService.options.testChatbotData.welcomeSteps.at(-1)
+ );
+ this.livechatService.updateSession(this.livechatService.options.testChatbotChannelData);
+ }
this.livechatService.initializedDeferred.then(() => {
this.chatbot = this.livechatService.rule?.chatbot
? new Chatbot(this.livechatService.rule.chatbot)
@@ -77,7 +88,11 @@ export class ChatBotService {
/**
* Start the chatbot script.
*/
- start() {
+ async start() {
+ if (this.livechatService.options.isTestChatbot && !this.hasPostedWelcomeSteps) {
+ await this.postWelcomeSteps();
+ this.save();
+ }
if (this.shouldRestore && this.livechatService.state !== SESSION_STATE.PERSISTED) {
// We need to repost the welcome steps as they were not saved.
this.chatbot.welcomeStepIndex = 0;
@@ -135,6 +150,7 @@ export class ChatBotService {
this.livechatService.thread?.messages.push(message);
}
}
+ this.hasPostedWelcomeSteps = true;
}
// =============================================================================
diff --git a/addons/im_livechat/static/src/embed/core/livechat_service.js b/addons/im_livechat/static/src/embed/core/livechat_service.js
index 082e560a5d7..3f709386089 100644
--- a/addons/im_livechat/static/src/embed/core/livechat_service.js
+++ b/addons/im_livechat/static/src/embed/core/livechat_service.js
@@ -64,11 +64,14 @@ export class LivechatService {
}
async initialize() {
- const init = await this.rpc("/im_livechat/init", {
- channel_id: this.options.channel_id,
- });
- this.available = init.available_for_me ?? this.available;
- this.rule = init.rule;
+ let init;
+ if (!this.options.isTestChatbot) {
+ init = await this.rpc("/im_livechat/init", {
+ channel_id: this.options.channel_id,
+ });
+ }
+ this.available = init?.available_for_me ?? this.available;
+ this.rule = init?.rule ?? {};
this.initialized = true;
this.initializedDeferred.resolve();
}
diff --git a/addons/im_livechat/views/im_livechat_chatbot_templates.xml b/addons/im_livechat/views/im_livechat_chatbot_templates.xml
index 0da13bf3d9c..05b89bfb8bb 100644
--- a/addons/im_livechat/views/im_livechat_chatbot_templates.xml
+++ b/addons/im_livechat/views/im_livechat_chatbot_templates.xml
@@ -7,19 +7,19 @@