-
Notifications
You must be signed in to change notification settings - Fork 1
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
9d596e3
commit 38d6e9b
Showing
7 changed files
with
135 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,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" | ||
] | ||
} |
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 |
27 changes: 27 additions & 0 deletions
27
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,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
56
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,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, | ||
} | ||
} | ||
|
29 changes: 29 additions & 0 deletions
29
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,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> |