fire-slack
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

fire-slack npm version Build Status Codacy Badge License: MIT

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:

Package Sidebar

Install

npm i fire-slack

Weekly Downloads

8

Version

0.6.0

License

MIT

Unpacked Size

2.78 MB

Total Files

14

Last publish

Collaborators

  • star__hoshi