npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@apigrate/slack

v4.0.1

Published

Convenience logger for transactional logging to Slack using inbound webhooks.

Downloads

17

Readme

apigrate-slack

A simple utility to post messages to Slack using inbound webhooks. Useful for logging transactions to a channel where others can see the messages and take action if needed.

Usage

Instantiation

var webhook = 'your inbound webhook here';

var slack_logger = new SlackLogger(webhook,
  "test environment",
  "SlackLogger Test"
);

In the above simple example, the username for each slack entry will be 'test environment' and the author will be "SlackLogger Test". By convention, we use username to store our environment or host name and use the author to identify the app making the logging call from that environment. You are, of course, free to implement your own conventions.

Here is a more detailed instantiation that includes additional information to be recorded on every logging call.

var webhook = 'your inbound webhook here';

var slack_logger = new SlackLogger(webhook,
  "test environment",
  "Invoice Integration",
  {
    author_url: "http://documentation.about.invoice.integration",
    fields: {
      account_id: 24601,
      environment: "test"
    }
  }
);

In this case, account_id and environment fields will be added to the slack message on every log entry. The "Invoice Integration" author will be hyperlinked as well with the value of author_url. This is a nice way to tie documentation together with your log entries, or to hyperlink to an app that is logging activity.

Logging

Each log message must have the following parameters:

  1. true/false indicating success or failure
  2. the log message (i.e. a summary)
  3. a more detailed message (optional). This could be log details, stack trace or other detailed information for the message (typically more useful to provide troubleshooting info on errors).

Here's how to post a simple "success" message.

slack_logger.log(
  true,
  'That worked.'
);

It is possible include more detail in log messages. Provide a more detailed message (up to 7500 characters) if you like. Note that this detailed message will be formatted in fixed-font code block immediately following the summary message for readability (newline characters are respected by Slack in the formatting). Additionally, the fields parameter allows you to specify additional data that may be helpful for reporting or troubleshooting on specific log messages.

slack_logger.log(
  true,
  'Invoice Created.',
  'Found customer.\nThere are 3 invoice lines.\nThe total amount is $107.80',
  {
    customer_id: 28390,
    invoice_id: 123789
  }
);

Error log messages (as shown below) are more useful when they include detailed information to allow consumers to troubleshoot more effectively.

slack_logger.log(
  false,
  'Invoice creation failed.',
  'Found customer.\nException processing invoice lines.\nThe quantity is missing for the line with product 1234879.',
  {
    customer_id: 28390,
    product_id: 1234879,
    product_sku: 'TS4921'
  }
);