2020-07-17 20:07:32 +09:00
|
|
|
const { promisify } = require("util");
|
|
|
|
const { App, ExpressReceiver } = require("@slack/bolt");
|
2019-07-28 01:52:06 +09:00
|
|
|
const daraz = require("./");
|
2019-07-27 01:30:19 +09:00
|
|
|
|
2020-07-17 20:07:32 +09:00
|
|
|
class Receiver extends ExpressReceiver {
|
|
|
|
/**
|
|
|
|
* @param {import("express").Request} req
|
|
|
|
* @param {import("express").Response} res
|
|
|
|
*/
|
|
|
|
requestHandler(req, res) {
|
|
|
|
// NOTE: See also https://api.slack.com/events-api#errors
|
|
|
|
res.header("x-slack-no-retry", "1");
|
|
|
|
if (req.headers["x-slack-retry-reason"] === "http_timeout")
|
|
|
|
return promisify(res.end)();
|
|
|
|
|
|
|
|
return super.requestHandler(req, res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const receiver = new Receiver({
|
|
|
|
signingSecret: process.env.SLACK_SIGNING_SECRET,
|
|
|
|
});
|
|
|
|
|
2019-07-28 01:52:06 +09:00
|
|
|
const app = daraz(
|
|
|
|
new App({
|
|
|
|
token: process.env.SLACK_BOT_TOKEN,
|
2020-07-17 20:07:32 +09:00
|
|
|
receiver,
|
2019-07-28 01:52:06 +09:00
|
|
|
})
|
|
|
|
);
|
2019-07-27 01:30:19 +09:00
|
|
|
|
|
|
|
(async () => {
|
2019-07-30 09:23:20 +09:00
|
|
|
await app.start(process.env.PORT || 8080);
|
2019-07-27 01:30:19 +09:00
|
|
|
console.log("Daraz-san ⚡ running");
|
|
|
|
})();
|