Skip to content

Commit

Permalink
get message sending working from web ui
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Sep 20, 2017
1 parent 24ad097 commit 48556df
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atomist/automation-client",
"version": "0.1.2",
"version": "0.1.3",
"description": "Atomist automation client for running command and event handlers",
"author": "Atomist, Inc.",
"license": "GPL-3.0",
Expand Down
37 changes: 22 additions & 15 deletions src/automationClient.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Configuration } from "./configuration";
import { HandleCommand } from "./HandleCommand";
import { HandleEvent } from "./HandleEvent";
import { AutomationEventListener } from "./internal/transport/AutomationEventListener";
import { ExpressServer, ExpressServerOptions } from "./internal/transport/express/ExpressServer";
import { WebSocketClient, WebSocketClientOptions } from "./internal/transport/websocket/WebSocketClient";
import { BuildableAutomationServer } from "./server/BuildableAutomationServer";

import { Configuration } from "./configuration";
import {
DefaultExpressAutomationEventListener,
} from "./internal/transport/express/DefaultExpressAutomationEventListener";
import { DefaultWebSocketAutomationEventListener,
} from "./internal/transport/websocket/DefaultWebSocketAutomationEventListener";
import { prepareRegistration } from "./internal/transport/websocket/Payloads";
import { WebSocketAutomationEventListener } from "./internal/transport/websocket/WebSocketAutomationEventListener";
import { WebSocketClient, WebSocketClientOptions } from "./internal/transport/websocket/WebSocketClient";
import { logger } from "./internal/util/logger";
import { AutomationServer } from "./server/AutomationServer";
import { BuildableAutomationServer } from "./server/BuildableAutomationServer";

export const DefaultStagingAtomistServer =
"https://automation-staging.atomist.services/registration";
Expand Down Expand Up @@ -60,23 +58,33 @@ export class AutomationClient {

public run(): Promise<any> {
logger.info(`Starting Atomist automation client for ${this.configuration.name}@${this.configuration.version}`);
const listeners = this.setupEventListeners();
const options: WebSocketClientOptions = {
graphUrl: DefaultStagingAtomistGraphQLServer,
registrationUrl: DefaultStagingAtomistServer,
token: this.configuration.token,
};
return Promise.all([
Promise.resolve(this.runWs()),
Promise.resolve(this.runHttp()),
Promise.resolve(this.runWs(listeners, options)),
Promise.resolve(this.runHttp(listeners)),
]);
}

private runWs(): void {
private setupEventListeners(): WebSocketAutomationEventListener[] {
const webSocketOptions: WebSocketClientOptions = {
graphUrl: DefaultStagingAtomistGraphQLServer,
registrationUrl: DefaultStagingAtomistServer,
token: this.configuration.token,
};
this.webSocketClient = new WebSocketClient(() => prepareRegistration(this.automations.rugs), webSocketOptions,
[new DefaultWebSocketAutomationEventListener(this.automations, webSocketOptions)]);
return [new DefaultWebSocketAutomationEventListener(this.automations, webSocketOptions)];
}

private runWs(listeners: WebSocketAutomationEventListener[], options: WebSocketClientOptions): void {
this.webSocketClient = new WebSocketClient(() => prepareRegistration(this.automations.rugs), options,
listeners );
}

private runHttp(): void {
private runHttp(listeners: AutomationEventListener[]): void {
const http = this.configuration.http;
this.httpPort = http && http.port ? http.port : (process.env.PORT ? +process.env.PORT : 2866);
const expressOptions: ExpressServerOptions = {
Expand Down Expand Up @@ -111,8 +119,7 @@ export class AutomationClient {
}
}
if (!http || http.enabled) {
this.httpServer = new ExpressServer(this.automations, expressOptions,
[new DefaultExpressAutomationEventListener(this.automations)]);
this.httpServer = new ExpressServer(this.automations, expressOptions, listeners);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/transport/express/ExpressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class ExpressServer {
rug: {},
mapped_parameters: undefined,
secrets: undefined,
correlation_context: [],
correlation_context: {team: { id: this.automations.rugs.team_id }},
corrid: guid(),
team: {
id: this.automations.rugs.team_id,
Expand Down
3 changes: 3 additions & 0 deletions src/internal/transport/websocket/WebSocketMessageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export abstract class AbstractWebSocketMessageClient extends MessageClientSuppor
constructor(private automations: AutomationServer, private ws: WebSocket, private correlationId: string,
private correlationContext: any, private rug: any = {}) {
super();
if (!correlationContext) {
this.correlationContext = { team: { id: automations.rugs.team_id }};
}
}

protected async doSend(msg: string | SlackMessage, userNames: string | string[],
Expand Down
5 changes: 1 addition & 4 deletions test/command/HelloWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export class HelloWorld implements HandleCommand {
@Parameter({pattern: /^.*$/})
public name: string;

@Secret(Secrets.USER_TOKEN)
public userToken: string;

public handle(ctx: HandlerContext): Promise<HandlerResult> {
logger.info(`Incoming parameter was ${this.name}`);

Expand All @@ -31,7 +28,7 @@ export class HelloWorld implements HandleCommand {
}],
};

ctx.messageClient.recordAddressUsers(msg, "cd", { id: "new/cd/test" });
ctx.messageClient.recordAddressUsers(msg, "cd");
// .recordRespond(`Hello ${this.name}`)
// .recordRespond(msg)
// .recordAddressChannels(msg, "general");
Expand Down

0 comments on commit 48556df

Please sign in to comment.