import { EventFired, HandlerContext, HandlerResult, Maker, ProjectOperationCredentials } from "@atomist/automation-client"; import { HandleEvent } from "@atomist/automation-client/lib/HandleEvent"; import { CredentialsResolver, ParametersDefinition } from "@atomist/sdm"; import { Action, SlackMessage } from "@atomist/slack-messages"; import { Action as CardAction, CardMessage } from "./card"; export interface LifecycleParametersDefinition { orgToken: string; credentialsResolver?: CredentialsResolver; } export declare const LifecycleParameters: ParametersDefinition; export declare function lifecycle(e: EventFired, params: LifecycleParametersDefinition, ctx: HandlerContext, maker: Maker>): Promise; export declare function resolveEventHandlerCredentials(e: EventFired, params: LifecycleParametersDefinition, ctx: HandlerContext): Promise; /** * Base Event Handler implementation that handles rendering of lifecycle messages. */ export declare abstract class LifecycleHandler implements HandleEvent { orgToken: string; credentials: ProjectOperationCredentials; defaultConfigurations: any; handle(event: EventFired, ctx: HandlerContext): Promise; protected processLifecycle(lifecycle: Lifecycle, store: Map): Lifecycle; protected abstract extractPreferences(event: EventFired): { [teamId: string]: Preferences[]; }; /** * Extension point to configure nodes and rendering of those nodes for a given path expression match. * @param event the cortex event the path expression matched */ protected abstract prepareLifecycle(event: EventFired, ctx: HandlerContext): Lifecycle[]; /** * Extension point to create an empty starting point for the lifecycle message. * @returns {any} */ protected abstract prepareMessage(lifecycle: Lifecycle, ctx: HandlerContext): Promise; private prepareConfiguration; private createAndSendMessage; private sendCard; private sendMessage; private lifecycleEnabled; /** * Clean up the list of channels; look for channels that can be processed together as they don't have * any configuration. */ private groupChannels; private channelConfigured; private normalizeTimestamp; private configureContributors; private configureRenderers; private filterAndSortContributions; } export interface LifecycleConfiguration { renderers: string[]; contributors: string[]; configuration: any; } export interface ChatTeam { id: string; preferences: Preferences[]; } export interface Preferences { name?: string; value?: string; } export interface Channel { name: string; teamId: string; } /** * Returned by LifecycleHandler.prepareLifecycle in order to link path expressions matches up with * NodeRenderer and ActionContributor. */ export interface Lifecycle { /** * The name of the lifecycle */ name: string; /** * The id to be used to identify the lifecycle message in Slack. * Only lifecycle messages with matching ids are being overwritten. */ id: string; /** * Timestamp of the lifecycle message. This is used to drop out-of-order messages. */ timestamp: string; /** * Timestamp after which message should be re-written. */ ttl?: string; /** * Indicate if this message should only be an update to an existing message */ post?: "update_only" | "always"; /** * The channels the lifecycle message should be send to. */ channels: Channel[]; /** * The cortex nodes that should be rendered. * The order of the nodes in the returned array determines the rendering order: the first node * in the array will be passed to the NodeRenderes first, etc. */ nodes: any[]; /** * The NodeRenderers to use for rendering. * The order of renderers in the returned array determines the rendering order. */ renderers: Array>; /** * The ActionContributor to use for adding buttons to messages. */ contributors?: Array>; /** * The NodeExtractor to help extract nodes from the root */ extract: (type: string) => any; } export interface IdentifiableContribution { /** * Unique id of this renderer */ id(): string; /** * Configure the contributions with the provided configuration * @param {LifecycleConfiguration} config */ configure?(config: LifecycleConfiguration): void; } /** * A NodeRenderer is responsible to render a given and supported cortex node into the provided * SlackMessage. */ export interface NodeRenderer extends IdentifiableContribution { /** * Indicate if a NodeRenderer supports a provided cortex node. */ supports(node: T): boolean; /** * Render the given node and actions into the given SlackMessage. */ render(node: T, actions: A[], msg: M, context: RendererContext): Promise; } export interface SlackNodeRenderer extends NodeRenderer { } export interface CardNodeRenderer extends NodeRenderer { } /** * A ActionContributor can add one or multiple buttons/actions for a given cortex node. */ export interface ActionContributor extends IdentifiableContribution { /** * Indicate if a ActionContributor supports a provided cortex node. */ supports(node: any, context: RendererContext): boolean; /** * Create buttons for the provided node. */ buttonsFor(node: T, context: RendererContext): Promise; /** * Create menus for the provided node. */ menusFor(node: T, context: RendererContext): Promise; } export interface SlackActionContributor extends ActionContributor { } export interface CardActionContributor extends ActionContributor { } export declare class RendererContext { rendererId: string; lifecycle: Lifecycle; configuration: LifecycleConfiguration; credentials: ProjectOperationCredentials; context: HandlerContext; channels: { teamId: string; channels: string[]; }; private readonly store; constructor(rendererId: string, lifecycle: Lifecycle, configuration: LifecycleConfiguration, credentials: ProjectOperationCredentials, context: HandlerContext, channels: { teamId: string; channels: string[]; }, store: Map); set(key: string, value: any): void; get(key: string): any; has(key: string): boolean; } export declare abstract class AbstractIdentifiableContribution implements IdentifiableContribution { private readonly _id; constructor(_id: string); id(): string; } export declare class CardActionContributorWrapper implements CardActionContributor { private readonly delegate; constructor(delegate: SlackActionContributor); supports(node: any, context: RendererContext): boolean; buttonsFor(node: any, context: RendererContext): Promise; menusFor(node: any, context: RendererContext): Promise; id(): string; configure?(configuration: LifecycleConfiguration): void; }