GithubHelp home page GithubHelp logo

node-slack's Introduction

node-slack

A node module for sending and receiving messages with Slack via webhooks.

Slack is a messaging platform that is easy to integrate with. This module should be useful for creating various integrations with Slack, such as chat bots!

Install Slack

node-slack is available via npm:

npm install node-slack

Get your hook_url from the Slack Incoming Webhooks Integration page.

var Slack = require('node-slack');
var slack = new Slack(hook_url,options);

If your system requires that requests be made through an HTTP or HTTPS proxy, you can either set an environment variables https_proxy and http_proxy, or pass in the optional third option:

var slack = new Slack(hook_url,{proxy: http_proxy});

To send a message, call slack.send:

slack.send({
	text: 'Howdy!',
	channel: '#foo',
	username: 'Bot'
});

You can also specify an emoji icon, a url to a custom icon, attachments, and any of the other options listed here.

slack.send({
	text: 'Howdy!',
	channel: '#foo',
	username: 'Bot',
	icon_emoji: 'taco',
	attachments: attachment_array,
	unfurl_links: true,
	link_names: 1
});

To respond to an outgoing webhook from slack, pass the information from the webhook into slack.respond, along with a callback function responsible for returning a response.

From inside an Express.js route, this is as easy as passing in req.body:

app.post('/yesman',function(req,res) {

	var reply = slack.respond(req.body,function(hook) {

		return {
			text: 'Good point, ' + hook.user_name,
			username: 'Bot'
		};

	});

	res.json(reply);

});

node-slack's People

Contributors

muddydixon avatar superhighfives avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.