@atomist/automation-client
Version:
Atomist API for software low-level client
86 lines • 3.59 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const string_1 = require("../../internal/util/string");
const GraphClient_1 = require("../graph/GraphClient");
const MessageClient_1 = require("./MessageClient");
class MessageClientSupport {
respond(msg, options) {
return this.doSend(msg, [], options);
}
send(msg, destinations, options) {
const dests = (Array.isArray(destinations)) ? destinations : [destinations];
return this.doSend(msg, dests, options);
}
}
exports.MessageClientSupport = MessageClientSupport;
exports.Query = `
query ChatTeam {
ChatTeam {
id
}
}`;
class DefaultSlackMessageClient {
constructor(delegate, graphClient) {
this.delegate = delegate;
this.graphClient = graphClient;
}
respond(msg, options) {
return this.delegate.respond(msg, options);
}
send(msg, destinations, options) {
return this.delegate.send(msg, destinations, options);
}
delete(destinations, options) {
return __awaiter(this, void 0, void 0, function* () {
return this.delegate.delete(destinations, options);
});
}
addressUsers(msg, users, options) {
if (!users || (Array.isArray(users) && users.length === 0)) {
throw new Error("Please pass at least one user");
}
return lookupChatTeam(this.graphClient)
.then(chatTeamId => this.delegate.send(msg, MessageClient_1.addressSlackUsers(chatTeamId, ...string_1.toStringArray(users)), options));
}
addressChannels(msg, channels, options) {
if (!channels || (Array.isArray(channels) && channels.length === 0)) {
throw new Error("Please pass at least one channel");
}
return lookupChatTeam(this.graphClient)
.then(chatTeamId => this.delegate.send(msg, MessageClient_1.addressSlackChannels(chatTeamId, ...string_1.toStringArray(channels)), options));
}
}
exports.DefaultSlackMessageClient = DefaultSlackMessageClient;
function lookupChatTeam(graphClient) {
if (graphClient) {
return graphClient.query({
query: exports.Query,
variables: {},
options: GraphClient_1.QueryNoCacheOptions,
})
.then(result => {
if (result.ChatTeam && result.ChatTeam.length !== 1) {
return Promise.reject("More then one or no ChatTeam found. Please use fully qualified " +
"message addressing available on MessageClient");
}
else {
return result.ChatTeam[0].id;
}
});
}
else {
return Promise.reject("No GraphClient to lookup ChatTeam. Please use fully qualified message " +
"addressing available on MessageClient");
}
}
exports.lookupChatTeam = lookupChatTeam;
//# sourceMappingURL=MessageClientSupport.js.map