Files
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

254 lines
8.4 KiB
TypeScript

// This is a JS File that was renamed to TS so it won't lose its git history when converted to TS
// TODO: Remove the following lint/ts instructions when the file gets properly converted
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
// @ts-nocheck
import { serverFetch as fetch } from '@rocket.chat/server-fetch';
export class SlackAPI {
constructor(apiOrBotToken) {
this.token = apiOrBotToken;
}
async getChannels(cursor = null) {
let channels = [];
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/conversations.list', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
types: 'public_channel',
exclude_archived: true,
limit: 1000,
...(cursor && { cursor }),
},
});
const response = await request.json();
if (response && response && Array.isArray(response.channels) && response.channels.length > 0) {
channels = channels.concat(response.channels);
if (response.response_metadata?.next_cursor) {
const nextChannels = await this.getChannels(response.response_metadata.next_cursor);
channels = channels.concat(nextChannels);
}
}
return channels;
}
async getGroups(cursor = null) {
let groups = [];
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/conversations.list', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
types: 'private_channel',
exclude_archived: true,
limit: 1000,
...(cursor && { cursor }),
},
});
const response = await request.json();
if (response && response && Array.isArray(response.channels) && response.channels.length > 0) {
groups = groups.concat(response.channels);
if (response.response_metadata?.next_cursor) {
const nextGroups = await this.getGroups(response.response_metadata.next_cursor);
groups = groups.concat(nextGroups);
}
}
return groups;
}
async getRoomInfo(roomId) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch(`https://slack.com/api/conversations.info`, {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
channel: roomId,
include_num_members: true,
},
});
const response = await request.json();
return response && response && request.status === 200 && request.ok && response.channel;
}
async getMembers(channelId) {
const { num_members } = this.getRoomInfo(channelId);
const MAX_MEMBERS_PER_CALL = 100;
let members = [];
let currentCursor = '';
for (let index = 0; index < num_members; index += MAX_MEMBERS_PER_CALL) {
const request = await fetch('https://slack.com/api/conversations.members', {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
channel: channelId,
limit: MAX_MEMBERS_PER_CALL,
...(currentCursor && { cursor: currentCursor }),
},
});
const response = await request.json();
if (response && response && request.status === 200 && request.ok && Array.isArray(response.members)) {
members = members.concat(response.members);
const hasMoreItems = response.response_metadata?.next_cursor;
if (hasMoreItems) {
currentCursor = response.response_metadata.next_cursor;
}
}
}
return members;
}
async react(data) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/reactions.add', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
const response = await request.json();
return response && request.status === 200 && response && request.ok;
}
async removeReaction(data) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/reactions.remove', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
const response = await request.json();
return response && request.status === 200 && response && request.ok;
}
async removeMessage(data) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/chat.delete', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
const response = await request.json();
return response && request.status === 200 && response && request.ok;
}
async sendMessage(data) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/chat.postMessage', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
return request.json();
}
async updateMessage(data) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/chat.update', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
method: 'POST',
params: data,
});
const response = await request.json();
return response && request.status === 200 && response && request.ok;
}
async getHistory(options) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch(`https://slack.com/api/conversations.history`, {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
params: options,
});
const response = await request.json();
return response;
}
async getPins(channelId) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/pins.list', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
channel: channelId,
},
});
const response = await request.json();
return response && response && request.status === 200 && request.ok && response.items;
}
async getUser(userId) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/users.info', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${this.token}`,
},
params: {
user: userId,
},
});
const response = await request.json();
return response && response && request.status === 200 && request.ok && response.user;
}
static async verifyToken(token) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/auth.test', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${token}`,
},
method: 'POST',
});
const response = await request.json();
return response && response && request.status === 200 && request.ok && response.ok;
}
static async verifyAppCredentials({ botToken, appToken }) {
// SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check.
const request = await fetch('https://slack.com/api/apps.connections.open', {
ignoreSsrfValidation: true,
headers: {
Authorization: `Bearer ${appToken}`,
},
method: 'POST',
});
const response = await request.json();
const isAppTokenOk = response && response && request.status === 200 && request.ok && response.ok;
const isBotTokenOk = await this.verifyToken(botToken);
return isAppTokenOk && isBotTokenOk;
}
}