UNPKG

7.14 kBTypeScriptView Raw
1import { SlackMessage } from "@atomist/slack-messages";
2import { Action as SlackAction } from "@atomist/slack-messages/lib/SlackMessages";
3import { GraphQLClient } from "./graphql";
4import { CommandContext, EventContext, HandlerStatus } from "./handler";
5import { CommandIncoming, EventIncoming, Skill, Source } from "./payload";
6export interface Destinations {
7 users: string | string[];
8 channels: string | string[];
9}
10export interface MessageClient {
11 send(msg: any, destinations: Destinations, options?: MessageOptions): Promise<any>;
12 delete?(destinations: Destinations, options: RequiredMessageOptions): Promise<void>;
13}
14export interface CommandMessageClient extends MessageClient {
15 respond(msg: any, options?: MessageOptions): Promise<any>;
16}
17export declare type RequiredMessageOptions = Pick<MessageOptions, "id" | "thread"> & {
18 id: string;
19};
20/**
21 * Options for sending messages using the MessageClient.
22 */
23export interface MessageOptions extends Record<string, any> {
24 /**
25 * Unique message id per channel and team. This is required
26 * if you wish to re-write a message at a later time.
27 */
28 id?: string;
29 /**
30 * Time to live for a posted message. If ts + ttl of the
31 * existing message with ts is < as a new incoming message
32 * with the same id, the message will be re-written.
33 */
34 ttl?: number;
35 /**
36 * Timestamp of the message. The timestamp needs to be
37 * sortable lexicographically. Should be in milliseconds and
38 * defaults to Date.now().
39 *
40 * This is only applicable if id is set too.
41 */
42 ts?: number;
43 /**
44 * If update_only is given, this message will only be posted
45 * if a previous message with the same id exists.
46 */
47 post?: "update_only" | "always";
48 /**
49 * Optional thread identifier to send this message to or true to send
50 * this to the message that triggered this command.
51 */
52 thread?: string | boolean;
53}
54/** Valid MessageClient types. */
55export declare const MessageMimeTypes: {
56 SLACK_JSON: string;
57 SLACK_FILE_JSON: string;
58 PLAIN_TEXT: string;
59 APPLICATION_JSON: string;
60};
61export declare abstract class MessageClientSupport implements MessageClient, CommandMessageClient {
62 respond(msg: any, options?: MessageOptions): Promise<any>;
63 send(msg: any, destinations: Destinations, options?: MessageOptions): Promise<any>;
64 abstract delete(destinations: Destinations, options: RequiredMessageOptions): Promise<void>;
65 protected abstract doSend(msg: any, destinations: Destinations, options?: MessageOptions): Promise<any>;
66}
67export declare abstract class AbstractMessageClient extends MessageClientSupport {
68 protected readonly request: CommandIncoming | EventIncoming;
69 protected readonly correlationId: string;
70 protected readonly team: {
71 id: string;
72 name?: string;
73 };
74 protected readonly source: Source;
75 protected readonly graphClient: GraphQLClient;
76 constructor(request: CommandIncoming | EventIncoming, correlationId: string, team: {
77 id: string;
78 name?: string;
79 }, source: Source, graphClient: GraphQLClient);
80 delete(destinations: Destinations, options: RequiredMessageOptions): Promise<void>;
81 protected doSend(msg: any, destinations: Destinations, options?: MessageOptions): Promise<any>;
82 protected abstract sendResponse(response: any): Promise<void>;
83 private ts;
84 private getTeamId;
85}
86export interface CommandReferencingAction extends SlackAction {
87 command: CommandReference;
88}
89/**
90 * Information about a command handler used to connect message actions
91 * to a command.
92 */
93export interface CommandReference {
94 /**
95 * The id of the action as referenced in the markup.
96 */
97 id: string;
98 /**
99 * The name of the command the button or menu should invoke
100 * when selected.
101 */
102 name: string;
103 /**
104 * List of parameters to be passed to the command.
105 */
106 parameters?: {
107 [key: string]: any;
108 };
109 /**
110 * Name of the parameter that should be used to pass the values
111 * of the menu drop-down.
112 */
113 parameterName?: string;
114}
115export declare function mapActions(msg: SlackMessage): Action[];
116export interface HandlerResponse {
117 api_version: "1";
118 correlation_id: any;
119 team: {
120 id: string;
121 name?: string;
122 };
123 command?: string;
124 event?: string;
125 status?: {
126 visibility?: "hidden";
127 code?: number;
128 reason: string;
129 };
130 source?: Source;
131 destinations?: any[];
132 content_type?: string;
133 body?: string;
134 id?: string;
135 timestamp?: number;
136 ttl?: number;
137 post_mode?: "ttl" | "always" | "update_only";
138 actions?: Action[];
139 skill: Skill;
140}
141export interface Action {
142 id: string;
143 parameter_name?: string;
144 command: string;
145 parameters: Parameter[];
146}
147export interface Parameter {
148 name: string;
149 value: string;
150}
151export declare function isSlackMessage(object: any): object is SlackMessage;
152/**
153 * Message to create a Snippet in Slack
154 */
155export interface SlackFileMessage {
156 content: string;
157 title?: string;
158 fileName?: string;
159 fileType?: string;
160 comment?: string;
161}
162export declare function isFileMessage(object: any): object is SlackFileMessage;
163export interface StatusPublisher {
164 publish(status: HandlerResponse["status"]): Promise<void>;
165}
166declare abstract class AbstractPubSubMessageClient extends AbstractMessageClient {
167 protected readonly request: CommandIncoming | EventIncoming;
168 protected readonly correlationId: string;
169 protected readonly team: {
170 id: string;
171 name?: string;
172 };
173 protected readonly source: Source;
174 protected readonly graphClient: GraphQLClient;
175 private readonly pubsub;
176 constructor(request: CommandIncoming | EventIncoming, correlationId: string, team: {
177 id: string;
178 name?: string;
179 }, source: Source, graphClient: GraphQLClient);
180 sendResponse(message: any): Promise<void>;
181}
182export declare class PubSubCommandMessageClient extends AbstractPubSubMessageClient implements StatusPublisher {
183 protected readonly request: CommandIncoming;
184 protected readonly graphClient: GraphQLClient;
185 constructor(request: CommandIncoming, graphClient: GraphQLClient);
186 protected doSend(msg: string | SlackMessage, destinations: Destinations, options?: MessageOptions): Promise<any>;
187 publish(status: HandlerResponse["status"]): Promise<void>;
188}
189export declare class PubSubEventMessageClient extends AbstractPubSubMessageClient implements StatusPublisher {
190 protected readonly request: EventIncoming;
191 protected readonly graphClient: GraphQLClient;
192 constructor(request: EventIncoming, graphClient: GraphQLClient);
193 protected doSend(msg: string | SlackMessage, destinations: Destinations, options?: MessageOptions): Promise<any>;
194 publish(status: HandlerResponse["status"]): Promise<void>;
195}
196export declare function prepareStatus(status: HandlerStatus | Error, context: EventContext | CommandContext): HandlerResponse["status"];
197export {};
198//# sourceMappingURL=message.d.ts.map
\No newline at end of file