Skip to content

Commit

Permalink
[16.0][NEW] Módulo de integração entre Helpdesk e Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMarcos committed May 17, 2024
1 parent 9d596e3 commit 38d6e9b
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions enterprise_helpdesk_discord_connector/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=================================
KMEE HELDESK DISCORD INTEGRATION
=================================
1 change: 1 addition & 0 deletions enterprise_helpdesk_discord_connector/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions enterprise_helpdesk_discord_connector/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Enterprise Helpdesk Discord Connector",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "KMEE",
"website": "https://kmee.com.br",
"depends": [
"base",
"helpdesk",
],
"data": [
"views/res_config_settings.xml"
]
}
2 changes: 2 additions & 0 deletions enterprise_helpdesk_discord_connector/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import helpdesk_ticket
from . import res_config
27 changes: 27 additions & 0 deletions enterprise_helpdesk_discord_connector/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, fields, api
import requests
from odoo.tools import html2plaintext

class HelpdeskTicket(models.Model):
_inherit = 'helpdesk.ticket'

@api.model
def create(self, vals):
ticket = super(HelpdeskTicket, self).create(vals)
self.send_discord_notification(ticket)
return ticket

def send_discord_notification(self, ticket):
webhook_url = self.env['ir.config_parameter'].sudo().get_param('helpdesk.discord_webhook_url')
if webhook_url:
description = html2plaintext(ticket.description or "")
data = {
"content": f"Novo ticket criado:\n**Título:** {ticket.name}\n**Cliente:** {ticket.partner_id.name}\n**Responsável:** {ticket.user_id.name or 'N/A'}\n**Descrição:** {description}"
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(webhook_url, json=data, headers=headers)
56 changes: 56 additions & 0 deletions enterprise_helpdesk_discord_connector/models/res_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models, fields
import requests


class HelpdeskConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

discord_webhook_url = fields.Char(string="Discord Webhook URL", config_parameter='helpdesk.discord_webhook_url')

def action_test_discord_webhook(self):
webhook_url = self.env['ir.config_parameter'].sudo().get_param('helpdesk.discord_webhook_url')
if webhook_url:
data = {
"content": "Teste de integração do webhook do Discord: A integração está funcionando corretamente."
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(webhook_url, json=data, headers=headers)
if response.status_code == 204 or response.status_code==200:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': 'Sucesso!',
'message': 'Notificação de teste enviada com sucesso para o Discord.',
'type': 'success',
'sticky': False,
}
}
else:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': 'Erro!',
'message': f'Falha ao enviar notificação para o Discord: {response.status_code} - {response.text}',
'type': 'danger',
'sticky': False,
}
}
else:
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'title': 'Erro!',
'message': 'URL do webhook do Discord não está configurada.',
'type': 'danger',
'sticky': False,
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.helpdesk</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[hasclass('settings')]" position="inside">
<div class="app_settings_block" data-string="Helpdesk" data-key="helpdesk" string="Helpdesk" >
<h2>Integração do Helpdesk com Discord</h2>
<div class="col-xs-12 row o_settings_container">
<div class="col-xs-12 row col-md-12 o_setting_box">
<div class="o_setting_right_pane border-start-0">
<div class="content-group">
<div class="row">
<label for="discord_webhook_url">Discord Webhook URL</label>
<field name="discord_webhook_url" class="form-control"/>
<button name="action_test_discord_webhook" string="Testar Webhook do Discord" type="object" class="btn btn-primary"/>
</div>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 38d6e9b

Please sign in to comment.