Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add discord webhook to send msg when there's new ticket #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Controller/SupportAppController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
class SupportAppController extends AppController
{
protected function sendDiscordMessage($msg = "", $embedData = [])
{
$this->loadModel("Support.SettingsSupport");
$discordWebhook = $this->SettingsSupport->find("first");
if (empty($discordWebhook) || empty($discordWebhook["SettingsSupport"]["discord_webhook"]))
return false;

$discordWebhook = explode("/", $discordWebhook["SettingsSupport"]["discord_webhook"]);
$webhookData = [
"id" => $discordWebhook[5],
"token" => $discordWebhook[6]
];

$handle = curl_init("https://discord.com/api/webhooks/" . $webhookData["id"] . "/" . $webhookData["token"]);

$data = json_encode([
"content" => $msg,
"embeds" => $embedData
]);

curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_HTTPHEADER,
array(
'Content-Type:application/json',
'Content-Length: ' . strlen($data)
)
);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);

$res = curl_exec($handle);
return true;
}
}

44 changes: 41 additions & 3 deletions Controller/SupportController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SupportController extends AppController
class SupportController extends SupportAppController
{
public $components = ['EySecurity'];

Expand Down Expand Up @@ -71,11 +71,38 @@ function admin_index()
function admin_config()
{
$this->layout = 'admin';
if (!$this->Permissions->can('SETTINGS_SUPPORT'))
if (!$this->Permissions->can('PERMISSIONS__SETTINGS_SUPPORT'))
throw new ForbiddenException();
$this->set('title_for_layout', $this->Lang->get('SUPPORT__SETTINGS_TITLE') . ' - ' . $this->Lang->get('SUPPORT__SUPPORT'));

$this->loadModel('Support.SettingsSupport');
if ($this->request->is('post')) {
if (!isset($this->request->data["webhook"])) {
return $this->sendJSON(['statut' => false, 'msg' => $this->Lang->get('ERROR__FILL_ALL_FIELDS')]);
}

$settings = $this->SettingsSupport->find('first');
if (!$settings) {
$this->SettingsSupport->create([
"discord_webhook" => $this->request->data["webhook"]
]);
} else {
$this->SettingsSupport->read(null, $settings["SettingsSupport"]["id"]);
$this->SettingsSupport->set([
"discord_webhook" => $this->request->data["webhook"]
]);
}

$this->SettingsSupport->save();
$this->Session->setFlash($this->Lang->get('CONFIG__EDIT_SUCCESS'), 'default.success');
$this->redirect("/admin/support/config");
}

$this->set('title_for_layout', $this->Lang->get('SUPPORT__SETTINGS_TITLE') . ' - ' . $this->Lang->get('SUPPORT__SUPPORT'));
$settings = $this->SettingsSupport->find('first');
if ($settings) {
$settings = $settings["SettingsSupport"];
}

$this->set(compact('settings'));
}

Expand Down Expand Up @@ -222,6 +249,17 @@ function ajax_create()
));
$this->Ticket->save();
$this->Notification->setToAdmin($this->User->getKey('pseudo') . ' ' . $this->Lang->get('SUPPORT__NOTIF_CREATE'));

$this->loadModel("Support.CategoriesSupport");
$categorieName = $this->CategoriesSupport->find("first", ["conditions" => ["id" => $this->request->data['categorie']]])["CategoriesSupport"]["name"];
$this->sendDiscordMessage("", [array(
"title" => "SUPPORT: Nouveau ticket par " . $this->User->getKey("pseudo"),
"color" => "3447003",
"description" => $this->Lang->get('SUPPORT__DISCORD_EMBED_CREATE_DESCRIPTION',
['{SUBJECT_NAME}' => $this->request->data['subject'], '{CATEGORIE_NAME}' => $categorieName]
)
)]);

$this->sendJSON(['statut' => true, 'msg' => $this->Lang->get('SUPPORT__SUCCESS_CREATE')]);
}

