Files
odoo_source/addons/website_livechat/controllers/chatbot.py
T
tsm-odoo 4b72cd0e3f [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>
2023-09-04 20:55:13 +00:00

43 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.http import request
class WebsiteLivechatChatbotScriptController(http.Controller):
@http.route('/chatbot/<model("chatbot.script"):chatbot_script>/test',
type="http", auth="user", website=True)
def chatbot_test_script(self, chatbot_script):
""" Custom route allowing to test a chatbot script.
As we don't have a im_livechat.channel linked to it, we pre-emptively create a discuss.channel
that will hold the conversation between the bot and the user testing the script. """
discuss_channel_values = {
'channel_member_ids': [(0, 0, {
'partner_id': chatbot_script.operator_partner_id.id,
'is_pinned': False
}, {
'partner_id': request.env.user.partner_id.id
})],
'livechat_active': True,
'livechat_operator_id': chatbot_script.operator_partner_id.id,
'chatbot_current_step_id': chatbot_script._get_welcome_steps()[-1].id,
'anonymous_name': False,
'channel_type': 'livechat',
'name': chatbot_script.title,
}
visitor_sudo = request.env['website.visitor']._get_visitor_from_request()
if visitor_sudo:
discuss_channel_values['livechat_visitor_id'] = visitor_sudo.id
discuss_channel = request.env['discuss.channel'].create(discuss_channel_values)
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(),
'current_partner_id': request.env.user.partner_id.id,
})