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

slack-topic-updater

v0.0.8

Published

Updates a Slack channel's topic, hiding the 'topic update' notice.

Downloads

6

Readme

Slack Topic Updater

Updates a Slack channel's topic, then 'hides' the topic update notice by deleting it afterwards. Useful for regular scripted updates of a channel's topic.

Why?

Updating a Slack channel topic is pretty simple. But, it leaves a message behind saying the topic has been updated. If you want to automate topic updates - for example, to use them as a 'ticker' of sorts - this can result in a lot of useless noise.

So, this module abstracts into one line the process of checking the current topic, querying the latest channel messages, and then deleting the topic update message. All this happens quite quickly, so no-one will notice the topic update message appearing unless they're watching quite intently!

As a bonus, the same topic text can be sent to multiple channels at the same time.

Usage

Add to your project:

npm install --save slack-topic-updater

Or if you use Yarn:

yarn add slack-topic-updater

Then, call like this:

const slackTopicUpdater = require('slack-topic-updater');

const response = await slackTopicUpdater.update({
  token: 'xoxp-0000000000-000000000000-000000000000-00000000000000000000000000000000',
  channel: 'C12345678',
  topic: 'This topic was last updated at ' + Date.now()
});

The response from Slack will be passed straight back through to you. In practice, this means that if response.ok is true, the actions have successfully completed.

Alternatively, you can instead pass an array of channel IDs as channels. If you do this, you'll also receive an array of Slack responses back - one for each channel.

const response = await slackTopicUpdater.update({
  token: 'xoxp-0000000000-000000000000-000000000000-00000000000000000000000000000000',
  channels: [
    'C12345678',
    'C98765432'
  ],
  topic: 'This topic was last updated at ' + Date.now()
});

Authorisation

To get your Slack token, create an app from api.slack.com/apps. After making it to the app management screen, from Features: OAuth & Permissions, and then under Scopes, you'll need to select:

  • channels:write (to set the topic);
  • channels:history (to search for the topic update message);
  • groups:write (to set the topic in private channels);
  • groups:history (to search for the topic update message in private channels); and
  • chat:write:user (to delete the topic update message).

NOTE: The private channel scopes are only required if you want to update the topic in private channels. If you'll only be using public channels, you should leave these scopes out. Also note that the app will only be able to access channels that you are in (this applies to both public and private channels).

Once you've added the scopes, follow the instructions under Settings: Install App. You should be provided with an OAuth Access Token, which is what you'll need to send through to this module. Bot user tokens are not supported by the channels.setTopic endpoint, so they can't be used here - you must use a user token instead.

Running Tests

npm test

or

yarn test

Problems?

Please feel free to log an issue, or - if you can solve a problem yourself - pull requests will be gladly accepted. If you add new functionality, please add tests to cover it.

If you are receiving errors from the Slack API, depending on the error ensure you have set up the correct scopes (documented under Authorisation above); provided the correct token; and are in the channel you are trying to update. API errors that indicate something is amiss here can include missing_scope, invalid_auth, not_in_channel, and channel_not_found.

License

MIT.