From a385e8b4b76bb37fb2dbe6cd0e44dc32935db5fc Mon Sep 17 00:00:00 2001 From: Joshua DeVinney Date: Tue, 25 Oct 2016 23:28:34 -0500 Subject: [PATCH] Typings for slack-node (#12195) * Typings for slack-node * Turning on strictNullChecks --- slack-node/index.d.ts | 45 +++++++++++++++++++++++++++++++ slack-node/slack-node-tests.ts | 49 ++++++++++++++++++++++++++++++++++ slack-node/tsconfig.json | 19 +++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 slack-node/index.d.ts create mode 100644 slack-node/slack-node-tests.ts create mode 100644 slack-node/tsconfig.json diff --git a/slack-node/index.d.ts b/slack-node/index.d.ts new file mode 100644 index 0000000000..c10e744e28 --- /dev/null +++ b/slack-node/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for slack-node v0.1 +// Project: https://github.com/clonn/slack-node-sdk +// Definitions by: Joshua DeVinney +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as request from "request"; + +declare class Slack { + token: string; + domain: string; + apiMode: boolean; + url: string; + timeout: number; + maxAttempts: number; + + constructor(token?: string, domain?: string); + composeUrl(): string; + setWebhook(url: string): this; + detectEmoji(emoji: string): { key: "icon_url" | "icon_emoji", val: string }; + webhook(options: Slack.WebhookOptions, callback: (err: any, response: Slack.WebhookResponse) => void): void; + api(method: string, callback: (err: any, response: any) => void): this; + api(method: string, options: any, callback: (err: any, response: any) => void): this; +} + +declare namespace Slack { + + export interface WebhookOptions { + icon_emoji?: string; + response_type?: string; + channel?: string; + text?: string; + username?: string; + attachments?: any[]; + link_names?: any; + } + + export interface WebhookResponse { + status: "fail" | "ok"; + statusCode: number; + headers: any; + response: any; + } +} + +export = Slack; \ No newline at end of file diff --git a/slack-node/slack-node-tests.ts b/slack-node/slack-node-tests.ts new file mode 100644 index 0000000000..b14029af19 --- /dev/null +++ b/slack-node/slack-node-tests.ts @@ -0,0 +1,49 @@ +import * as Slack from "slack-node"; + +let webhookUri = "__uri___"; + +let slack = new Slack(); +slack.setWebhook(webhookUri); + +slack.webhook({ + channel: "#general", + username: "webhookbot", + text: "This is posted to #general and comes from a bot named webhookbot." +}, function(err, response) { + console.log(response); +}); + +// slack emoji +slack.webhook({ + channel: "#general", + username: "webhookbot", + icon_emoji: ":ghost:", + text: "test message, test message" +}, function(err, response) { + console.log(response); +}); + +// URL image +slack.webhook({ + channel: "#general", + username: "webhookbot", + icon_emoji: "http://icons.iconarchive.com/icons/rokey/popo-emotions/128/after-boom-icon.png", + text: "test message, test message" +}, function(err, response) { + console.log(response); +}); + + +let apiToken = "-- api token --"; +slack = new Slack(apiToken); + +slack.api("users.list", function(err, response) { + console.log(response); +}); + +slack.api("chat.postMessage", { + text: "hello from nodejs", + channel: "#general" +}, function(err, response){ + console.log(response); +}); diff --git a/slack-node/tsconfig.json b/slack-node/tsconfig.json new file mode 100644 index 0000000000..b49b6acc21 --- /dev/null +++ b/slack-node/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "slack-node-tests.ts" + ] +} \ No newline at end of file