UNPKG

@microfox/slack

Version:

This package provides a lightweight, proxy interface to the official Slack Web API, offering a curated set of the most commonly used functions for building Slack integrations. It is designed to be simple, efficient, and easy to integrate into your project

208 lines (207 loc) 5.8 kB
// src/index.ts export * from "@slack/web-api"; // src/MicrofoxSlackClient.ts import { WebClient } from "@slack/web-api"; var MicrofoxSlackClient = class { constructor(token, options) { this.web = new WebClient(token, options); } /** * Lists all public and private channels in a workspace. */ async listChannels() { const result = await this.web.conversations.list({ types: "public_channel,private_channel" }); return result.channels; } /** * Fetches information about a conversation. * @param channelId Conversation ID to fetch information for. */ async getChannelConversationInfo(channelId) { const result = await this.web.conversations.info({ channel: channelId }); return result.channel; } /** * Lists all users in a workspace. */ async listUsers() { const result = await this.web.users.list({ limit: 1e3 }); return result.members; } /** * Lists all users in a channel. * @param channelId Channel ID to get members of. */ async listChannelUsers(channelId) { const result = await this.web.conversations.members({ channel: channelId }); return result.members; } /** * Finds a user by their email address. * @param email The email address of the user to find. */ async searchUser(email) { const result = await this.web.users.lookupByEmail({ email }); return result.user; } /** * Finds a channel by its name. This is case-insensitive. * @param name The name of the channel to find. */ async searchChannel(name) { const channels = await this.listChannels(); return channels == null ? void 0 : channels.find((c) => { var _a; return ((_a = c.name) == null ? void 0 : _a.toLowerCase()) === name.toLowerCase(); }); } /** * Sends a direct message to a user. * @param userId The ID of the user to message. * @param text The text of the message to send. */ async messageUser(userId, text) { var _a; const im = await this.web.conversations.open({ users: userId }); if (im.ok && ((_a = im.channel) == null ? void 0 : _a.id)) { return this.web.chat.postMessage({ channel: im.channel.id, text }); } throw new Error(`Could not open DM with user ${userId}`); } /** * Sends a message to a channel. * @param channelId The ID of the channel to message. * @param text The text of the message to send. */ async messageChannel(channelId, text) { return this.web.chat.postMessage({ channel: channelId, text }); } /** * Sets a reminder for a user. * @param userId The ID of the user to set a reminder for. * @param text The text of the reminder. * @param time A string describing when the reminder should fire (e.g., "in 5 minutes" or a Unix timestamp). */ async setReminder(userId, text, time) { return this.web.reminders.add({ user: userId, text, time }); } /** * Creates a new channel. * @param name The name of the channel to create. * @param isPrivate Whether the channel should be private. Defaults to false. */ async createChannel(name, isPrivate = false) { const result = await this.web.conversations.create({ name, is_private: isPrivate }); return result.channel; } /** * Adds a reaction to a message. * @param channelId The ID of the channel where the message is. * @param timestamp The timestamp of the message to react to. * @param reaction The name of the emoji to use for the reaction. */ async reactMessage(channelId, timestamp, reaction) { return this.web.reactions.add({ channel: channelId, timestamp, name: reaction }); } /** * Gets information about a user. * @param userId The ID of the user to get information for. */ async getUserInfo(userId) { const result = await this.web.users.info({ user: userId }); return result.user; } /** * Replies to a message in a thread. * @param channelId The ID of the channel where the message is. * @param thread_ts The timestamp of the message to reply to, establishing the thread. * @param text The text of the reply. */ async replyMessage(channelId, thread_ts, text) { return this.web.chat.postMessage({ channel: channelId, thread_ts, text }); } /** * Adds a user to a channel. * @param channelId The ID of the channel to add the user to. * @param userId The ID of the user to add. */ async addUserToChannel(channelId, userId) { return this.web.conversations.invite({ channel: channelId, users: userId }); } /** * Removes a user from a channel. * @param channelId The ID of the channel to remove the user from. * @param userId The ID of the user to remove. */ async removeUserFromChannel(channelId, userId) { return this.web.conversations.kick({ channel: channelId, user: userId }); } /** * Uploads a file to a channel. * @param channelId The ID of the channel to upload the file to. Can be a comma-separated list of strings. * @param file A Buffer containing the file content. * @param filename The name of the file. * @param title An optional title for the file. */ async sendFile(channelId, file, filename, title) { return this.web.files.upload({ channels: channelId, file, filename, title }); } /** * Gets information about a file. * @param fileId The ID of the file to get information for. */ async getFileInfo(fileId) { const result = await this.web.files.info({ file: fileId }); return result.file; } }; export { MicrofoxSlackClient }; //# sourceMappingURL=index.mjs.map