diff --git a/ai_helpdesk_agent/__manifest__.py b/ai_helpdesk_agent/__manifest__.py index ae0069a..1529b3a 100644 --- a/ai_helpdesk_agent/__manifest__.py +++ b/ai_helpdesk_agent/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'AI Helpdesk Agent', - 'version': '16.0.0.1.0', + 'version': '18.0.0.1.0', 'summary': 'Process tickets with AI and send responses to customers.', 'description': 'AI for helpdesk tickets', 'category': 'Services/Helpdesk', diff --git a/ai_helpdesk_agent/const.py b/ai_helpdesk_agent/const.py index 18ace01..3e4b2ca 100644 --- a/ai_helpdesk_agent/const.py +++ b/ai_helpdesk_agent/const.py @@ -1,3 +1,5 @@ class AIActions: """AI Actions for Helpdesk Tickets get from AI API""" ESCALATE = 'ESCALATE' + +HTML_FOR_AI_RESPONSE = True diff --git a/ai_helpdesk_agent/models/conversation_examples.py b/ai_helpdesk_agent/models/conversation_examples.py index ec75404..32e228c 100644 --- a/ai_helpdesk_agent/models/conversation_examples.py +++ b/ai_helpdesk_agent/models/conversation_examples.py @@ -11,7 +11,6 @@ class ConversationExamples(models.Model): ticket_id = fields.Many2one('helpdesk.ticket') subject = fields.Char() description = fields.Char() - ticket_type_id = fields.Many2one('helpdesk.ticket.type') partner_id = fields.Many2one('res.partner') customer_name = fields.Char() customer_email = fields.Char() @@ -32,7 +31,6 @@ def get_conv_examples(self): 'ticket_id': exmpl_id.ticket_id.id, 'subject': '', 'description': exmpl_id.description, - 'ticket_type': exmpl_id.ticket_type_id.name, 'status': exmpl_id.state if exmpl_id.active else 'archived', 'last_update_at': str(exmpl_id.write_date.timestamp()).split('.')[0], 'customer_name': exmpl_id.customer_name, diff --git a/ai_helpdesk_agent/models/helpdesk_team.py b/ai_helpdesk_agent/models/helpdesk_team.py index ad545e8..a724576 100644 --- a/ai_helpdesk_agent/models/helpdesk_team.py +++ b/ai_helpdesk_agent/models/helpdesk_team.py @@ -5,7 +5,7 @@ class HelpdeskTeam(models.Model): _inherit = 'helpdesk.team' - mail_shortcode_ids = fields.Many2many('mail.shortcode') + mail_shortcode_ids = fields.Many2many('mail.canned.response') @api.model def get_templates(self): @@ -18,4 +18,4 @@ def get_templates(self): 'id': canned.id, 'substitution': canned.substitution, } for canned in team.mail_shortcode_ids] - return json.dumps(templates) \ No newline at end of file + return json.dumps(templates) diff --git a/ai_helpdesk_agent/models/helpdesk_ticket.py b/ai_helpdesk_agent/models/helpdesk_ticket.py index d88eaec..6a51542 100644 --- a/ai_helpdesk_agent/models/helpdesk_ticket.py +++ b/ai_helpdesk_agent/models/helpdesk_ticket.py @@ -7,7 +7,7 @@ from odoo import models, fields, api from odoo.fields import Command -from ..const import AIActions +from ..const import AIActions, HTML_FOR_AI_RESPONSE _logger = logging.getLogger(__name__) @@ -17,7 +17,8 @@ def send_default_email(ticket_id): def send_ai_response(ticket_id, ai_result, user_id): - ticket_id.sudo().message_post(body=ai_result, message_type='comment', subtype_xmlid='mail.mt_comment', + ticket_id.sudo().message_post(body=ai_result, body_is_html=HTML_FOR_AI_RESPONSE, + message_type='comment', subtype_xmlid='mail.mt_comment', author_id=user_id.sudo().partner_id.id) def get_ai_user(env): @@ -121,6 +122,9 @@ def _process_ai_response(self, request, continue_conv): self._set_error_tag() _logger.error(f'{self.id} AI Error, text: {request.text}, status: {request.status_code}') return + if dry_run: + send_default_email(self) + return request_data = request.json() text = request_data.get('text', '') escalate = request_data.get('actions', []) @@ -130,7 +134,8 @@ def _process_ai_response(self, request, continue_conv): if text: send_ai_response(self, text, ai_user_id) if reasoning: - self.message_post(body=reasoning, message_type='comment', subtype_xmlid='mail.mt_note') + self.message_post(body=reasoning, body_is_html=HTML_FOR_AI_RESPONSE, + message_type='comment', subtype_xmlid='mail.mt_note') def _save_ticket(self, escalate, continue_conv): self.ensure_one() @@ -199,7 +204,6 @@ def _get_request_data(self, messages=[]): 'ticket_id': self.id, 'subject': self.name if self.name else '', 'description': str(self.description) if self.description else '', - 'ticket_type': self.ticket_type_id.name if self.ticket_type_id.name else '', 'customer_name': self.partner_id.name if self.partner_id.name else '', 'customer_email': self.partner_id.email if self.partner_id.email else '', 'question': '', @@ -214,7 +218,6 @@ def _action_conv_expl(self): 'ticket_id': self.id, 'subject': self.name, 'description': str(self.description), - 'ticket_type_id': self.ticket_type_id.id, 'partner_id': self.partner_id.id, 'customer_name': self.partner_id.name, 'customer_email': self.partner_id.email, diff --git a/ai_helpdesk_agent/views/conversation_examples_view.xml b/ai_helpdesk_agent/views/conversation_examples_view.xml index 63c49fb..b60439f 100644 --- a/ai_helpdesk_agent/views/conversation_examples_view.xml +++ b/ai_helpdesk_agent/views/conversation_examples_view.xml @@ -8,47 +8,50 @@