Expand Down
1 change: 1 addition & 0 deletions SQL/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function after($event = array()) {
public $support__settings = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
'suffix_reply' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'discord_webhook' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1)
),
Expand Down
20 changes: 13 additions & 7 deletions View/Support/admin_config.ctp
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
<?php
App::import('Controller', 'SupportController');
$Support = new SupportController();
?>
<section class="content">
<h3 style="margin-top: 6px;"><?= $Lang->get('SUPPORT__SETTINGS_TITLE'); ?></h3>
<div class="card">
<div class="card-body">
Bientôt
<form method="post">
<div class="row">
<div class="col-sm-5">
<label><?= $Lang->get('SUPPORT__SETTINGS_WEBHOOK'); ?></label>
<input type="text" class="form-control" name="webhook" value="<?= $settings ? $settings["discord_webhook"] : "" ?>">
</div>
</div>

<button type="submit"
class="btn btn-primary float-right"><?= $Lang->get('GLOBAL__SUBMIT'); ?></button>
</form>
</div>
</div>
</section>
<div class="modal fade" id="modal-settings-suffix" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><?= $Lang->get('SUPPORT__SHOW_EDIT'); ?></h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<h4>Aperçu</h4>
<hr>
<blockquote>
<?= $settings['SettingsSupport']['suffix_reply']; ?>
<?= $settings ? $settings['suffix_reply'] : "" ?>
</blockquote>
</div>
<div class="modal-footer">
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Support",
"author": "Eywek",
"version": "1.0.45",
"version": "1.0.46",
"admin_menus": {
"Support": {
"icon": "fas fa-ticket-alt",
Expand Down
162 changes: 82 additions & 80 deletions lang/en_US.json
Original file line number Diff line number Diff line change
@@ -1,85 +1,87 @@
{
"SUPPORT__SUPPORT": "Support",
"SUPPORT__SUBJECT": "Subject",
"SUPPORT__POST_A_TICKET": "Post a ticket",
"SUPPORT__AUTHOR": "Author",
"SUPPORT__STATE_TITLE": "State",
"SUPPORT__STATE_0": "Waiting",
"SUPPORT__STATE_1": "Answered",
"SUPPORT__STATE_2": "Clôs",
"SUPPORT__STATE_3": "Reopened",
"SUPPORT__CREATED": "Creation Date",
"SUPPORT__ACTIONS": "Options",
"SUPPORT__SHOW": "See",
"SUPPORT__CLOSE": "Close",
"SUPPORT__UNCLOSE": "Reopen",
"SUPPORT__DELETE": "Delete",
"SUPPORT__CLOSED": "Close",
"SUPPORT__MODIFY": "Edit",
"SUPPORT__EDIT": "Edit",
"SUPPORT__PROBLEMQUESTION": "Ticket n ° {ID_TICKET}",
"SUPPORT__CREATEDATE": "Sent the",
"SUPPORT__ANSWERTO": "Answer of",
"SUPPORT__ANSWER": "Answers",
"SUPPORT__REPLYTICKET": "Reply to the ticket",
"SUPPORT__REPLY": "Reply",
"SUPPORT_BACK_TO_LIST": "Back to the ticket list",
"SUPPORT__CLOSTICKETWARNING": "The ticket has been closed, so you can not answer anymore.",
"SUPPORT__CREATE": "Create a ticket",
"SUPPORT__CREATETITLE": "Creating a ticket",
"SUPPORT__YOURPROBLEM": "Your problem",
"SUPPORT__CREATETICKET": "Create ticket",
"SUPPORT__TICKETNUMBER": "Ticket N °",
"SUPPORT__SUCCESS_CREATE": "Ticket successfully created!",
"SUPPORT__SUCCESS_SEND_ANSWER": "Your reply has been sent successfully!",
"SUPPORT__SUCCESS_CLOSE": "The ticket has been closed successfully!",
"SUPPORT__SUCCESS_UNCLOSE": "The ticket has been opened successfully!",
"SUPPORT__SUCCESS_DELETE": "The ticket has been successfully deleted!",
"SUPPORT__ERROR_PROBLEM_SHORT": "The description of your problem is too short (50 characters minimum)",
"SUPPORT__ERROR_RESOLVE_EMPTY": "The description of your resolution is empty!",
"SUPPORT__GESTION_TICKETS": "Tickets management",
"SUPPORT__SETTINGS_TITLE": "Media Settings",
"SUPPORT__GESTION_CATEGORIES": "Category Management",
"SUPPORT__TICKET_NOT_EXIST": "The ticket seems to be non-existent!",
"SUPPORT__NOTIF_CREATE": "opened a ticket!",
"SUPPORT__NOTIF_ANSWER": "answered the ticket N °",
"SUPPORT__NOTIF_CLOS": "closed the ticket N °",
"SUPPORT__NOTIF_UNCLOS": "reopened the ticket N °",
"SUPPORT__ERROR_PERMISSION_ANSWER": "You do not have permission to reply to tickets.",
"SUPPORT__SHOW_EDIT": "View / modify answer suffix",
"SUPPORT__WARNING_ALERT": "Support Plugin | Information",
"SUPPORT__WARNING_ALERT_MAJ": "This update makes important changes in the source code and you may encounter internal errors.",
"SUPPORT__WARNING_ALERT_MAJ_MORE": "Remember to clear the cache properly by deleting the folder <b>app/tmp/cache</b>.",
"SUPPORT__TICKET_ETAT_LIST": "Ticket Status List",
"SUPPORT__TICKET_TITLE": "Tickets",
"SUPPORT__TICKET_NOTHING_ETAT": "No ticket is in the state",
"SUPPORT__ACTIONS_DROPDOWN": "Toggle Dropdown",
"SUPPORT__SUPPORT": "Support",
"SUPPORT__SUBJECT": "Subject",
"SUPPORT__POST_A_TICKET": "Post a ticket",
"SUPPORT__AUTHOR": "Author",
"SUPPORT__STATE_TITLE": "State",
"SUPPORT__STATE_0": "Waiting",
"SUPPORT__STATE_1": "Answered",
"SUPPORT__STATE_2": "Clôs",
"SUPPORT__STATE_3": "Reopened",
"SUPPORT__CREATED": "Creation Date",
"SUPPORT__ACTIONS": "Options",
"SUPPORT__SHOW": "See",
"SUPPORT__CLOSE": "Close",
"SUPPORT__UNCLOSE": "Reopen",
"SUPPORT__DELETE": "Delete",
"SUPPORT__CLOSED": "Close",
"SUPPORT__MODIFY": "Edit",
"SUPPORT__EDIT": "Edit",
"SUPPORT__PROBLEMQUESTION": "Ticket n ° {ID_TICKET}",
"SUPPORT__CREATEDATE": "Sent the",
"SUPPORT__ANSWERTO": "Answer of",
"SUPPORT__ANSWER": "Answers",
"SUPPORT__REPLYTICKET": "Reply to the ticket",
"SUPPORT__REPLY": "Reply",
"SUPPORT_BACK_TO_LIST": "Back to the ticket list",
"SUPPORT__CLOSTICKETWARNING": "The ticket has been closed, so you can not answer anymore.",
"SUPPORT__CREATE": "Create a ticket",
"SUPPORT__CREATETITLE": "Creating a ticket",
"SUPPORT__YOURPROBLEM": "Your problem",
"SUPPORT__CREATETICKET": "Create ticket",
"SUPPORT__TICKETNUMBER": "Ticket N °",
"SUPPORT__SUCCESS_CREATE": "Ticket successfully created!",
"SUPPORT__SUCCESS_SEND_ANSWER": "Your reply has been sent successfully!",
"SUPPORT__SUCCESS_CLOSE": "The ticket has been closed successfully!",
"SUPPORT__SUCCESS_UNCLOSE": "The ticket has been opened successfully!",
"SUPPORT__SUCCESS_DELETE": "The ticket has been successfully deleted!",
"SUPPORT__ERROR_PROBLEM_SHORT": "The description of your problem is too short (50 characters minimum)",
"SUPPORT__ERROR_RESOLVE_EMPTY": "The description of your resolution is empty!",
"SUPPORT__GESTION_TICKETS": "Tickets management",
"SUPPORT__SETTINGS_TITLE": "Media Settings",
"SUPPORT__GESTION_CATEGORIES": "Category Management",
"SUPPORT__TICKET_NOT_EXIST": "The ticket seems to be non-existent!",
"SUPPORT__NOTIF_CREATE": "opened a ticket!",
"SUPPORT__NOTIF_ANSWER": "answered the ticket N °",
"SUPPORT__NOTIF_CLOS": "closed the ticket N °",
"SUPPORT__NOTIF_UNCLOS": "reopened the ticket N °",
"SUPPORT__ERROR_PERMISSION_ANSWER": "You do not have permission to reply to tickets.",
"SUPPORT__SHOW_EDIT": "View / modify answer suffix",

"SUPPORT__WARNING_ALERT": "Support Plugin | Information",
"SUPPORT__WARNING_ALERT_MAJ": "This update makes important changes in the source code and you may encounter internal errors.",
"SUPPORT__WARNING_ALERT_MAJ_MORE": "Remember to clear the cache properly by deleting the folder <b>app/tmp/cache</b>.",
"SUPPORT__TICKET_ETAT_LIST": "Ticket Status List",
"SUPPORT__TICKET_TITLE": "Tickets",
"SUPPORT__TICKET_NOTHING_ETAT": "No ticket is in the state",
"SUPPORT__ACTIONS_DROPDOWN": "Toggle Dropdown",

"SUPPORT__CATEGORY": "Category",
"SUPPORT__CATEGORIE": "Category",
"SUPPORT__CATEGORIE_EMPTY_NAME": "The category name must not be empty!",
"SUPPORT__CATEGORIE_ALREADY_EXIST": "The category {NAME} already exists!",
"SUPPORT__CATEGORIE_CREATE_SUCCESS": "The category {NAME} has been successfully created!",
"SUPPORT__CATEGORIE_EDIT_SUCCESS": "The {NAME} category has been successfully edited!",
"SUPPORT__CATEGORIE_DELETE_SUCCESS": "The category {NAME} has been successfully deleted!",
"SUPPORT__CATEGORIE_CREATE_BUTTON": "Create a category",
"SUPPORT__CATEGORIE_CREATE_TITLE": "Add a category",
"SUPPORT__CATEGORIE_NAME_OF_CATEGORIE": "Category Name",
"SUPPORT__CATEGORIE_CREATE_BUTTON": "Create category",
"SUPPORT__CATEGORIE_EDIT_TITLE": "Editing categories",
"SUPPORT__IN_A_CATEGORIE": "In category, {NAME}",
"SUPPORT__CATEGORIE": "Category",
"SUPPORT__CATEGORIE_EMPTY_NAME": "The category name must not be empty!",
"SUPPORT__CATEGORIE_ALREADY_EXIST": "The category {NAME} already exists!",
"SUPPORT__CATEGORIE_CREATE_SUCCESS": "The category {NAME} has been successfully created!",
"SUPPORT__CATEGORIE_EDIT_SUCCESS": "The {NAME} category has been successfully edited!",
"SUPPORT__CATEGORIE_DELETE_SUCCESS": "The category {NAME} has been successfully deleted!",
"SUPPORT__CATEGORIE_CREATE_BUTTON": "Create a category",
"SUPPORT__CATEGORIE_CREATE_TITLE": "Add a category",
"SUPPORT__CATEGORIE_NAME_OF_CATEGORIE": "Category Name",
"SUPPORT__CATEGORIE_EDIT_TITLE": "Editing categories",
"SUPPORT__IN_A_CATEGORIE": "In category, {NAME}",

"SUPPORT__SETTINGS_WEBHOOK": "Discord Webhook URL",
"SUPPORT__SETTINGS_SUCCESS_MODIFIED": "Settings successfully changed!",

"PERMISSIONS__MANAGE_TICKETS": "Manage support tickets",
"PERMISSIONS__VIEW_TICKETS": "View support tickets",
"PERMISSIONS__UNCLOSE_TICKETS": "Reopen support tickets",
"PERMISSIONS__CLOSE_TICKETS": "Close support tickets",
"PERMISSIONS__ANSWER_TICKETS": "Reply to support tickets",
"PERMISSIONS__ADD_CATEGORIE": "Create support categories",
"PERMISSIONS__DELETE_TICKETS": "Delete tickets from support",
"PERMISSIONS__MANAGE_CATEGORIES": "Manage support categories",
"PERMISSIONS__EDIT_CATEGORIE": "Edit Categories",
"PERMISSIONS__DELETE_CATEGORIE": "Delete support categories",
"PERMISSIONS__SETTINGS_SUPPORT": "Settings"
"SUPPORT__DISCORD_EMBED_CREATE_DESCRIPTION": "Sujet: {SUBJECT_NAME}\nCatégorie: {CATEGORIE_NAME}",

"PERMISSIONS__MANAGE_TICKETS": "Manage support tickets",
"PERMISSIONS__VIEW_TICKETS": "View support tickets",
"PERMISSIONS__UNCLOSE_TICKETS": "Reopen support tickets",
"PERMISSIONS__CLOSE_TICKETS": "Close support tickets",
"PERMISSIONS__ANSWER_TICKETS": "Reply to support tickets",
"PERMISSIONS__ADD_CATEGORIE": "Create support categories",
"PERMISSIONS__DELETE_TICKETS": "Delete tickets from support",
"PERMISSIONS__MANAGE_CATEGORIES": "Manage support categories",
"PERMISSIONS__EDIT_CATEGORIE": "Edit Categories",
"PERMISSIONS__DELETE_CATEGORIE": "Delete support categories",
"PERMISSIONS__SETTINGS_SUPPORT": "Settings"
}
6 changes: 4 additions & 2 deletions lang/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@
"SUPPORT__CATEGORIE_CREATE_BUTTON": "Créer une catégorie",
"SUPPORT__CATEGORIE_CREATE_TITLE": "Ajouter une catégorie",
"SUPPORT__CATEGORIE_NAME_OF_CATEGORIE": "Nom de la catégorie",
"SUPPORT__CATEGORIE_CREATE_BUTTON": "Créer la catégorie",
"SUPPORT__CATEGORIE_EDIT_TITLE": "Édition de la catégories",
"SUPPORT__IN_A_CATEGORIE": "Dans la catégorie, {NAME}",

"SUPPORT__SETTINGS_WEBHOOK": "URL du Webhook Discord",
"SUPPORT__SETTINGS_SUCCESS_MODIFIED": "Paramètres modifiés avec succès",

"SUPPORT__DISCORD_EMBED_CREATE_DESCRIPTION": "Sujet: {SUBJECT_NAME}\nCatégorie: {CATEGORIE_NAME}",

"PERMISSIONS__MANAGE_TICKETS": "Gérer les tickets du support",
"PERMISSIONS__VIEW_TICKETS": "Voir les tickets du support",
Expand All @@ -81,5 +84,4 @@
"PERMISSIONS__EDIT_CATEGORIE": "Éditer les catégories",
"PERMISSIONS__DELETE_CATEGORIE": "Supprimer les catégories du support",
"PERMISSIONS__SETTINGS_SUPPORT": "Paramètres du support"

}