import * as express from 'express'; import * as http from "http" declare namespace botkit { function slackbot(configuration: SlackConfiguration): SlackController; function sparkbot(configuration: CiscoSparkConfiguration): CiscoSparkController; function facebookbot(configuration: FacebookConfiguration): FacebookController; function twilioipmbot(configuration: TwilioIPMConfiguration): TwilioIPMController; function twiliosmsbot(configuration: TwilioSMSConfiguration): TwilioSMSController; function botframeworkbot(configuration: BotFrameworkConfiguration): BotFrameworkController; function teamsbot(configuration: TeamsConfiguration): TeamsController; function consolebot(configuration: ConsoleConfiguration): ConsoleController; function jabberbot(configuration: JabberConfiguration): JabberController; function socketbot(configuration: WebConfiguration): WebController; function anywhere(configuration: WebConfiguration): WebController; interface Bot { readonly botkit: Controller; readonly identity: Identity; readonly utterances: { yes: RegExp; no: RegExp; quit: RegExp; }; say(message: string | M, cb?: (err: Error, res?: any) => void): void replyWithQuestion(src: M, question: string | M, cb: ConversationCallback): void reply(src: M, resp: string | M, cb?: (err: Error, res: any) => void): void; findConversation(message: M, cb: (convo?: Conversation) => void): void; createConversation(message: M, cb: (err: Error, convo: Conversation) => void): void; startConversation(message: M, cb: (err: Error, convo: Conversation) => void): void; // abstract function send(src: M, cb?: (err: Error, res?: any) => void): void; } interface BotFrameworkBot extends Bot { } interface BotFrameworkConfiguration extends Configuration { } interface BotFrameworkController extends Controller { createWebhookEndpoints(webserver: any, bot: BotFrameworkBot, cb?: () => void): this; } interface BotFrameworkMessage extends Message { } interface BotFrameworkSpawnConfiguration { appId: string; appPassword: string; } interface Channel { id: string; } interface CiscoSparkBot extends Bot { retrieveFile(url: string, cb: (err: Error, body: any) => void): void; retrieveFileInfo(url: string, cb: (err: Error, obj: any) => void): void; startPrivateConversation(message: CiscoSparkMessage, cb: (err: Error, convo: Conversation) => void): void; startPrivateConversationWithActor(message: CiscoSparkMessage, cb: (err: Error, convo: Conversation) => void): void; startPrivateConversationWithPersonId(personId: string, cb: (err: Error, convo: Conversation) => void): void; } interface CiscoSparkConfiguration extends Configuration { ciscospark_access_token: string; limit_to_domain?: string | string[]; limit_to_org?: string; public_address: string; secret?: string; webhook_name?: string; } interface CiscoSparkController extends Controller { createWebhookEndpoints(webserver: any, bot: CiscoSparkBot, cb?: () => void): this; } interface CiscoSparkMessage extends Message { actorId?: string; data?: { personDisplayName: string; }; files?: any[]; markdown?: string; original_message?: CiscoSparkMessage; } interface CiscoSparkSpawnConfiguration { } interface Configuration { debug?: boolean; hostname?: string; json_file_store?: string; log?: boolean; logger?: { log: Function; }; storage?: { users: Storage; channels: Storage; teams: Storage; }; studio_token?: string; } interface ConsoleBot extends Bot { } interface ConsoleConfiguration extends Configuration { } interface ConsoleController extends Controller { } interface ConsoleMessage extends Message { } interface ConsoleSpawnConfiguration { } interface Controller> { readonly hears_regexp: HearsFunction; readonly log: { (...params: any[]): void; } readonly middleware: { capture: { use(cb: (bot: B, message: M, convo: Conversation, next: () => void) => void): void; }; heard: { use(cb: (bot: B, message: M, next: () => void) => void): void; }; receive: { use(cb: (bot: B, message: M, next: () => void) => void): void; }; send: { use(cb: (bot: B, message: M, next: () => void) => void): void; }; } readonly storage: { users: Storage; channels: Storage; teams: Storage; }; readonly studio: Studio; changeEars(new_test: HearsFunction): void; hears(keywords: string | string[] | RegExp | RegExp[], events: string | string[], cb: HearsCallback): this; hears(keywords: string | string[] | RegExp | RegExp[], events: string | string[], middleware_or_cb: HearsFunction, cb: HearsCallback): this; on(event: string, cb: HearsCallback): this; setupWebserver(port: number | string, cb: (err: Error, webserver: any) => void): this; spawn(config?: S, cb?: (worker: B) => void): B; startTicking(): void; } interface Conversation { readonly status: ConversationStatusType; activate(): void; addMessage(message: string | M, thread: string): void; addQuestion(message: string | M, cb: ConversationCallback, capture_options: ConversationCaptureOptions, thread: string): void; ask(message: string | M, cb: ConversationCallback, capture_options?: ConversationCaptureOptions): void; beforeThread(thread: string, callback: (convo: this, next: (err: string | Error) => void) => void): void; collectResponse(key: string, value: string): void; extractResponse(key: string): string; extractResponses(): { [key: string]: string }; gotoThread(thread: string): void; next(): void; on(event: string, cb: (convo: this) => void): void; onTimeout(handler: (convo: this) => void): void; repeat(): void; say(message: string | M): void; sayFirst(message: string | M): void; setTimeout(timeout: number): void; setVar(field: string, value: any): void; silentRepeat(): void; stop(status?: ConversationStatusType): void; transitionTo(thread: string, message: string | M): void; } interface ConversationCaptureOptions { key?: string; multiple?: boolean; } interface FacebookAttachment { type: 'audio' | 'file' | 'image' | 'template' | 'video'; payload: any; } interface FacebookBot extends Bot { replyWithTyping(src: FacebookMessage, resp: string | FacebookMessage, cb?: (err: Error) => void): void; startTyping(src: FacebookMessage, cb?: (err: Error) => void): void; stopTyping(src: FacebookMessage, cb?: (err: Error) => void): void; } interface FacebookConfiguration extends Configuration { access_token: string; app_secret?: string; receive_via_postback?: boolean; require_delivery?: boolean; validate_requests?: boolean; verify_token: string; } interface FacebookController extends Controller { readonly api: { attachment_upload: { upload(attachment: FacebookAttachment, cb: (err: Error, attachment_id: string) => void): void; }; messenger_profile: any; thread_settings: any; tags: any; nlp: any; }; createWebhookEndpoints(webserver: any, bot: FacebookBot, cb?: () => void): this; } interface FacebookMessage extends Message { attachment?: FacebookAttachment; notification_type: 'REGULAR' | 'SILENT_PUSH' | 'NO_PUSH'; payload?: string; sender_action?: 'typing_on' | 'typing_off'; } interface FacebookMessengerProfileAPI { account_linking(payload: string): void; delete_account_linking(): void; delete_domain_whitelist(): void; delete_get_started(): void; delete_greeting(): void; delete_home_url(): void; delete_menu(): void; delete_target_audience(): void; domain_whitelist(payload: string | string[]): void; get_account_linking(cb: (err: Error, body: any) => void): void; get_domain_whitelist(cb: (err: Error, body: any) => void): void; get_get_started(cb: (err: Error, body: any) => void): void; get_greeting(cb: (err: Error, body: any) => void): void; get_home_url(cb: (err: Error, body: any) => void): void; get_started(payload: string): void; get_menu(cb: (err: Error, body: any) => void): void; get_messenger_code(image_size: number, cb: (err: Error, uri: string) => void, ref?: string): void; get_target_audience(cb: (err: Error, body: any) => void): void; greeting(payload: string | { locale: string; text: string; }[]): void; home_url(payload: { url: string; webview_height_ratio: 'tall'; webview_share_button?: 'show' | 'hide'; in_test?: boolean; }): void; menu(payload: any): void; target_audience(payload: { audience_type: 'all' | 'custom' | 'none'; countries?: { blacklist?: string[]; whitelist?: string[]; }; }): void; } interface FacebookSpawnConfiguration { } interface Identity { name: string; emails: string[]; } interface JabberBot extends Bot { } interface JabberConfiguration extends Configuration { } interface JabberController extends Controller { } interface JabberMessage extends Message { } interface JabberSpawnConfiguration { client: { jid?: string, password?: string, host?: string, port?: number } } interface Message { action?: string; channel?: string; match?: RegExpMatchArray; text?: string; user?: string; } interface SlackAttachment { attachment_type?: string; actions?: any[]; author_icon?: string; author_link?: string; author_name?: string; callback_id?: string; color?: string; fallback?: string; fields?: { title: string; value: string; short: boolean; }[]; footer?: string; footer_icon?: string; image_url?: string; mrkdwn_in?: string[]; pretext?: string; text?: string; thumb_url?: string; title?: string; title_link?: string; ts?: string; } interface SlackUpdateMessageCallback { (newResponse: string | SlackMessage, cb?: (err: Error) => void): void } interface SlackBot extends Bot { readonly api: SlackWebAPI; configureIncomingWebhook(config: { url: string; }): this; createConversationInThread(src: SlackMessage, cb: (err: Error, res: string) => void): void; createPrivateConversation(message: SlackMessage & { user: string; }, cb: (err: Error, convo: Conversation) => void): void; closeRTM(): void; destroy(): void; identifyTeam(): string; identifyBot(): { id: string; name: string; team_id: string; }; replyAcknowledge(cb?: (err: Error) => void): void; replyAndUpdate(src: SlackMessage, resp: string | SlackMessage, cb: (err: Error, res: string, updateResponse: SlackUpdateMessageCallback) => void): void; replyInThread(src: SlackMessage, resp: string | SlackMessage, cb: (err: Error, res: string) => void): void; replyPrivate(src: SlackMessage, resp: string | SlackMessage, cb?: (err: Error) => void): void; replyPrivateDelayed(src: SlackMessage, resp: string | SlackMessage, cb?: (err: Error) => void): void; replyPublic(src: SlackMessage, resp: string | SlackMessage, cb?: (err: Error) => void): void; replyPublicDelayed(src: SlackMessage, resp: string | SlackMessage, cb?: (err: Error) => void): void; replyInteractive(src: SlackMessage, resp: string | SlackMessage, cb?: (err: Error) => void): void; sendWebhook(options: SlackMessage, cb: (err: string, body: any) => void): void; startPrivateConversation(message: SlackMessage & { user: string; }, cb: (err: Error, convo: Conversation) => void): void; startConversationInThread(src: SlackMessage, cb: (err: Error, res: string) => void): void; startRTM(cb?: (err: string, bot: SlackBot, payload: any) => void): SlackBot; } interface SlackConfiguration extends Configuration { api_root?: string; clientId?: string; clientSecret?: string; disable_startup_messages?: boolean; incoming_webhook?: { url: string; }; interactive_replies?: boolean; rtm_receive_messages?: boolean; require_delivery?: boolean; retry?: number; scopes?: string[]; send_via_rtm?: boolean; stale_connection_timeout?: number; } interface SlackController extends Controller { configureSlackApp(config: { clientId: string; clientSecret: string; redirectUri: string; scopes: string[]; }): this; createHomepageEndpoint(webserver: any): this; createOauthEndpoints(webserver: any, callback: (err: Error, req: any, res: any) => void): this; createWebhookEndpoints(webserver: any, authenticationTokens?: string[]): this; setupWebserver(port: number | string, cb: (err: Error, webserver: any) => void): this; getAuthorizeURL(team_id: string, redirect_params: any): string; } interface SlackMessage extends Message { attachments?: SlackAttachment[]; icon_emoji?: string; icon_url?: string; link_names?: boolean; parse?: string; reply_broadcast?: boolean; replace_original?: boolean; response_type?: string; type?: string; thread_ts?: string; ts?: string; unfurl_links?: boolean; unfurl_media?: boolean; username?: string; } interface SlackSpawnConfiguration { token: string; } interface SlackWebAPI { auth: { test: SlackWebAPIMethod; }, oauth: { access: SlackWebAPIMethod; } channels: { archive: SlackWebAPIMethod; create: SlackWebAPIMethod; history: SlackWebAPIMethod; info: SlackWebAPIMethod; invite: SlackWebAPIMethod; join: SlackWebAPIMethod; kick: SlackWebAPIMethod; leave: SlackWebAPIMethod; list: SlackWebAPIMethod; mark: SlackWebAPIMethod; rename: SlackWebAPIMethod; replies: SlackWebAPIMethod; setPurpose: SlackWebAPIMethod; setTopic: SlackWebAPIMethod; unarchive: SlackWebAPIMethod; }; chat: { delete: SlackWebAPIMethod; postMessage: SlackWebAPIMethod; update: SlackWebAPIMethod; unfurl: SlackWebAPIMethod; }; dnd: { endDnd: SlackWebAPIMethod; endSnooze: SlackWebAPIMethod; info: SlackWebAPIMethod; setSnooze: SlackWebAPIMethod; teamInfo: SlackWebAPIMethod; }; emoji: { list: SlackWebAPIMethod; }; files: { delete: SlackWebAPIMethod; info: SlackWebAPIMethod; list: SlackWebAPIMethod; upload: SlackWebAPIMethod; }; groups: { archive: SlackWebAPIMethod; close: SlackWebAPIMethod; create: SlackWebAPIMethod; createChild: SlackWebAPIMethod; history: SlackWebAPIMethod; info: SlackWebAPIMethod; invite: SlackWebAPIMethod; kick: SlackWebAPIMethod; leave: SlackWebAPIMethod; list: SlackWebAPIMethod; mark: SlackWebAPIMethod; open: SlackWebAPIMethod; rename: SlackWebAPIMethod; replies: SlackWebAPIMethod; setPurpose: SlackWebAPIMethod; setTopic: SlackWebAPIMethod; unarchive: SlackWebAPIMethod; }; im: { close: SlackWebAPIMethod; history: SlackWebAPIMethod; list: SlackWebAPIMethod; mark: SlackWebAPIMethod; open: SlackWebAPIMethod; replies: SlackWebAPIMethod; }; mpim: { close: SlackWebAPIMethod; history: SlackWebAPIMethod; list: SlackWebAPIMethod; mark: SlackWebAPIMethod; open: SlackWebAPIMethod; replies: SlackWebAPIMethod; }; pins: { add: SlackWebAPIMethod; list: SlackWebAPIMethod; remove: SlackWebAPIMethod; }; reactions: { add: SlackWebAPIMethod; get: SlackWebAPIMethod; list: SlackWebAPIMethod; remove: SlackWebAPIMethod; }; reminders: { add: SlackWebAPIMethod; complete: SlackWebAPIMethod; delete: SlackWebAPIMethod; info: SlackWebAPIMethod; list: SlackWebAPIMethod; }; rtm: { start: SlackWebAPIMethod; connect: SlackWebAPIMethod; }; search: { all: SlackWebAPIMethod; files: SlackWebAPIMethod; messages: SlackWebAPIMethod; }; stars: { add: SlackWebAPIMethod; list: SlackWebAPIMethod; remove: SlackWebAPIMethod; }; team: { accessLogs: SlackWebAPIMethod; info: SlackWebAPIMethod; billableInfo: SlackWebAPIMethod; integrationLogs: SlackWebAPIMethod; profile: { get: SlackWebAPIMethod; }; }; users: { getPresence: SlackWebAPIMethod; info: SlackWebAPIMethod; list: SlackWebAPIMethod; setActive: SlackWebAPIMethod; setPresence: SlackWebAPIMethod; deletePhoto: SlackWebAPIMethod; identity: SlackWebAPIMethod; setPhoto: SlackWebAPIMethod; profile: { get: SlackWebAPIMethod; set: SlackWebAPIMethod; }; }; } interface Storage { save: (data: O, cb?: (err: Error, id: string) => void) => void; get: (id: string, cb: (err: Error, data: O) => void) => void; delete?: (id: string, cb?: (err: Error) => void) => void; all?: (cb: (err: Error, data: O[]) => void) => void; } interface Studio> { after(command_name: string, func: (convo: Conversation, next: () => void) => void): this; before(command_name: string, func: (convo: Conversation, next: () => void) => void): this; beforeThread(command_name: string, thread_name: string, func: (convo: Conversation, next: () => void) => void): this; get(bot: B, input_text: string, user: string, channel: string): Promise>; run(bot: B, input_text: string, user: string, channel: string): Promise>; runTrigger(bot: B, input_text: string, user: string, channel: string): Promise>; validate(command_name: string, key: string, func: (convo: Conversation, next: () => void) => void): this; } interface Team { id: string; } interface TeamsAPI { getUserById(conversationId: string, userId: string, cb: (err: Error, user_profile: any) => void): void; getUserByUpn(conversationId: string, upn: string, cb: (err: Error, user_profile: any) => void): void; getConversationMembers(conversationId: string, cb: (err: Error, members: any[]) => void): void; getTeamRoster(teamId: string, cb: (err: Error, members: any[]) => void): void; updateMessage(conversationId: string, messageId: string, replacement: TeamsMessage, cb: (err: Error, results: any) => void): void; getChannels(teamId: string, cb: (err: Error, channels: any[]) => void): void; } interface TeamsAttachment { content: TeamsAttachmentContent; contentType: string; title(v: string): this; subtitle(v: string): this; text(v: string): this; image(object: _TeamsAttachmentContentImage): this; image(url: string, alt?: string): this; button(object: _TeamsAttachmentContentButtonAction): this; button(type: string, title: string, value: string): this; tap(object: _TeamsAttachmentContentTapAction): this; tap(type: string, title: string, payload: string): this; } interface TeamsAttachmentContent { title?: string; subtitle?: string; text?: string; images?: _TeamsAttachmentContentImage[]; buttons?: _TeamsAttachmentContentButtonAction[]; tap?: _TeamsAttachmentContentTapAction; } interface _TeamsAttachmentContentButtonAction { type: string; title: string; image?: string; value: string; } interface _TeamsAttachmentContentImage { url: string; alt?: string; } interface _TeamsAttachmentContentTapAction { type: string; value: string; } interface TeamsBot extends Bot { api: TeamsAPI; createHero(object: TeamsAttachmentContent): TeamsAttachment; createHero(title?: string, subtitle?: string, text?: string, images?: _TeamsAttachmentContentImage[], buttons?: _TeamsAttachmentContentButtonAction[], tap?: _TeamsAttachmentContentTapAction): TeamsAttachment; createThumbnail(object: TeamsAttachmentContent): TeamsAttachment; createThumbnail(title?: string, subtitle?: string, text?: string, images?: _TeamsAttachmentContentImage[], buttons?: _TeamsAttachmentContentButtonAction[], tap?: _TeamsAttachmentContentTapAction): TeamsAttachment; } interface TeamsConfiguration extends Configuration { clientId?: string; clientSecret?: string; } interface TeamsController extends Controller { createWebhookEndpoints(): this; } interface TeamsMessage extends Message { // for outgoing message summary: string, attachments?: TeamsAttachment[]; attachmentLayout?: 'list' | 'grid'; // for incoming events type?: [ 'direct_message' | 'direct_mention' | 'mention' | 'bot_channel_join' | 'user_channel_join' | 'bot_channel_leave' | 'user_channel_leave' | 'channelDeleted' | 'channelRenamed' | 'channelCreated' | 'invoke' | 'composeExtension' ] raw_message?: any } interface TeamsSpawnConfiguration { serviceUrl: string team?: string // GUID } interface TwilioIPMBot extends Bot { readonly api: any; } interface TwilioIPMConfiguration extends Configuration { } interface TwilioIPMController extends Controller { createWebhookEndpoints(webserver: any, bot: TwilioIPMBot): this; } interface TwilioIPMMessage extends Message { } interface TwilioIPMSpawnConfiguration { autojoin?: boolean; identity?: string; TWILIO_IPM_SERVICE_SID: string; TWILIO_ACCOUNT_SID: string; TWILIO_API_KEY: string; TWILIO_API_SECRET: string; } interface TwilioSMSBot extends Bot { } interface TwilioSMSConfiguration extends Configuration { account_sid: string; auth_token: string; twilio_number: string; } interface TwilioSMSController extends Controller { createWebhookEndpoints(webserver: any, bot: TwilioSMSBot, cb?: () => void): this; } interface TwilioSMSMessage extends Message { } interface TwilioSMSSpawnConfiguration { } interface WebBot extends Bot { connected: boolean; } interface WebConfiguration extends Configuration { replyWithTyping?: boolean; } interface WebController extends Controller { httpserver: http.Server; webserver: express.Express; openSocketServer(server: http.Server): void; } export interface WebMessage extends Message { } interface WebSpawnConfiguration { } interface User { id: string; name?: string; } type ConversationCallback = ((message: M, convo: Conversation) => void) | ({ pattern?: string | RegExp; default?: boolean; callback: (message: M, convo: Conversation) => void; }[]); type ConversationStatusType = 'completed' | 'active' | 'stopped' | 'timeout' | 'ending' | 'inactive'; type HearsCallback> = (bot: B, message: M) => void; type HearsFunction = (tests: string | string[] | RegExp | RegExp[], message: M) => boolean; type SlackWebAPIMethod = (data: any, cb: (err: Error, response: any) => void) => void; } export = botkit;