Skip to content

Instantly share code, notes, and snippets.

@alexjyong
Created December 21, 2022 21:23
Show Gist options
  • Save alexjyong/764a0751fc2c709eeb6e07299a56f5c3 to your computer and use it in GitHub Desktop.
Save alexjyong/764a0751fc2c709eeb6e07299a56f5c3 to your computer and use it in GitHub Desktop.
nodeJS slack talk example
//this uses node version 16.15.0
import { WebClient } from '@slack/web-api';
// An access token (from your Slack app or custom integration - xoxp, xoxb)
const token = "SuperSecretToken";
const web = new WebClient(token);
// This argument can be a channel ID, a DM ID, a MPDM ID, or a group ID
const conversationId = 'test123';
(async () => {
// See: https://api.slack.com/methods/chat.postMessage
const res = await web.chat.postMessage({ channel: conversationId, text: 'Check out this link: <https://www.example.com|Example>' });
// `res` contains information about the posted message
console.log('Message sent: ', res.ts);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment