Skip to content

Commit

Permalink
discord support
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Dec 3, 2023
1 parent 5a01214 commit 01ced57
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,35 @@ export function ticketRoutes(fastify: FastifyInstance) {

for (let i = 0; i < webhook.length; i++) {
if (webhook[i].active === true) {
console.log(webhook[i].url);
await axios.post(`${webhook[i].url}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
data: `Ticket ${ticket.id} created by ${ticket.name} -> ${ticket.email}. Priority -> ${ticket.priority}`,
}),
});
const url = webhook[i].url;
if (url.includes("discord.com")) {
console.log("discord");
const message = {
content: `Ticket ${ticket.id} created by ${ticket.name} -> ${ticket.email}. Priority -> ${ticket.priority}`,
avatar_url:
"https://avatars.githubusercontent.com/u/76014454?s=200&v=4",
username: "Peppermint.sh",
};
axios
.post(url, message)
.then((response) => {
console.log("Message sent successfully!");
console.log("Discord API response:", response.data);
})
.catch((error) => {
console.error("Error sending message:", error);
});
} else {
console.log("non discord");
await axios.post(`${webhook[i].url}`, {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
data: `Ticket ${ticket.id} created by ${ticket.name} -> ${ticket.email}. Priority -> ${ticket.priority}`,
}),
});
}
}
}

Expand Down

0 comments on commit 01ced57

Please sign in to comment.