Skip to content

Commit 0f66e3e

Browse files
authored
chore(billing): migrate deprecated slack package to @slack/web-api (#4281)
* chore(billing): migrate deprecated slack package to @slack/web-api * fix(billing): update node engine to >=18.0.0 for slack web-api compatibility * refactor: rename web variable to slackClient
1 parent 6a530b5 commit 0f66e3e

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

functions/billing/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ const PROJECT_NAME = `projects/${PROJECT_ID}`;
2323
// [END functions_billing_limit]
2424

2525
// [START functions_billing_slack]
26-
const slack = require('slack');
26+
const {WebClient} = require('@slack/web-api');
2727

2828
// TODO(developer) replace these with your own values
2929
const BOT_ACCESS_TOKEN =
3030
process.env.BOT_ACCESS_TOKEN || 'xxxx-111111111111-abcdefghidklmnopq';
3131
const CHANNEL = process.env.SLACK_CHANNEL || 'general';
32+
const slackClient = new WebClient(BOT_ACCESS_TOKEN);
3233

3334
exports.notifySlack = async pubsubEvent => {
3435
const pubsubAttrs = pubsubEvent.attributes;
@@ -37,8 +38,7 @@ exports.notifySlack = async pubsubEvent => {
3738
pubsubAttrs
3839
)}, ${pubsubData}`;
3940

40-
await slack.chat.postMessage({
41-
token: BOT_ACCESS_TOKEN,
41+
await slackClient.chat.postMessage({
4242
channel: CHANNEL,
4343
text: budgetNotificationText,
4444
});

functions/billing/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Examples of integrating Cloud Functions with billing",
66
"main": "index.js",
77
"engines": {
8-
"node": ">=16.0.0"
8+
"node": ">=18.0.0"
99
},
1010
"scripts": {
1111
"compute-test": "c8 mocha -p -j 2 test/periodic.test.js --timeout=600000",
@@ -16,9 +16,9 @@
1616
"dependencies": {
1717
"@google-cloud/billing": "^4.0.0",
1818
"@google-cloud/compute": "^4.0.0",
19+
"@slack/web-api": "^7.15.0",
1920
"google-auth-library": "^9.0.0",
20-
"googleapis": "^143.0.0",
21-
"slack": "^11.0.1"
21+
"googleapis": "^143.0.0"
2222
},
2323
"devDependencies": {
2424
"@google-cloud/functions-framework": "^3.0.0",

0 commit comments

Comments
 (0)