Created
August 26, 2021 01:20
-
-
Save wktq/c2da999c47da8dab718c8f9b621f7990 to your computer and use it in GitHub Desktop.
Notionのkanbanから日報をSlackに自動投稿
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Client } = require("@notionhq/client"); | |
const { WebClient } = require("@slack/web-api"); | |
const notion = new Client({ | |
auth: "secret_YOUR_NOTION_TOKEN_HERE", | |
}); | |
const completedTaskTitles = []; | |
const todoTaskTitles = []; | |
(async () => { | |
const databaseId = "173e71d900e2449aa4d498daf8425fb3"; | |
const responseCompleted = await notion.databases.query({ | |
database_id: databaseId, | |
filter: { | |
and: [ | |
{ | |
property: "Status", | |
select: { | |
equals: "完了", | |
}, | |
}, | |
{ | |
property: "プロジェクト", | |
multi_select: { | |
contains: "207inc", | |
}, | |
}, | |
], | |
}, | |
sorts: [ | |
{ | |
timestamp: "last_edited_time", | |
direction: "ascending", | |
}, | |
], | |
}); | |
const responseTodo = await notion.databases.query({ | |
database_id: databaseId, | |
filter: { | |
or: [ | |
{ | |
and: [ | |
{ | |
property: "Status", | |
select: { | |
equals: "本日対応", | |
}, | |
}, | |
{ | |
property: "プロジェクト", | |
multi_select: { | |
contains: "207inc", | |
}, | |
}, | |
], | |
}, | |
{ | |
and: [ | |
{ | |
property: "Status", | |
select: { | |
equals: "対応中", | |
}, | |
}, | |
{ | |
property: "プロジェクト", | |
multi_select: { | |
contains: "207inc", | |
}, | |
}, | |
], | |
}, | |
], | |
}, | |
sorts: [ | |
{ | |
timestamp: "last_edited_time", | |
direction: "ascending", | |
}, | |
], | |
}); | |
await Promise.all( | |
responseCompleted.results.map(async (page) => { | |
const pageId = page.id; | |
const response = await notion.pages.retrieve({ page_id: pageId }); | |
completedTaskTitles.push(response.properties.Name.title[0].plain_text); | |
}) | |
); | |
await Promise.all( | |
responseTodo.results.map(async (page) => { | |
const pageId = page.id; | |
const response = await notion.pages.retrieve({ page_id: pageId }); | |
todoTaskTitles.push(response.properties.Name.title[0].plain_text); | |
}) | |
); | |
const token = "YOUR_SLACK_BOT_TOKEN_HERE"; | |
const channel = "#times-titch"; | |
const today = new Date(); | |
const month = today.getMonth() + 1; | |
const week = today.getDay(); | |
const day = today.getDate(); | |
const yobi = new Array("日", "月", "火", "水", "木", "金", "土"); | |
let text = "*" + month + "月" + day + "日 " + yobi[week] + "曜日 日報*\n\n"; | |
text = text + "✅ やった\n"; | |
completedTaskTitles.map((completedTaskTitle) => { | |
text = text + '• ' + completedTaskTitle + "\n"; | |
}); | |
text = text + "\n 💪 やる\n"; | |
todoTaskTitles.map((todoTaskTitle) => { | |
text = text + "• " + todoTaskTitle + "\n"; | |
}); | |
const client = new WebClient(token); | |
const params = { | |
channel: channel, | |
blocks: [ | |
{ | |
type: "section", | |
text: { | |
type: "mrkdwn", | |
text: text, | |
}, | |
}, | |
], | |
}; | |
const slackResponse = await client.chat.postMessage(params); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment