Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(handleApiResponse)
.catch(handleApiError)
} else if (payload.event.text.match('42')) {
// use chat.postMessage over say method
slackWebApi.chat.postMessage({
channel: payload.event.channel,
text: 'The answer to life, the universe and everything',
thread_ts: payload.event.ts
})
.then(handleApiResponse)
.catch(handleApiError)
} else if (payload.event.text.match('webhook')) {
const url = process.env.SLACK_WEBHOOK_URL;
const webhook = new IncomingWebhook(url);
webhook.send({
text: payload.event.text.split("webhook")[1],
unfurl_links: true
})
.then((apiRes) => {
console.log(`Succeeded ${JSON.stringify(apiRes)}`)
}).catch(reason => {
console.error(`Failed because ${reason}`)
})
}
}
}
} else {
// application/x-www-form-urlencoded
const qs = require('querystring')
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"), (_a !== 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);
async function slackExecutor(
execOptions: ActionTypeExecutorOptions
): Promise {
const id = execOptions.id;
const secrets = execOptions.secrets as ActionTypeSecretsType;
const params = execOptions.params as ActionParamsType;
let result: IncomingWebhookResult;
const { webhookUrl } = secrets;
const { message } = params;
try {
const webhook = new IncomingWebhook(webhookUrl);
result = await webhook.send(message);
} catch (err) {
if (err.original == null || err.original.response == null) {
return errorResult(id, err.message);
}
const { status, statusText, headers } = err.original.response;
// special handling for 5xx
if (status >= 500) {
return retryResult(id, err.message);
}
// special handling for rate limiting
if (status === 429) {
return pipe(
app.message('webhook', ({ message }) => {
const { IncomingWebhook } = require('@slack/webhook');
const url = config.SLACK_WEBHOOK_URL;
const webhook = new IncomingWebhook(url);
webhook.send({
text: message.text.split("webhook")[1],
unfurl_links: true
})
.then((res) => {
console.log(`Succeeded ${JSON.stringify(res)}`)
}).catch(reason => {
console.error(`Failed because ${reason}`)
})
})
app.message('webhook', ({ message }) => {
const { IncomingWebhook } = require('@slack/webhook');
const url = process.env.SLACK_WEBHOOK_URL;
const webhook = new IncomingWebhook(url);
webhook.send({
text: message.text.split("webhook")[1],
unfurl_links: true
})
.then((res) => {
console.log(`Succeeded ${JSON.stringify(res)}`)
}).catch(reason => {
console.error(`Failed because ${reason}`)
})
})
exports.notifySlack = (msg) => {
const url = functions.config().slack_integration.webhook_url;
const webhook = new IncomingWebhook(url, {});
return webhook
.send({
text: msg,
})
.then(() => {
console.log('notification sent');
})
.catch((e) => {
console.log('error while posting to slack', e);
});
};
export function init() {
const slackUrl: string | undefined = process.env[env.SLACK_WEBHOOK_URL];
if (slackUrl) {
webhook = new IncomingWebhook(slackUrl);
}
}
"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 = core.getInput("message") ?? "티켓사세요";
const webhook = new IncomingWebhook(webhookUrl);
const res = await axios({
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,
}),
});
async function slackNotification({ status, slackWebhookUrl }) {
const conclusion = status === 0 ? 'success' : 'failure'
const webhook = new IncomingWebhook(slackWebhookUrl)
const color = status === 0 ? 'good' : 'danger'
/** @type {Buffer} */
const assertionResults = readFileSync(`${process.cwd()}/.lighthouseci/assertion-results.json`)
const groupedResults = groupBy(JSON.parse(assertionResults.toString()), 'url')
const attachments = Object.values(groupedResults).map(groupedResult => {
const results = groupedResult.map(
/**
* @param {{auditId: string, auditProperty: string, auditTitle: string, expected: string, operator: string, actual: string, url: string}} res
* @return {{title?: string, type: string, value: string, url: string}}
*/
res => ({
title: `${res.auditId}.${res.auditProperty}`,
value: `${res.auditTitle} \n _Expected ${res.expected} ${
res.operator === '<=' ? ' less then' : ' greater than'
const webhookInitialArguments = webhookInitialArgs({}, status);
const webhook = new IncomingWebhook(
SLACK_WEBHOOK_URL,
webhookInitialArguments
);
const reports = attachmentReports({
attachmentsReports: attachments,
status
});
const artefacts = attachementsVideoAndScreenshots(attachments, status);
const sendArguments = webhookSendArgs(sendArgs, [reports, artefacts]);
return webhook.send(sendArguments);
}
case "passed": {
const webhookInitialArguments = webhookInitialArgs({}, status);
const webhook = new IncomingWebhook(
SLACK_WEBHOOK_URL,
webhookInitialArguments
);
const reports = attachmentReports({
attachmentsReports: attachments,
status
});
const artefacts = attachementsVideoAndScreenshots(attachments, status);
const sendArguments = webhookSendArgs(sendArgs, [reports, artefacts]);
return webhook.send(sendArguments);
}
default: {
throw new Error("An error occured getting the status of the test run");
}
}
}