Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private createRtmClient(token: string, logLabel: string): RTMClient {
const LOG_LEVELS = ["debug", "info", "warn", "error", "silent"];
const connLog = Logging.get(`RTM-${logLabel.substr(0, LOG_TEAM_LEN)}`);
const logLevel = LOG_LEVELS.indexOf(this.main.config.rtm!.log_level || "silent");
const rtm = new RTMClient(token, {
logLevel: LogLevel.DEBUG, // We will filter this ourselves.
logger: {
getLevel: () => LogLevel.DEBUG,
setLevel: () => {},
setName: () => {}, // We handle both of these ourselves.
debug: logLevel <= 0 ? connLog.debug.bind(connLog) : () => {},
warn: logLevel <= 1 ? connLog.warn.bind(connLog) : () => {},
info: logLevel <= 2 ? connLog.info.bind(connLog) : () => {},
error: logLevel <= 3 ? connLog.error.bind(connLog) : () => {},
} as Logger,
});
rtm.on("error", (error) => {
// We must handle this lest the process be killed.
connLog.error("Encountered 'error' event:", error);
});
const { RTMClient } = require('@slack/rtm-api');
const { WebClient, retryPolicies } = require('@slack/web-api');
const Queue = require('smart-request-balancer');
const memoize = require('memoizee');
const Logger = require('../includes/logger.js');
const DB = require('./db.js');
const { PRIVATE_TEST_CHANNELS } = require('../consts.js');
const { SLACK_BOT_TOKEN, SLACK_USER_TOKEN } = process.env;
const RTM = new RTMClient(SLACK_BOT_TOKEN);
const PR_REGEX = /github\.com\/([\w-.]*)?\/([\w-.]*?)\/pull\/(\d+)/i;
const PR_REGEX_GLOBAL = new RegExp(PR_REGEX.source, `${PR_REGEX.flags}g`);
const user_client = new WebClient(SLACK_USER_TOKEN, {
retryConfig: retryPolicies.rapidRetryPolicy,
});
const bot_client = new WebClient(SLACK_BOT_TOKEN, {
retryConfig: retryPolicies.rapidRetryPolicy,
});
exports.bot_client = bot_client;
exports.user_client = user_client;
const balancer = new Queue({
rules: {
createRtmRuntime(): void {
const rtm = new RTMClient(this._accessToken);
const handler = this.createRequestHandler();
rtm.on('message', handler);
rtm.start();
}
}