Commit 43875f1c by Lin Wang

feat: send message to the slack channel

parent 14dc04f9
...@@ -4,16 +4,12 @@ import { basename } from 'path'; ...@@ -4,16 +4,12 @@ import { basename } from 'path';
export async function sendSlackMessage(webhookUrl: string, params: { export async function sendSlackMessage(webhookUrl: string, params: {
issue: string, issue: string,
displayName: string, details?: string,
language: string,
siteEditor: string
}) { }) {
const text = [ const parts: string[] = [];
`Issue: ${params.issue}`, parts.push(`Issue: ${params.issue}`);
`Display Name: ${params.displayName}`, if (params.details) parts.push(`Details: ${params.details}`);
`Language: ${params.language}`, const text = parts.join('\n');
`Site editor: ${params.siteEditor}`
].join('\n');
const res = await fetch(webhookUrl, { const res = await fetch(webhookUrl, {
method: "POST", method: "POST",
...@@ -50,12 +46,4 @@ export async function sendSlackFile( ...@@ -50,12 +46,4 @@ export async function sendSlackFile(
if (!response.ok) { if (!response.ok) {
throw new Error(`Slack 文件上传失败: ${response.error}`); throw new Error(`Slack 文件上传失败: ${response.error}`);
} }
} }
\ No newline at end of file
// 示例用法
// sendSlackMessage('https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX', {
// issue: 'Theme color missing',
// displayName: 'Lavender',
// language: 'en',
// siteEditor: 'https://www.strikingly.com/s/sites/12572142/edit'
// });
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { google } from 'googleapis'; import { google } from 'googleapis';
import { readdirSync, readFileSync } from 'fs'; import { readdirSync, readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { sendSlackMessage } from '../clients/slack';
async function uploadAllToSheets() { async function uploadAllToSheets() {
const useAiSelectors = process.env.USE_AI_SELECTORS === 'true'; const useAiSelectors = process.env.USE_AI_SELECTORS === 'true';
...@@ -61,7 +62,24 @@ async function uploadAllToSheets() { ...@@ -61,7 +62,24 @@ async function uploadAllToSheets() {
} }
} }
uploadAllToSheets().catch(err => { async function notifySlack() {
console.error('Error uploading to Google Sheets:', err); const webhookUrl = process.env.SLACK_WEBHOOK!;
process.exit(1); const nonAiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_ID}/edit`;
}); const aiUrl = `https://docs.google.com/spreadsheets/d/${process.env.GOOGLE_SHEET_AI_ID}/edit`;
await sendSlackMessage(webhookUrl, {
issue: 'Inconsistencies are detected in i18n master section template',
details: `Google Sheet Links:\n- Non-AI selectors: ${nonAiUrl}\n- AI selectors: ${aiUrl}`
});
}
async function main() {
try {
await uploadAllToSheets();
await notifySlack();
} catch (err) {
console.error('Error in task:gsheet workflow:', err);
process.exit(1);
}
}
main();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment