mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Typings for slack-node (#12195)
* Typings for slack-node * Turning on strictNullChecks
This commit is contained in:
parent
bd04381359
commit
a385e8b4b7
45
slack-node/index.d.ts
vendored
Normal file
45
slack-node/index.d.ts
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Type definitions for slack-node v0.1
|
||||
// Project: https://github.com/clonn/slack-node-sdk
|
||||
// Definitions by: Joshua DeVinney <https://github.com/geoffreak>
|
||||
// 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;
|
||||
49
slack-node/slack-node-tests.ts
Normal file
49
slack-node/slack-node-tests.ts
Normal file
@ -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);
|
||||
});
|
||||
19
slack-node/tsconfig.json
Normal file
19
slack-node/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user