slack-webhook-alias
Version:
Slack Webhook Library with alias for sending Slack notifications to multiple channels
57 lines (56 loc) • 2.44 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
class SlackBot {
constructor(aliases, disabled) {
this.disabled = false;
this.createBot = (alias) => {
const send = (object) => __awaiter(this, void 0, void 0, function* () {
if (!this.disabled)
this.send(this._aliases[alias], object);
});
const sendText = (text) => __awaiter(this, void 0, void 0, function* () {
if (!this.disabled)
this.sendText(this._aliases[alias], text);
});
const sendForce = (object) => __awaiter(this, void 0, void 0, function* () {
this.send(this._aliases[alias], object);
});
const sendTextForce = (text) => __awaiter(this, void 0, void 0, function* () {
this.sendText(this._aliases[alias], text);
});
return {
send,
sendText,
sendForce,
sendTextForce
};
};
this._aliases = aliases;
if (disabled)
this.disabled = disabled;
}
send(alias, object) {
return __awaiter(this, void 0, void 0, function* () {
return axios_1.default.post(this._aliases[alias], object);
});
}
sendText(alias, text) {
return __awaiter(this, void 0, void 0, function* () {
return axios_1.default.post(this._aliases[alias], { text });
});
}
}
exports.default = SlackBot;