@synonymdev/blocktank-util-slack-client
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

blocktank-util-slack-client

NPM version

Client to interact with the blocktank-util-slack service.

Usage

Send message

import { SlackClient } from '@synonymdev/blocktank-util-slack-client';

const client = new SlackClient('myConfiguredChannelName') // See service config for channel names.

await client.info('myTitle', 'myMessage') // Send message.

If the channel name is empty, the message will be logged to the console instead of sent to slack.

Rate limiting

Messages can be ratelimited to not overwhelm the channel. The rate limit is based on a key. If the key was already seen within the limitFor duration, the message will be ignored.

interface RateLimitOptions {
    // Key of the operation that will be rate limited. Example: `blocktank-instant:funds-are-low`.
    key: string,
    // Duration of the rate limit until the next message can be sent.
    limitFor: Duration
}

// Amount of time the limit should be applied for this key.
interface Duration {
    years?: number;
    months?: number;
    weeks?: number;
    days?: number;
    hours?: number;
    minutes?: number;
    seconds?: number;
}

Let's make an example:

await client.error('Couldnt read file', 'errorMessage', {
    key: 'blocktank-ls-btc:fileReadKey',
    limitFor: {
        hours: 1
    }
})

This will send a message with the level error and the title Couldnt read file.
The message will be sent only if the last message with the key blocktank-ls-btc:fileReadKey was sent more than 1 hour ago. If the last message was sent less than 1 hour ago, the message will be ignored.

Emojis used

SlackMessageLevel Emoji
debug
success
info ℹ️
notice 📢
warning ⚠️
error
critical ‼️
alert 🚨
emergency 🆘

Test messages

Execute npx blocktank-util-slack-cli in the terminal to send test messages. Make sure you install this package first.

Versioning

  1. Increase version in package.json.
  2. Add changes to CHANGELOG.md.
  3. Commit changes.
  4. Tag new version: git tag v0.1.0.
  5. Push tag git push origin v0.1.0.
  6. Publish to npm: npm publish.

/@synonymdev/blocktank-util-slack-client/

    Package Sidebar

    Install

    npm i @synonymdev/blocktank-util-slack-client

    Weekly Downloads

    72

    Version

    0.1.5

    License

    MIT

    Unpacked Size

    41 kB

    Total Files

    37

    Last publish

    Collaborators

    • shacollision
    • dzdidi_restored
    • sebubu
    • coreyphillips
    • jayvdb