This repository was archived by the owner on May 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWebhook.prompt.ts
96 lines (89 loc) · 3.12 KB
/
Webhook.prompt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* eslint-disable no-case-declarations */
import Logger from "../../Lib/Logger";
import prompt from "prompt";
import ConfigModel from "../../Database/Models/Configs.model";
export default
{
name: 'Webhooks',
description: 'Get all webhook jobs',
args: [
{
name: 'action',
type: "list",
message: "Select the webhook job you want to run",
choices: [
{
name: 'Show webhooks',
value: 'show_webhooks',
},
{
name: 'Add webhook',
value: 'add_webhook',
},
{
name: 'Delete webhook',
value: 'delete_webhook',
}
],
}
],
method: async ({action}: {action: string}) =>
{
switch(action)
{
case 'show_webhooks':
return new Promise(async (resolve) =>
{
// Get our config from database
const config = (await ConfigModel.find())[0];
Logger.info(`Webhooks:`, config.webhooks_urls);
resolve(true);
});
case 'add_email':
return new Promise((resolve) =>
{
prompt.get([
{
name: "url",
description: "URL for webhook",
required: true
},
], async (err, result) =>
{
const url = result.url as string;
Logger.info(`Adding webhook..`);
// Get our config from database
const config = (await ConfigModel.find())[0];
// Add webhook
config.webhooks_urls.push(url);
// Save our config
await config.save();
return resolve(true)
});
});
case 'delete_email':
return new Promise((resolve) =>
{
prompt.get([
{
name: "url",
description: "URL for webhook",
required: true
},
], async (err, result) =>
{
const url = result.url as string;
Logger.info(`Deleting webhook..`);
// Get our config from database
const config = (await ConfigModel.find())[0];
// Remove webhook
config.webhooks_urls = config.webhooks_urls.filter((e: any) => e !== url);
// Save our config
await config.save();
return resolve(true)
});
});
}
return true;
}
}