[FIX] im_livechat: fix chatbot test page
This PR fixes a server error when trying to test a chatbot that appeared with the [livechat refactoring]. Steps to reproduce: - Go to a livechat channel form view - Click on the "chatbot" smart button - Click on a chatbot - Click on the "test" button - An internal server error occurs task-3485014 [livechat refactoring]: https://github.com/odoo/odoo/pull/122834 closes odoo/odoo#134227 X-original-commit: dfc50ea4e4fb327876458afee1b807e36ce80c2b Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
<t t-set="head">
|
||||
<script>
|
||||
<t t-call="im_livechat.loader">
|
||||
<t t-set="info" t-value="{ 'available': True, 'options': { 'isTestChatbot': True, 'testChatbotChannelData': channel_data, 'testChatbotData': chatbot_data }, 'server_url': server_url }"/>
|
||||
<t t-set="info" t-value="{ 'available': True, 'options': { 'isTestChatbot': True, 'testChatbotChannelData': channel_data, 'testChatbotData': chatbot_data, 'current_partner_id': current_partner_id }, 'server_url': server_url }"/>
|
||||
</t>
|
||||
</script>
|
||||
</t>
|
||||
<t t-set="title" t-value="chatbot_data['chatbot_name']"/>
|
||||
<t t-set="title" t-value="chatbot_data['name']"/>
|
||||
|
||||
<div id="wrap">
|
||||
<div groups="im_livechat.im_livechat_group_user" t-ignore="true"
|
||||
class="alert alert-info alert-dismissible rounded-0 fade show d-print-none css_editable_mode_hidden mb-0">
|
||||
<div t-ignore="true" class="text-center">
|
||||
<a t-attf-href="/web#view_type=form&model=chatbot.script&id=#{chatbot_data['chatbot_script_id']}&action=im_livechat.chatbot_script_action">
|
||||
<a t-attf-href="/web#view_type=form&model=chatbot.script&id=#{chatbot_data['scriptId']}&action=im_livechat.chatbot_script_action">
|
||||
<span>You are currently testing</span>
|
||||
<span t-out="chatbot_data['chatbot_name']"/>
|
||||
<span t-out="chatbot_data['name']"/>
|
||||
<i class="oi oi-fw oi-arrow-right"/>Back to edit mode
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -37,5 +37,6 @@ class WebsiteLivechatChatbotScriptController(http.Controller):
|
||||
return request.render("im_livechat.chatbot_test_script_page", {
|
||||
'server_url': chatbot_script.get_base_url(),
|
||||
'channel_data': discuss_channel._channel_info()[0],
|
||||
'chatbot_data': chatbot_script._format_for_frontend()
|
||||
'chatbot_data': chatbot_script._format_for_frontend(),
|
||||
'current_partner_id': request.env.user.partner_id.id,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user