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-qna-node

v1.2.5

Published

An easy plug-and-use library for developing Slack BOT that serves a Q&A-like use case.

Downloads

368

Readme

Slack Q&A

An easy plug-and-use library for developing Slack BOT that serves a Q&A-like use case.

For Python version, please see https://github.com/lokwkin/slack-qna-python

Description

High level flow:

  1. User messages this BOT via either:
    1. Direct Message
    2. Mention in Channel
    3. Slack Command
  2. The BOT shows a loading reaction to the message.
  3. The BOT relays user's message to your custom handler, and expect for a result either in Text, File or Image type.
  4. The BOT reply the user's message in Slack Thread.
  5. The BOT also shows a success reaction to the message.

Note:

  • This BOT uses Slack's Socket Mode instead of Webhook mode for slack connection, so it does not require an exposed public endpoint. But your services need to be long running.

Sample use cases

Use with ChatGPT (Text Response)

Loading
Reply

Use with Dall-E (Image Response)

Loading
Reply

Usage

Install

npm install --save slack-qna-node
import { SlackQna, IncomingMessage } from 'slack-qna-node';

const slackQnABot = new SlackQna({_
    slackBotToken: '<SLACK_BOT_TOKEN>',
    slackAppToken: '<SLACK_APP_TOKEN>',
    botUserId: '<SLACK_BOT_USER_ID>'
});

slackQnABot.registerHandler({
  isSync: true,         // If isSync = true, it would reply the user with the handler function result.
                        // If isSync = false, you would need to call slackQnABot.postMessage(OutgoingMessage) on your own.
  dataType: 'image',    // Expected output. Can either be "text", "file" or "image"
  handler: async (message: IncomingMessage) => {
    // Your logic goes here.
    return 'Hi there';
  },
});

slackAdapter.listen({
  directMessage: true,
  mention: true,
  command: true
});

Slack Setup

  1. Register an Slack App in portal https://api.slack.com/
  2. "Socket Mode" -> Enable Socket Mode
  3. "OAuth & Permissions" -> "Bot Token Scopes" -> Grant these permissions: app_mentions:read, channels:history, chat:write, im:history, im:write, reactions:write, groups:history, files:write
  4. "Event Subscription" -> "Enable Event" -> "Subscribe to bot events" -> Add message.im and app_mention --> "save"
  5. "App Home" -> "Message Tab" -> Enable "Allow users to send Slash commands and messages from the messages tab"
  6. Install bot to your workspace
  7. Obtain your Bot Token from "OAuth & Permissions" > "Bot User OAuth Token"
  8. Obtain your App Token from "Basic Information" > "App Level Token"
  9. "Install App" -> Reinstall to workspace if neccessary