cusdis icon indicating copy to clipboard operation
cusdis copied to clipboard

discord webhook?

Open milindpatel63 opened this issue 2 years ago • 4 comments

any way to use discord webhook url to get comments approval in discord channel?

milindpatel63 avatar Nov 25 '21 10:11 milindpatel63

You can make your own webhook: https://cusdis.com/doc#/advanced/webhook

But we didn't provide an official webhook service yet

djyde avatar Nov 25 '21 10:11 djyde

I copied the discord webhook url in cusdis, but it doesn't work. Do you have any instructions on how to do it?

milindpatel63 avatar Nov 25 '21 11:11 milindpatel63

I copied the discord webhook url in cusdis, but it doesn't work. Do you have any instructions on how to do it?

What webhook url? We only provide Telegram webhook for now.

djyde avatar Nov 25 '21 11:11 djyde

I managed to set up Discord webhooks by modifying the service/webhook.service.ts file. Comment out the axios.post and create a new one following Discord's format. I used Discohook to help build the embed fields.

diff --git a/service/webhook.service.ts b/service/webhook.service.ts
index 3a77b29..d3b245f 100644
--- a/service/webhook.service.ts
+++ b/service/webhook.service.ts
@@ -64,6 +64,7 @@ export class WebhookService extends RequestScopeService {
       })
 
       try {
+        /*
         axios.post(project.webhook, {
           type: HookType.NewComment,
           data: {
@@ -76,6 +77,21 @@ export class WebhookService extends RequestScopeService {
             approve_link: approveLink,
           },
         } as HookBody<NewCommentHookData>)
+        */
+
+        axios.post(project.webhook, {
+          "content": comment.content.substr(0, 1500),
+          "username": comment.by_nickname,
+          "embeds": [
+            {
+              "color": null,
+              "fields": [
+                { "name": "Post", "value": fullComment.page.title },
+                { "name": "Links", "value": `[Approve](${approveLink})` }
+              ]
+            }
+          ]
+        });
       } catch (e) {
         
       }

hizkifw avatar Jan 11 '22 11:01 hizkifw