UNPKG

3.56 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2017 Atomist, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27const decorators_1 = require("@atomist/automation-client/decorators");
28const HandlerResult_1 = require("@atomist/automation-client/HandlerResult");
29const Handlers_1 = require("@atomist/automation-client/Handlers");
30const logger_1 = require("@atomist/automation-client/internal/util/logger");
31let HelloWorld = class HelloWorld {
32 handle(ctx) {
33 logger_1.logger.info(`incoming parameter was ${this.name}`);
34 if (!ctx.graphClient) {
35 return Promise.resolve(HandlerResult_1.Success);
36 }
37 return ctx.graphClient.executeFile("graphql/person", { teamId: ctx.teamId, slackUser: this.slackUser })
38 .then(result => {
39 if (result && result.ChatTeam && result.ChatTeam[0] && result.ChatTeam[0].members &&
40 result.ChatTeam[0].members[0] && result.ChatTeam[0].members[0].person) {
41 return result.ChatTeam[0].members[0].person;
42 }
43 else {
44 return null;
45 }
46 })
47 .then(person => {
48 if (person) {
49 return ctx.messageClient.respond(`Hello ${this.name} from ${person.forename} ${person.surname}`);
50 }
51 else {
52 return ctx.messageClient.respond(`Hello ${this.name}`);
53 }
54 })
55 .then(() => {
56 return HandlerResult_1.Success;
57 });
58 }
59};
60__decorate([
61 Handlers_1.Parameter({
62 displayName: "Name",
63 description: "name of person to say hello to",
64 pattern: /^.+$/,
65 validInput: "a single line of text",
66 minLength: 1,
67 maxLength: 100,
68 required: true,
69 }),
70 __metadata("design:type", String)
71], HelloWorld.prototype, "name", void 0);
72__decorate([
73 decorators_1.MappedParameter(Handlers_1.MappedParameters.SlackUserName),
74 __metadata("design:type", String)
75], HelloWorld.prototype, "slackUser", void 0);
76HelloWorld = __decorate([
77 Handlers_1.CommandHandler("sends a hello back to the channel", "hello world"),
78 Handlers_1.Tags("hello")
79], HelloWorld);
80exports.HelloWorld = HelloWorld;
81//# sourceMappingURL=HelloWorld.js.map
\No newline at end of file