Add node-slack

This commit is contained in:
tkQubo 2015-08-25 19:57:18 +09:00
parent a1226afe5c
commit eac74c371e
3 changed files with 109 additions and 2 deletions

View File

@ -24,8 +24,8 @@ interface RetryOption {
interface DeferredizedFunction { (...arg: any[]): Deferred; }
interface DeferredizedFunctionWithNumber { (n: number): Deferred; }
interface FunctionWithNumber { (i: number, o?: any); }
interface ErrorCallback { (d: Deferred, ...args: any[]); }
interface FunctionWithNumber { (i: number, o?: any): any; }
interface ErrorCallback { (d: Deferred, ...args: any[]): any; }
declare class Deferred {

View File

@ -0,0 +1,46 @@
/// <reference path="../express/express.d.ts" />
/// <reference path="node-slack.d.ts" />
import express = require('express');
import Slack = require('node-slack');
let app = express();
var hook_url: string = 'foo_hook';
var options: Slack.Option = { proxy: '' };
var slack = new Slack(hook_url, options);
slack.send({
text: 'Howdy!',
channel: '#foo',
username: 'Bot'
});
var attachment_array: any[] = [];
slack.send({
text: 'Howdy!',
channel: '#foo',
username: 'Bot',
icon_emoji: 'taco',
attachments: attachment_array,
unfurl_links: true,
link_names: 1
});
app.post('/yesman', function(req, res) {
var reply = slack.respond(req.body, function(hook: any) {
return {
text: 'Good point, ' + hook.user_name,
username: 'Bot'
};
});
res.json(reply);
});

61
node-slack/node-slack.d.ts vendored Normal file
View File

@ -0,0 +1,61 @@
// Type definitions for node-slack
// Project: https://github.com/xoxco/node-slack
// Definitions by: Qubo <https://github.com/tkQubo>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../request/request.d.ts" />
declare module "node-slack" {
import request = require('request');
class Slack {
constructor(hookUrl: string, option?: Slack.Option);
send(message: Slack.Message): any; //TODO: Here comes deferred's promise as a return type
send(message: Slack.Message, callback: Slack.SendCallback): request.Request;
respond(query: Slack.Query): Slack.TextResponse;
respond(query: Slack.Query, callback: Slack.ResponseCallback): Slack.TextResponse;
}
namespace Slack {
interface Option {
proxy: string;
}
interface Message {
text: string;
channel?: string;
username?: string;
icon_emoji?: string;
attachments?: any[];
unfurl_links?: boolean;
link_names?: number;
}
interface SendCallback {
(err: any, body: any): any;
}
interface Query {
token?: string;
team_id?: string;
channel_id?: string;
channel_name?: string;
timestamp?: number;
user_id?: string;
user_name?: string;
text: string;
}
interface TextResponse {
text: string;
}
interface ResponseCallback {
(err: any, query: Query): any;
}
}
export = Slack;
}