{"library":"slack-node","title":"Slack Node.js SDK","description":"slack-node is a Node.js library for interacting with the Slack API, supporting both incoming webhooks and the comprehensive Slack Web API. Currently at version 0.3.2, it maintains a policy of zero runtime dependencies, making it a lightweight choice for integrating Slack functionalities into Node.js applications. The library is designed for flexibility, offering both traditional callback-based asynchronous operations and modern Promise-based and async/await syntax, catering to various coding styles. While its version number suggests a pre-1.0 stability, the project claims continuous updates and full feature support. Its core differentiation lies in its minimalist approach to dependencies and its dual API consumption models.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install slack-node"],"cli":null},"imports":["const Slack = require('slack-node');","const slack = new Slack();\nslack.setWebhook('__your_webhook_url__');","const slack = new Slack('__your_api_token__');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const Slack = require('slack-node');\n\nasync function main() {\n  // Webhook usage\n  const webhookUrl = process.env.SLACK_WEBHOOK_URL ?? '__your_webhook_url__';\n  const slackWebhook = new Slack();\n  slackWebhook.setWebhook(webhookUrl);\n\n  if (webhookUrl === '__your_webhook_url__') {\n    console.warn(\"Please provide a valid SLACK_WEBHOOK_URL environment variable or replace the placeholder.\");\n  } else {\n    try {\n      const webhookResponse = await slackWebhook.webhook({\n        channel: \"#general\",\n        username: \"webhookbot\",\n        text: \"Hello from async/await via webhook!\",\n        icon_emoji: \":ghost:\"\n      });\n      console.log(\"Webhook message sent:\", webhookResponse.data);\n    } catch (err) {\n      console.error(\"Webhook error:\", err);\n    }\n  }\n\n  // API usage\n  const apiToken = process.env.SLACK_API_TOKEN ?? '__your_api_token__';\n  if (apiToken === '__your_api_token__') {\n    console.warn(\"Please provide a valid SLACK_API_TOKEN environment variable or replace the placeholder.\");\n  } else {\n    const slackApi = new Slack(apiToken);\n    try {\n      const usersList = await slackApi.api(\"users.list\");\n      console.log(\"Users list:\", usersList.members.map(u => u.real_name));\n\n      const chatPostMessage = await slackApi.api(\"chat.postMessage\", {\n        text: \"hello from async/await via API\",\n        channel: \"#general\"\n      });\n      console.log(\"API message sent (timestamp):\", chatPostMessage.ts);\n    } catch (err) {\n      console.error(\"API error:\", err);\n    }\n  }\n}\n\nmain();","lang":"javascript","description":"Demonstrates sending a message via an Incoming Webhook and calling a Slack Web API method (users.list and chat.postMessage) using `async/await` syntax, utilizing environment variables for credentials.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}