1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import common
class ChatbotCase(common.HttpCase):
@classmethod
def setUpClass(cls):
super(ChatbotCase, cls).setUpClass()
cls.chatbot_script = cls.env['chatbot.script'].create({
'title': 'Testing Bot',
})
ChatbotScriptStep = cls.env['chatbot.script.step'].sudo()
[
cls.step_hello,
cls.step_welcome,
cls.step_dispatch,
] = ChatbotScriptStep.create([{
'step_type': 'text',
'message': "Hello! I'm a bot!",
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'text',
'message': "I help lost visitors find their way.",
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'question_selection',
'message': "How can I help you?",
'chatbot_script_id': cls.chatbot_script.id,
}])
[
cls.step_dispatch_buy_software,
cls.step_dispatch_pricing,
cls.step_dispatch_operator,
] = cls.env['chatbot.script.answer'].sudo().create([{
'name': 'I want to buy the software',
'script_step_id': cls.step_dispatch.id,
}, {
'name': 'Pricing Question',
'script_step_id': cls.step_dispatch.id,
}, {
'name': "I want to speak with an operator",
'script_step_id': cls.step_dispatch.id,
}])
[
cls.step_pricing_contact_us,
cls.step_email,
cls.step_email_validated,
cls.step_forward_operator,
cls.step_no_one_available,
cls.step_no_operator_dispatch,
] = ChatbotScriptStep.create([{
'step_type': 'text',
'message': 'For any pricing question, feel free ton contact us at pricing@mycompany.com',
'triggering_answer_ids': [(4, cls.step_dispatch_pricing.id)],
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'question_email',
'message': 'Can you give us your email please?',
'triggering_answer_ids': [(4, cls.step_dispatch_buy_software.id)],
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'text',
'message': 'Your email is validated, thank you!',
'triggering_answer_ids': [(4, cls.step_dispatch_buy_software.id)],
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'forward_operator',
'message': 'I will transfer you to a human.',
'triggering_answer_ids': [(4, cls.step_dispatch_operator.id)],
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'text',
'message': 'Sorry, you will have to stay with me for a while',
'triggering_answer_ids': [(4, cls.step_dispatch_operator.id)],
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'question_selection',
'message': 'So... What can I do to help you?',
'triggering_answer_ids': [(4, cls.step_dispatch_operator.id)],
'chatbot_script_id': cls.chatbot_script.id,
}])
cls.step_no_operator_just_leaving = cls.env['chatbot.script.answer'].sudo().create({
'name': 'I will be leaving then',
'script_step_id': cls.step_no_operator_dispatch.id,
})
[
cls.step_just_leaving,
cls.step_pricing_thank_you,
cls.step_ask_website,
cls.step_ask_feedback,
cls.step_goodbye,
] = ChatbotScriptStep.create([{
'step_type': 'text',
'message': "Ok, I'm sorry I was not able to help you",
'triggering_answer_ids': [(4, cls.step_no_operator_just_leaving.id)],
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'text',
'message': 'We will reach back to you as soon as we can!',
'triggering_answer_ids': [(4, cls.step_dispatch_pricing.id)],
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'free_input_single',
'message': 'Would you mind providing your website address?',
'sequence': 97, # makes it easier for other modules to add steps before this one
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'free_input_multi',
'message': 'Great, do you want to leave any feedback for us to improve?',
'sequence': 98, # makes it easier for other modules to add steps before this one
'chatbot_script_id': cls.chatbot_script.id,
}, {
'step_type': 'text',
'message': "Ok bye!",
'sequence': 99, # makes it easier for other modules to add steps before this one
'chatbot_script_id': cls.chatbot_script.id,
}])
cls.livechat_channel = cls.env['im_livechat.channel'].create({
'name': 'Test Channel',
'rule_ids': [(0, 0, {
'chatbot_script_id': cls.chatbot_script.id,
})]
})
@classmethod
def _post_answer_and_trigger_next_step(cls, discuss_channel, answer, chatbot_script_answer=False):
mail_message = discuss_channel.message_post(body=answer)
if chatbot_script_answer:
cls.env['chatbot.message'].search([
('mail_message_id', '=', mail_message.id)
], limit=1).user_script_answer_id = chatbot_script_answer.id
next_step = discuss_channel.chatbot_current_step_id._process_answer(discuss_channel, mail_message.body)
next_step._process_step(discuss_channel)
|