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

happner-slack

v0.1.1

Published

happner slack integration

Downloads

8

Readme

npm Build Status

happner-slack

In progress.

Currently implements only /commands and webhook integrations from/to slack.

  • The /commands allow commands entered on slack to run mesh exchange methods that reply back to slack.
  • The webhook allows for the mesh to post messages to slack.

Todo

  • Security solution. Command calls from slack are relayed by a middleware function which means the actual exchange calls are secondary/internal calls run as admin. It would be nice if the team-domains/users from slack could be integrated with/mapped to happn users.
  • Support multiple (named) webhooks.

Setup in mesh

NB: slack requires https server with """valid""" cert (not self-signed)

...
components: {
  'happner-slack': {
    $configure: function (defaultConfig) {
      var config = defaultConfig.component.config;
      
      // supports multiple tokens so that multiple slack commands can post here
      config.command.tokens.push('SLACKTOKEN1');
      config.command.tokens.push('SLACKTOKEN2');
      
      // note: if process.env.SLACK_COMMAND_TOKENS = 'token1,token2,...'
      //       then those will be pre-loaded into defaultConfig
      
      config.webhook.url = 'https://hooks.slack.com/services/.../.../...'
      
      return defaultConfig;
    }
  },
  'componentName': {
    // another component (that happner-slack relays /commands to)
  }
},
...

Setup on slack

Create any number of /command integrations in slack resulting approximately as follows:

slack command image

  • Note that the component/method to run is encoded into the command's post url.
  • Contained in each command setup is a token that should go into the mesh config described above.

Create a webhook integration in slack resulting approximately as follows:

slack webhook image

  • Contained in the slack setup is a url that should go into the mesh config described above.
  • Note that although the happner-slack component supports only one webhook config, messages can be posted to any (public) channel in the team-domain using the same webhook.

(missing images? see github readme)

Slack compatible exchange methods

In the above setup, execution of /some-command in slack will call exchange.componentName.methodName(payload, callback) with the command payload as follows:

{
  team_id: "...",
  team_domain: "...",
  channel_id: "...",
  channel_name: "...",
  user_id: "...",
  user_name: "...",
  command: "/some-command",
  text: "additional parameters as text"
}

It is up to exchange.componentName.methodName(payload, callback) to callback with a slack compatible response as follows:

callback(null, {
  // response_type: "ephemeral", // only caller sees command response
  response_type: "in_channel", // everybody sees command response
  text: "Some response text.",
  attachments: [
    {
      text: "Additional text."
    }
  ]
});

Posting messages to slack using the webhook

Post messages from other mesh components via $happn.exchange.

var message = {
  text: "Some text",
  // channel: "#general", // post to alternative (public) channel in the team-domain
  // username: "bob the bot", // post as alternative user
  // icon_emoji: ":earth_africa:" // post with alternative icon
}

$happn.exchange['happner-slack'].post(message)  
  .then(function() {
    // success
  })
  .catch(function(error) {
    // failed
    
    // response from slack if "Error: slack api error"
    // error.statusCode
    // error.body
  });

slack message formatting emoji_icons