Files
odoo_source/addons/website_livechat/controllers/chatbot.py
T
Louis Wicket (wil) fdcaa53ca0 [IMP] mail, *: rename mail.channel.partner to mail.channel.member
* = calendar, crm_livechat, hr_holidays, im_livechat, privacy_lookup,
privacy_lookup, test_discuss_full, test_mail_full, website_livechat

closes odoo/odoo#95912

Related: odoo/upgrade#3681
Related: odoo/enterprise#29433
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-07-19 11:50:37 +02: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 mail.channel
that will hold the conversation between the bot and the user testing the script. """
mail_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,
'public': 'private',
}
visitor_sudo = request.env['website.visitor']._get_visitor_from_request()
if visitor_sudo:
mail_channel_values['livechat_visitor_id'] = visitor_sudo.id
mail_channel = request.env['mail.channel'].create(mail_channel_values)
return request.render("im_livechat.chatbot_test_script_page", {
'server_url': chatbot_script.get_base_url(),
'channel_data': mail_channel.channel_info()[0],
'chatbot_data': chatbot_script._format_for_frontend()
})