···
import { createHmac, timingSafeEqual } from "node:crypto";
-
import Bottleneck from "bottleneck";
-
* Interface for mapping emoji names to their URLs
* Configuration options for initializing the SlackWrapper
···
* @throws Error if authentication fails
async testAuth(): Promise<boolean> {
-
const response = await fetch("https://slack.com/api/auth.test", {
-
Authorization: `Bearer ${this.botToken}`,
-
"Content-Type": "application/json",
-
const data = await response.json();
throw new Error(`Authentication failed: ${data.error}`);
···
* @throws Error if the API request fails
async getUserInfo(userId: string): Promise<SlackUser> {
-
const response = await fetch(
-
`https://slack.com/api/users.info?user=${userId}`,
Authorization: `Bearer ${this.botToken}`,
"Content-Type": "application/json",
body: JSON.stringify({ user: userId }),
-
const data: SlackUserInfoResponse = await response.json();
if ((!data.ok && data.error !== "user_not_found") || !data.user) {
throw new Error(data.error);
···
* @throws Error if the API request fails
async getEmojiList(): Promise<Record<string, string>> {
-
const response = await fetch("https://slack.com/api/emoji.list", {
-
Authorization: `Bearer ${this.botToken}`,
-
"Content-Type": "application/json",
-
const data: SlackEmojiListResponse = await response.json();
if (!data.ok || !data.emoji) {
throw new Error(`Failed to get emoji list: ${data.error}`);
···
const hmac = createHmac("sha256", this.signingSecret);
const computedSignature = `v0=${hmac.update(baseString).digest("hex")}`;
-
Buffer.from(signature).valueOf() as Uint8Array,
-
Buffer.from(computedSignature).valueOf() as Uint8Array,
···
import { createHmac, timingSafeEqual } from "node:crypto";
+
import Bottleneck from "bottleneck";
* Configuration options for initializing the SlackWrapper
···
* @throws Error if authentication fails
async testAuth(): Promise<boolean> {
+
const response = await this.limiter.schedule(() =>
+
fetch("https://slack.com/api/auth.test", {
+
Authorization: `Bearer ${this.botToken}`,
+
"Content-Type": "application/json",
+
const data = (await response.json()) as {
throw new Error(`Authentication failed: ${data.error}`);
···
* @throws Error if the API request fails
async getUserInfo(userId: string): Promise<SlackUser> {
+
const response = await this.limiter.schedule(() =>
+
fetch(`https://slack.com/api/users.info?user=${userId}`, {
Authorization: `Bearer ${this.botToken}`,
"Content-Type": "application/json",
body: JSON.stringify({ user: userId }),
+
const data = (await response.json()) as SlackUserInfoResponse;
if ((!data.ok && data.error !== "user_not_found") || !data.user) {
throw new Error(data.error);
···
* @throws Error if the API request fails
async getEmojiList(): Promise<Record<string, string>> {
+
const response = await this.limiter.schedule(() =>
+
fetch("https://slack.com/api/emoji.list", {
+
Authorization: `Bearer ${this.botToken}`,
+
"Content-Type": "application/json",
+
const data = (await response.json()) as SlackEmojiListResponse;
if (!data.ok || !data.emoji) {
throw new Error(`Failed to get emoji list: ${data.error}`);
···
const hmac = createHmac("sha256", this.signingSecret);
const computedSignature = `v0=${hmac.update(baseString).digest("hex")}`;
+
new Uint8Array(Buffer.from(signature)),
+
new Uint8Array(Buffer.from(computedSignature)),