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 22, 2024
1 parent 9e26f90 commit 4923683
Show file tree
Hide file tree
Showing 9 changed files with 175 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
15 changes: 15 additions & 0 deletions enterprise_helpdesk_discord_connector/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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, Odoo Community Association (OCA)",
"website": "https://github.com/KMEE/kmee-odoo-addons",
"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
39 changes: 39 additions & 0 deletions enterprise_helpdesk_discord_connector/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import requests

from odoo import api, models
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, timeout=200
)

if response.status_code != 202 or 200:
pass
65 changes: 65 additions & 0 deletions enterprise_helpdesk_discord_connector/models/res_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import requests

from odoo import fields, models


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, timeout=200
)
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,43 @@
<?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>
6 changes: 6 additions & 0 deletions setup/enterprise_helpdesk_discord_connector/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 4923683

Please sign in to comment.