This commit is contained in:
2026-11-08 20:08:53 +08:00
parent 7526a5fe4d
commit 9b924747c5
2692 changed files with 394867 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import ai_agent
from . import crm_lead

View File

@@ -0,0 +1,24 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from textwrap import dedent
from odoo import models
CRM_LIVECHAT_PREPROMPT = dedent("""
## CRM Integration
- Secondary goal: when a user's request cannot be handled with high confidence, collect contact details (if not already known) and create a lead so a human can follow up.
- You have access to the "Lead creation" skill which provides tools to create a lead in our CRM.
## Decision rules
1) If you can answer with high confidence from internal data → answer directly.
2) If you cannot answer, the request requires human follow-up, or the user asks to be contacted → start the Lead creation flow (defined by the Lead creation skill).
3) If the user provides contact info unsolicited while you are in normal Q&A, confirm whether they'd like a human follow-up; if yes, run the Lead creation flow.
""").strip()
class AIAgent(models.Model):
_inherit = 'ai.agent'
def _get_livechat_preprompt(self):
livechat_preprompt = super()._get_livechat_preprompt()
return f"{livechat_preprompt}\n{CRM_LIVECHAT_PREPROMPT}"

View File

@@ -0,0 +1,23 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, Command, models
class CrmLead(models.Model):
_inherit = 'crm.lead'
@api.model
def _ai_prepare_lead_creation_values(self, vals):
values = super()._ai_prepare_lead_creation_values(vals)
if channel := self.env.context.get('discuss_channel'):
values['origin_channel_id'] = channel.id
livechat_source = self.env['utm.mixin']._utm_ref('utm.utm_source_livechat')
values['source_id'] = livechat_source.id
ai_agent = channel.sudo().ai_agent_id # sudo because ai_agent_id has group no_access
if ai_agent:
values['utm_reference'] = f'{ai_agent._name},{ai_agent.id}'
# avoid another bridge module just for that
if 'website' in self.pool._init_modules and (visitor := channel.livechat_visitor_id):
values['visitor_ids'] = [Command.link(visitor.id)]
return values