summaryrefslogtreecommitdiff
path: root/addons/mail_bot
diff options
context:
space:
mode:
authorXavierDo <xdo@odoo.com>2018-08-13 18:49:19 +0200
committerXavierDo <xdo@odoo.com>2018-08-13 21:45:53 +0200
commit2df29bcfbdf8e754903b6ef3a0a7dddc00f61b08 (patch)
treec38ad750cb029e450b3a83ef0d8776fe26cb7966 /addons/mail_bot
parent9916e5bad3ed5eb77d2dadaa1d06949ec3b02347 (diff)
[IMP] mail_bot: make odoobot statefull
The current implementation of odoobot is stateless, making him a little dummy. Adding a state on the user allow to be sure that the user don't skip a step, or loop back to a previous step. States also allows odoobot to repeat the question when the user don't give the right answer. A quick modification asked by FP before freeze, in order to change the field type in time.
Diffstat (limited to 'addons/mail_bot')
-rw-r--r--addons/mail_bot/models/ir_http.py2
-rw-r--r--addons/mail_bot/models/mail_bot.py32
-rw-r--r--addons/mail_bot/models/mail_channel.py4
-rw-r--r--addons/mail_bot/models/res_users.py12
4 files changed, 35 insertions, 15 deletions
diff --git a/addons/mail_bot/models/ir_http.py b/addons/mail_bot/models/ir_http.py
index ae01cb3e76f..09d997dbca0 100644
--- a/addons/mail_bot/models/ir_http.py
+++ b/addons/mail_bot/models/ir_http.py
@@ -9,5 +9,5 @@ class Http(models.AbstractModel):
def session_info(self):
res = super(Http, self).session_info()
- res['odoobot_initialized'] = self.env.user.odoobot_initialized
+ res['odoobot_initialized'] = self.env.user.odoobot_state == 'not_initialized'
return res
diff --git a/addons/mail_bot/models/mail_bot.py b/addons/mail_bot/models/mail_bot.py
index c3a6e74b3c5..50d43185454 100644
--- a/addons/mail_bot/models/mail_bot.py
+++ b/addons/mail_bot/models/mail_bot.py
@@ -33,17 +33,20 @@ class MailBot(models.AbstractModel):
def _get_answer(self, record, body, values, command=False):
# onboarding
+ odoobot_state = self.env.user.odoobot_state
if self._is_bot_in_private_channel(record):
# main flow
- if body in ('hi', 'hello'):
- return _("Hi, I will guide you through chat features. First, try to send me an emoji 😊")
- elif self._body_contains_emoji(body):
+ if odoobot_state == 'onboarding_emoji' and self._body_contains_emoji(body):
+ self.env.user.odoobot_state = "onboarding_attachement"
return _("Great! :) Did you notice that you can also send attachments, like a picture of your cute dog? Try it!")
- elif values.get("attachment_ids"):
+ elif odoobot_state == 'onboarding_attachement' and values.get("attachment_ids"):
+ self.env.user.odoobot_state = "onboarding_command"
return _("Not a cute dog, but you get it :) To access special features, start your sentence with '/' (e.g. /help).")
- elif command == 'help':
+ elif odoobot_state == 'onboarding_command' and command == 'help':
+ self.env.user.odoobot_state = "onboarding_ping"
return _("Wow you are a natural! Ping someone to grab its attention with @nameoftheuser. Try to ping me with <b>@OdooBot</b>.")
- elif self._is_bot_pinged(values):
+ elif odoobot_state == 'onboarding_ping' and self._is_bot_pinged(values):
+ self.env.user.odoobot_state = "idle"
discuss_href = 'href="/web#action=mail.mail_channel_action_client_chat&active_id=%s"' % record.id
discuss_src = 'src="/mail_bot/static/img/odoobot_discuss.png"'
chatter_src = 'src="/mail_bot/static/img/odoobot_chatter.png"'
@@ -54,15 +57,24 @@ class MailBot(models.AbstractModel):
-or via the chatter:<br/><img %s/><br/><br/>\
Aaaaand that's it! Enjoy discovering Odoo!") % (discuss_href, discuss_src, chatter_src)
# easter eggs
- elif body in ['❤️', _('i love you'), _('love')]:
+ elif odoobot_state == "idle" and body in ['❤️', _('i love you'), _('love')]:
return _("Aaaaaw that's really cute but, you know, bots don't work that way. You're too human for me! Let's keep it professional ❤️")
- elif body in [_('help'), _('help me'), _('i need help')]:
+ elif odoobot_state == "idle" and body in [_('help'), _('help me'), _('i need help')]:
return _("I'm trying to help you, but I'm just a bot... :( You can also check <a href=\"https://www.odoo.com/page/docs\">our documentation</a>) for more information!")
- elif _('fuck') in body or "fuck" in body:
+ elif odoobot_state == "idle" and _('fuck') in body or "fuck" in body:
return _("That's not a really nice thing to say, you know? I'm a bot but I have feelings, ok?! 💔")
else:
+ #repeat question
+ if odoobot_state == 'onboarding_emoji':
+ return _("Not exactly. To send an emoji, type \":)\" and press enter.")
+ elif odoobot_state == 'onboarding_attachement':
+ return _("I want you to send me an attachement, you should press the button next to the chat bar to select a file.")
+ elif odoobot_state == 'onboarding_command':
+ return _("Not sure wat you are doing. Please press / and wait for the propositions. Select \"help\" and press enter")
+ elif odoobot_state == 'onboarding_ping':
+ return _("Please, ping me. Type and \"@\" and begin to type \"odoobot\". Select the proposition and press enter.")
return random.choice([
- _("Mmmmh I'm not sure what you mean.. Can you try again?"),
+ _("I'm not smart enough to answer your question, sorry."),
_("I'm afraid I don't understand. Sorry!")
])
elif self._is_bot_pinged(values):
diff --git a/addons/mail_bot/models/mail_channel.py b/addons/mail_bot/models/mail_channel.py
index 23978eff1e6..60a8f7dd07d 100644
--- a/addons/mail_bot/models/mail_channel.py
+++ b/addons/mail_bot/models/mail_channel.py
@@ -25,7 +25,7 @@ class Channel(models.Model):
@api.model
def init_odoobot(self):
- if not self.env.user.odoobot_initialized:
+ if self.env.user.odoobot_state == 'not_initialized':
partner = self.env.user.partner_id
odoobot_id = self.env['ir.model.data'].xmlid_to_res_id("mail_bot.partner_odoobot")
channel = self.with_context({"mail_create_nosubscribe": True}).create({
@@ -37,5 +37,5 @@ class Channel(models.Model):
})
message = _("Hello, I'm here to help you discover chat features. Try answering me with an emoji 😊")
channel.message_post(body=message, author_id=odoobot_id, message_type="comment", subtype="mail.mt_comment")
- self.env.user.odoobot_initialized = True
+ self.env.user.odoobot_state = 'onboarding_emoji'
return channel
diff --git a/addons/mail_bot/models/res_users.py b/addons/mail_bot/models/res_users.py
index 8c880b11a6e..2905e3d8f5e 100644
--- a/addons/mail_bot/models/res_users.py
+++ b/addons/mail_bot/models/res_users.py
@@ -5,5 +5,13 @@ from odoo import models, fields
class Users(models.Model):
_inherit = 'res.users'
-
- odoobot_initialized = fields.Boolean(readonly=True, default=False)
+ odoobot_state = fields.Selection(
+ [
+ ('not_initialized', 'Not initialized'),
+ ('onboarding_emoji', 'Onboarding emoji'),
+ ('onboarding_attachement', 'Onboarding attachement'),
+ ('onboarding_command', 'Onboarding command'),
+ ('onboarding_ping', 'Onboarding ping'),
+ ('idle', 'Idle'),
+ ('disabled', 'Disabled'),
+ ], string="Odoobot Status", readonly=True, required=True, default="not_initialized") # keep track of the state: correspond to the code of the last message sent