์์ค์ฝ๋
require('dotenv').config()
const { App } = require('@slack/bolt');
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
port: process.env.PORT || 3000
});
app.command('/์ ์ฐ', async ({ ack, body, client, logger }) => {
await ack();
try {
const result = await client.views.open({
trigger_id: body.trigger_id,
view: {
"type": "modal",
"callback_id": "split_view",
"title": {
"type": "plain_text",
"text": "์ ์ฐ๋์ฐ๋ฏธ",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "input",
"block_id": "description",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action",
"placeholder": {
"type": "plain_text",
"text": "๋ฌด์์ ๋ํ ์ ์ฐ์ธ๊ฐ์?"
},
},
"label": {
"type": "plain_text",
"text": "ํญ๋ชฉ",
"emoji": true
}
},
{
"type": "input",
"block_id": "total",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action",
"placeholder": {
"type": "plain_text",
"text": "์ด ๊ธ์ก์ ์ผ๋ง์ธ๊ฐ์?"
},
},
"label": {
"type": "plain_text",
"text": "์ด ๊ธ์ก",
"emoji": true
}
},
{
"type": "input",
"block_id": "account_info",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action",
"placeholder": {
"type": "plain_text",
"text": "์ํ๋ช
๊ณผ ๊ณ์ข๋ฒํธ"
},
},
"label": {
"type": "plain_text",
"text": "์ํ๋ช
๊ณผ ๊ณ์ข๋ฒํธ",
"emoji": true
}
},
{
"type": "input",
"block_id": "subjects",
"element": {
"type": "multi_users_select",
"placeholder": {
"type": "plain_text",
"text": "๋์์ ์ ํํด์ฃผ์ธ์ (๋ณธ์ธ์ ํฌํจํ์ง ๋ง์์ฃผ์ธ์)",
"emoji": true
},
"action_id": "multi_users_select-action"
},
"label": {
"type": "plain_text",
"text": "๋์ (๋ณธ์ธ ๋ฏธํฌํจ ์ ์์ ์ ํํด์ฃผ์ธ์)",
"emoji": true
}
}
]
}
})
}
catch (error) {
logger.error(error);
}
});
app.view('split_view', async ({ ack, body, view, client, logger }) => {
await ack();
const user = body.user.id;
const total = view.state.values.total["plain_text_input-action"].value
const subjects = view.state.values.subjects["multi_users_select-action"].selected_users
const amountDue = total / (subjects.length + 1)
console.log(total, amountDue)
try {
Promise.all(subjects.map(sub => {
return client.chat.postMessage({
channel: sub,
"attachments": [
{
"color": "#f2c744",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "๐ค ์๋ก์ด ์ ์ฐ ์์ฒญ",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*ํญ๋ชฉ*: ์ ์ฌ ๋ฒํ
์ค"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*๋์*: <@${user}>`
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*๊ณ์ข*: ์นด๋ฑ
3333-06-12345"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*๊ธ์ก*: ${amountDue.toLocaleString()}์`
}
}
]
}
]
})
}))
}
catch (error) {
logger.error(error);
}
});
(async () => {
await app.start();
console.log('Bolt app is running');
})();