-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][NEW] Módulo de integração entre Helpdesk e Discord
- Loading branch information
1 parent
9e26f90
commit 4923683
Showing
9 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
================================= | ||
KMEE HELDESK DISCORD INTEGRATION | ||
================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
enterprise_helpdesk_discord_connector/models/helpdesk_ticket.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
65
enterprise_helpdesk_discord_connector/models/res_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} |
43 changes: 43 additions & 0 deletions
43
enterprise_helpdesk_discord_connector/views/res_config_settings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
1 change: 1 addition & 0 deletions
1
...p/enterprise_helpdesk_discord_connector/odoo/addons/enterprise_helpdesk_discord_connector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../enterprise_helpdesk_discord_connector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |