diff --git a/functions/billing/index.js b/functions/billing/index.js index 38d3bdfe5a..c99b222e25 100644 --- a/functions/billing/index.js +++ b/functions/billing/index.js @@ -23,13 +23,15 @@ const PROJECT_NAME = `projects/${PROJECT_ID}`; // [END functions_billing_limit] // [START functions_billing_slack] -const slack = require('slack'); +const {WebClient} = require('@slack/web-api'); // TODO(developer) replace these with your own values const BOT_ACCESS_TOKEN = process.env.BOT_ACCESS_TOKEN || 'xxxx-111111111111-abcdefghidklmnopq'; const CHANNEL = process.env.SLACK_CHANNEL || 'general'; +const slackClient = new WebClient(BOT_ACCESS_TOKEN); + exports.notifySlack = async pubsubEvent => { const pubsubAttrs = pubsubEvent.attributes; const pubsubData = Buffer.from(pubsubEvent.data, 'base64').toString(); @@ -37,13 +39,16 @@ exports.notifySlack = async pubsubEvent => { pubsubAttrs )}, ${pubsubData}`; - await slack.chat.postMessage({ - token: BOT_ACCESS_TOKEN, - channel: CHANNEL, - text: budgetNotificationText, - }); - - return 'Slack notification sent successfully'; + try { + await slackClient.chat.postMessage({ + channel: CHANNEL, + text: budgetNotificationText, + }); + return 'Slack notification sent successfully'; + } catch (error) { + console.error('Error sending Slack message:', error); + throw error; + } }; // [END functions_billing_slack] diff --git a/functions/billing/package.json b/functions/billing/package.json index 0c59d6c3e9..7417efc7bc 100644 --- a/functions/billing/package.json +++ b/functions/billing/package.json @@ -16,9 +16,9 @@ "dependencies": { "@google-cloud/billing": "^4.0.0", "@google-cloud/compute": "^4.0.0", + "@slack/web-api": "^7.9.1", "google-auth-library": "^9.0.0", - "googleapis": "^143.0.0", - "slack": "^11.0.1" + "googleapis": "^143.0.0" }, "devDependencies": { "@google-cloud/functions-framework": "^3.0.0",