forked from mooyoul/melon-ticket-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (49 loc) · 1.57 KB
/
index.js
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const webhook_1 = require("@slack/webhook");
const axios_1 = require("axios");
const qs = require("querystring");
(async () => {
var _a;
// Validate parameters
const [productId, scheduleId, seatId, webhookUrl] = [
"product-id",
"schedule-id",
"seat-id",
"slack-incoming-webhook-url",
].map((name) => {
const value = core.getInput(name);
if (!value) {
throw new Error(`melon-ticket-actions: Please set ${name} input parameter`);
}
return value;
});
const message = (_a = core.getInput("message")) !== null && _a !== void 0 ? _a : "티켓사세요";
const webhook = new webhook_1.IncomingWebhook(webhookUrl);
const res = await axios_1.default({
method: "POST",
url: "https://ticket.melon.com/tktapi/product/seatStateInfo.json",
params: {
v: "1",
},
data: qs.stringify({
prodId: productId,
scheduleNo: scheduleId,
seatId,
volume: 1,
selectedGradeVolume: 1,
}),
});
// tslint:disable-next-line
console.log("Got response: ", res.data);
if (res.data.chkResult) {
const link = `http://ticket.melon.com/performance/index.htm?${qs.stringify({
prodId: productId,
})}`;
await webhook.send(`${message} ${link}`);
}
})().catch((e) => {
console.error(e.stack); // tslint:disable-line
core.setFailed(e.message);
});