fire-slack
v0.6.0
Published
Easy to send a slack notification for Cloud Functions.
Downloads
43
Maintainers
Readme
fire-slack
fire-slack is a library that makes it easy and convenient to send Slack's Incoming Webhook from Cloud Functions.
Feature
- Automatically add
project_id
. - Add a link url to firebase's database. (optional)
- Add a error message and change it to red color. (optional)
Like this gif, firebase's database can be opened.
Installation
npm install --save fire-slack
Usage
1. Initialize
Initialize fire-slack in your index.ts.
import * as Slack from 'fire-slack'
Slack.initialize(
<admin.AppOptions>functions.config().firebase,
'https://your-incoming-webhook-url',
{ channel: 'default_channel', iconEmoji: ':default:', username: 'default_usern' } // optional
)
2. Send to slack
For example, when an error occurs on Cloud Functions.
webhook
options are the same as options in Incoming webhook. See Incoming Webhooks | Slack or typed-slack.d.ts.
export const orderPaymentRequested = functions.firestore
.document(`sampleorder/{orderID}`).onCreate(async event => {
try {
return event.data.ref.update({ name: 'new name' })
} catch (error) {
// ref and error are optional.
await Slack.send({ webhook: { text: 'An error occurred!' }, ref: event.data.ref, error: error })
return Promise.reject(error)
}
})
result: