1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | const decorators_1 = require("@atomist/automation-client/decorators");
|
28 | const HandlerResult_1 = require("@atomist/automation-client/HandlerResult");
|
29 | const Handlers_1 = require("@atomist/automation-client/Handlers");
|
30 | const logger_1 = require("@atomist/automation-client/internal/util/logger");
|
31 | let 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);
|
76 | HelloWorld = __decorate([
|
77 | Handlers_1.CommandHandler("sends a hello back to the channel", "hello world"),
|
78 | Handlers_1.Tags("hello")
|
79 | ], HelloWorld);
|
80 | exports.HelloWorld = HelloWorld;
|
81 |
|
\ | No newline at end of file |