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

benbrown avatar cyrusroshan avatar muddydixon avatar superhighfives avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-slack's Issues

Can't use icons

I tried to send icon with slack message but i can't get it done.

As the readme shows, I tried the following:

slack.send({
    text: `${environment} - ${finalMessage}`,
    channel: `#${channel}`,
    username: 'Bot',
    icon_emoji: ':taco:',
});

May I have to put :taco: in the message body? If i do that it works but then why i have to use 'icon_emoji' property?

Thank you in advance.

deprecated `request` dependency

I'm getting this warning:

npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142

From my investigation, it is coming from node-slack

    "node-slack": {
      "version": "0.0.7",
      "resolved": "https://registry.npmjs.org/node-slack/-/node-slack-0.0.7.tgz",
      "integrity": "sha512-LsjUmymJcwF7P2Z3wImZRYIZvh068aQNYK6/FW+24fred4+hWPHyc6L9f7nQUoA6myt6NPFDBPXSqe493+cXqQ==",
      "requires": {
        "deferred": "0.7.1",
        "request": "~2.x"
      }
    },

Link: request/request#3142

Access Control Origin

I am able to post messages through your repo but I continue to get the below message on both my local and staging environments

XMLHttpRequest cannot load https://hooks.slack.com/services/randomtext/randomtext.
A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. 
Origin 'https://localhost:3000' is therefore not allowed access.

ability to send commands

Just taking a look at this package for the first time, looks like we aren't able to send slash command, am I missing something or is this not available in this package?

Update docs

I only found out that there's a callback associated to send because of an unaccepted PR to make send promisified. Any docs around the promises or callbacks would really help new users.

Option unfurl_media=false doesn't work

I need to disable unfurling, but when I use option unfurl_media: false, the image is still shown.

This code reproduces it:

var Slack = require('node-slack');
var config = {
    hook: 'https://hooks.slack.com/services/<token>',
    channel: '#<channel>',
};

var slack = new Slack(config.hook);
slack.send({
    text: 'This message should not display image https://d3blmjzegggclu.cloudfront.net/assets/images/front/camera-big.png?1439887878, but image is shown.',
    username: 'TEST',
    channel: config.channel,
    unfurl_links: false,
    unfurl_media: false,
});

Result:

screen shot 2015-08-26 at 11 16 11

Not possible to send multiline messages?

Great little lib, I however fail to send multiline messages.
Setting text to something like "First line\nSecond line" comes out in Slack as "First line/nSecond line"
Looks like there is a mapping from \ to / somewhere... Couldn't find it though - prob missed something obvious..

error installing on windows

> [email protected] prepublish c:\Users\WesM\AppData\Local\Temp\npm-9848-gU1fR6N1\bluebird-2.9.341440627724324-0.9726775458548218\package
> node tools/build.js --no-debug --main --zalgo --browser --minify


module.js:333
    throw err;
          ^
Error: Cannot find module 'c:\Users\WesM\AppData\Local\Temp\npm-9848-gU1fR6N1\bluebird-2.9.341440627724324-0.9726775458548218\package\tools\build.js'
    at Function.Module._resolveFilename (module.js:331:15)
    at Function.Module._load (module.js:273:25)
    at Function.Module.runMain (module.js:490:10)
    at startup (node.js:123:16)
    at node.js:1027:3

"Error invoking Method 'sendSlack': Internal server error [500] "

I have developed a MeteorJs project which sends some messages on your Slack.

Though it runs smoothly locally and on Heroku, when I uploaded on DigitalOcean I am getting this message:

"[Log] Error invoking Method 'sendSlack': Internal server error [500] (f28e39f50692cf61ad0b0a98bfb0e69f709b7d17.js, line 3)"

Any idea why I am getting this?

Default channel is overridden with #general

Slack allows you to set the channel for an incoming webhook request, but because this module defaults to #general if no channel is passed to send(), the default always gets overridden with #general

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.