Coder Social home page Coder Social logo

slackapi / node-slack-sdk Goto Github PK

View Code? Open in Web Editor NEW
3.2K 123.0 657.0 14.3 MB

Slack Developer Kit for Node.js

Home Page: https://slack.dev/node-slack-sdk

License: MIT License

JavaScript 16.54% TypeScript 83.24% Ruby 0.16% Shell 0.05%
typescript slack slackapi websocket websocket-client websockets socket-mode

node-slack-sdk's Introduction

Node Slack SDK

build-ci


Getting Started

Visit the documentation site for all the lovely details.

This SDK is a collection of single-purpose packages. The packages are aimed at making building Slack apps easy, performant, secure, and scalable. They can help with just about anything in the Slack platform, from dropping notifications in channels to fully interactive bots.

The Slack platform offers several APIs to build apps. Each Slack API delivers part of the capabilities from the platform, so that you can pick just those that fit for your needs. This SDK offers a corresponding package for each of Slack's APIs. They are small and powerful when used independently, and work seamlessly when used together, too.

Just starting out? The Getting Started tutorial will walk you through building your first Slack app using Node.js.

Slack API What its for NPM Package
Web API Send data to or query data from Slack using any of over 220 methods. @slack/web-api
OAuth Setup the authentication flow using V2 OAuth for Slack apps as well as V1 OAuth for classic Slack apps. @slack/oauth
Incoming Webhooks Send notifications to a single channel which the user picks on installation. @slack/webhook
Socket Mode Listen for incoming messages and a limited set of events happening in Slack, using WebSocket. @slack/socket-mode

Not sure about which APIs are right for your app? Read our blog post that explains the options. If you're still not sure, reach out for help and our community can guide you.

Deprecation Notice

@slack/events-api and @slack/interactive-messages officially reached EOL on May 31st, 2021. Development has fully stopped for these packages and all remaining open issues and pull requests have been closed.

At this time, we recommend migrating to Bolt for JavaScript, a framework that offers all of the functionality available in those packages (and more). To help with that process, we've provided some migration samples for those looking to convert their existing apps.

Installation

Use your favorite package manager to install any of the packages and save to your package.json:

$ npm install @slack/web-api @slack/socket-mode

# Or, if you prefer yarn
$ yarn add @slack/web-api @slack/socket-mode

Usage

The following examples summarize the most common ways to use this package. There's also a Getting Started tutorial that's perfect for just starting out, and each package's documentation, linked in the table above.

Posting a message with Web API

Your app will interact with the Web API through the WebClient object, which is an export from @slack/web-api. You typically instantiate a client with a token you received from Slack. The example below shows how to post a message into a channel, DM, MPDM, or group. The WebClient object makes it simple to call any of the over 130 Web API methods.

const { WebClient } = require('@slack/web-api');

// An access token (from your Slack app or custom integration - xoxp, xoxb)
const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);

// This argument can be a channel ID, a DM ID, a MPDM ID, or a group ID
const conversationId = 'C1232456';

(async () => {
  // See: https://api.slack.com/methods/chat.postMessage
  const res = await web.chat.postMessage({ channel: conversationId, text: 'Hello there' });

  // `res` contains information about the posted message
  console.log('Message sent: ', res.ts);
})();

Note: To use the example above, the token is required to have either the bot, chat:user:write, or chat:bot:write scopes.

Tip: Use the Block Kit Builder for a playground where you can prototype your message's look and feel.

Listening for an event with the Events API

Refer to Bolt for JavaScript document pages.

Responding to interactive messages

Refer to Bolt for JavaScript document pages.

Using Socket Mode

Refer to the module document page and Bolt for JavaScript document page.

Requirements

This package supports Node v14 and higher. It's highly recommended to use the latest LTS version of node, and the documentation is written using syntax and features from that version.

Getting Help

If you get stuck, we're here to help. The following are the best ways to get assistance working through your issue:

  • Issue Tracker for questions, feature requests, bug reports and general discussion related to these packages. Try searching before you create a new issue.
  • Email us in Slack developer support: [email protected]

node-slack-sdk's People

Contributors

acemtp avatar againer avatar aoberoi avatar bertrandom avatar charliehess avatar clavin avatar copperwall avatar dominikpalo avatar ekmartin avatar evansolomon avatar filmaj avatar ggruiz avatar grantmd avatar hello-ashleyintech avatar kharitonoff avatar misscoded avatar moffatethan avatar mwbrooks avatar paulasjes avatar paulhammond avatar peernohell avatar roach avatar romanbalayan avatar seratch avatar shaydewael avatar srajiang avatar stevengill avatar svc-ghe-snow avatar vanm avatar zimeg 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  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

node-slack-sdk's Issues

Unable to install on Node V 0.10.29 - probable user error

Hi,

I am trying to run a Slackbot server on my Raspberry Pi2, below is an error I am getting when installing using NPM.

Is there a dependency upon the node version which I cannot see? I have installed all the optional dependencies, although Coffee-Script and WS are at a higher level than required.

Thanks

Chris

pi@raspberrypi3:~ $ sudo npm install slack-client
npm WARN package.json [email protected] No repository field.

[email protected] install /home/pi/node_modules/slack-client/node_modules/ws/node_modules/utf-8-validate
node-gyp rebuild

make: Entering directory '/home/pi/node_modules/slack-client/node_modules/ws/node_modules/utf-8-validate/build'
CXX(target) Release/obj.target/validation/src/validation.o
In file included from ../src/validation.cc:15:0:
../node_modules/nan/nan.h:328:47: error: ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’
static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
^
validation.target.mk:84: recipe for target 'Release/obj.target/validation/src/validation.o' failed
make: *** [Release/obj.target/validation/src/validation.o] Error 1
make: Leaving directory '/home/pi/node_modules/slack-client/node_modules/ws/node_modules/utf-8-validate/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:809:12)
gyp ERR! System Linux 4.1.13-v7+
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/pi/node_modules/slack-client/node_modules/ws/node_modules/utf-8-validate
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

[email protected] install /home/pi/node_modules/slack-client/node_modules/ws/node_modules/bufferutil
node-gyp rebuild

make: Entering directory '/home/pi/node_modules/slack-client/node_modules/ws/node_modules/bufferutil/build'
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
In file included from ../src/bufferutil.cc:16:0:
../node_modules/nan/nan.h:328:47: error: ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’
static const unsigned kReplaceInvalidUtf8 = v8::String::REPLACE_INVALID_UTF8;
^
bufferutil.target.mk:84: recipe for target 'Release/obj.target/bufferutil/src/bufferutil.o' failed
make: *** [Release/obj.target/bufferutil/src/bufferutil.o] Error 1
make: Leaving directory '/home/pi/node_modules/slack-client/node_modules/ws/node_modules/bufferutil/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:809:12)
gyp ERR! System Linux 4.1.13-v7+
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/pi/node_modules/slack-client/node_modules/ws/node_modules/bufferutil
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok
npm WARN optional dep failed, continuing [email protected]
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm WARN optional dep failed, continuing [email protected]
[email protected] node_modules/slack-client
├── [email protected]
└── [email protected] ([email protected], [email protected])

pi@raspberrypi3:~ $ sudo npm install coffee-script
npm WARN package.json [email protected] No repository field.
[email protected] node_modules/coffee-script

pi@raspberrypi3:~ $ sudo npm install ws
npm WARN package.json [email protected] No repository field.
[email protected] node_modules/ws
├── [email protected]
└── [email protected]

Event naming conventions are inconsistent.

Being pedantic.

So events like loggedIn and presenceChange are emitted as camelCase, but star_added and star_removed (and raw_message, but I'm not sure if that's intended to be actually exposed) are in snake_case.

For reasons related to preserving my sanity, can I submit a PR that either changes the snake_case events to be emitted as camelCase, or (for API preservation) emitted as both snake_case and camelCase? (Or variations thereof.)

Takes over `this` context

It seems that when the client is used inside of another constructor, it takes over the this context. Why, I'm not sure, nor how. Extremely inconvenient.

Prepublish fails for me

Following along in the example code, I ran npm install and failed:

npm ERR! [email protected] prepublish: `grunt prepublish`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prepublish script.
npm ERR! This is most likely a problem with the slack-client package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     grunt prepublish

Turns out grunt is required, so you'll need to install it first with:

npm install -g grunt-cli

`/away` sets you as offline

Shouldn't it mark you with a yellow dot or something, to show you're away and not offline?
Would also be useful with a /busy command, where the dot would turn red and you won't get any notifications, etc.

Add emit on user change to Slack client

Hi @paulhammond and @grantmd,

Good news! We've been able to successfully migrate our bot, Hermes, from Hipchat to Slack without much difficulty!

One thing we'd like to add to your Slack client is to add an emitter to fire on new user or user change. This way, when Hermes is running, a new user who joins the organization would be able to interact with Hermes (Hermes would dynamically add the new user to the list of all users).

We were thinking of just adding a single line as below:
screen shot 2014-11-17 at 5 25 18 pm
Here:
https://github.com/slackhq/node-slack-client/blob/master/src/client.coffee#L386

Thoughts?

/cc @stevenmiller888

Cannot listen on `team_join` event

I want to set slack client to listen on team_join event.

slack.on('team_join', function(message) {
    var user = slack.getUserByID(message.user),
        channel = slack.getChannelByName('general');

    console.log('message:', message);
    channel.send('Hello ' + user.name);
});

However, nothing happens when a new member joins the team.

On user leaving channel, slack errors

node_modules/slack-client/src/channel.js:78
        index = this.members.indexOf(message.user);
                            ^

TypeError: Cannot read property 'indexOf' of undefined
    at Channel.addMessage (node_modules/slack-client/src/channel.js:78:29)
    at Client.onMessage (node_modules/slack-client/src/client.js:486:26)
    at WebSocket.<anonymous> (node_modules/slack-client/src/client.js:140:24)
    at emitTwo (events.js:87:13)
    at WebSocket.emit (events.js:172:7)
    at Receiver.ontext (node_modules/slack-client/node_modules/ws/lib/WebSocket.js:816:10)
    at node_modules/slack-client/node_modules/ws/lib/Receiver.js:477:18
    at Receiver.applyExtensions (node_modules/slack-client/node_modules/ws/lib/Receiver.js:364:5)
    at node_modules/slack-client/node_modules/ws/lib/Receiver.js:466:14
    at Receiver.flush (node_modules/slack-client/node_modules/ws/lib/Receiver.js:340:3)

channel.send silently fails after a while

I have a bot running for days. It sometimes sends something or responses to special commands. I noticed that after some time being run the bot's messages aren't appeared in channels. I can see that the bot sent a message (I have logging) but there are nothing happened in Slack.
At some time my bot sends two messages in a row, the first one via channel.send and the second one via channel.postMessage (I do this for unfurl_links). Only the second message (sent via postMessage) appeared in the channel. If I restart the bot everything starts working fine again.

Removed app, no message

When the app is removed from Slack, I can't see any type of message received letting the client acknowledge that. I only have the ping messages stopped.
Is there a clear way of knowing that the app was removed?

Error - please help

I'm getting this error code, what can I do? Sorry, I'm very new to all this grunt stuff.

Error: Cannot find module 'grunt-legacy-log-utils'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/Volumes/webserver/jock/zinvite/node_modules/grunt/node_modules/grunt-legacy-log/index.js:25:16)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)

Thank you.

Only Listen to a specific channel

Hi,

I wonder if there is any way to listen to messages on a specific channel? Listening to messages event means checking every message that comes into the system and then checking the channel and then performing an action. Isn't there a simpler way in RTM where the bot opens a channel and listens for messages. When the task is complete, it closes the channel.

My real-world usecase is :
My bot will open a DM channel with a specific user and ask a question. When the user responds, it will followup with a second question. When the user answers that, the bot will thank the user and end the conversation.

API/Bot Client High Memory Usage

This bug's been around from quite a long while and i'm honestly surprised as to why no one else has picked up on it yet. I originally launched the issue through Slack's support, but it's apparent that it hasn't gotten through to the dev team.

Using the given example in the readme, produces a continual increase in memory usage with no other modules and minimal code. Let me know if you require any more details, but both of my 2 slack bots have had this issue, as well as 2 of my friends.

Edit: We've been able to reproduce this on 3 different systems, with 5 seperate programs, by 3 different people.

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

My bot often crashes for the following error:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
State changed from starting to crashed
State changed from crashed to starting
Process exited with status 137

Is it a bug within node-slack-client or some settings with heroku that I'm missing?
According to this StackOverflow thread, you can fix it by telling your app to listen to a port that Heroku assign dynamically app.listen(process.env.PORT). But how can you do it with slack-client?

My code is here.

How does getChannelGroupOrDMByID work? or does it?

I've been trying to send a DM to a user in a slack channel with many many users connected (at least 100). I've noticed that the IM list is very short (from the object returned from rtm.start) and that the user I'm trying to send a DM to isn't in this list. Normally, you would just look for the DM id using the IM list. How does node-slack-client handle this, if it even can? What's the correct way to send a DM to someone if they are not in the IM list (or how do you get the DM id from a user id)?

WebSocket closed silently and will not reconnect

Sometimes Slack RTM WebSocket connection close silently after running for a few days (2-3 days in our 2-3 months experiences). It does not emit any errors, unhandled exceptions, or quitting the app.

The existing "reconnect" algorithm only reconnect on auth error. Therefore, the app does not know the WS connection is dropped. It simply receive no new messages until someone restarted the app.

Currently, our remedy looks like this:

var slack = new (require('slack-client'))('xoxb-...', true, true);

slack
    …
    .on('close', function () {
        console.log('Connection closed, retrying');
        slack.reconnect();
    })
    …
    .login();

I would suggest putting this logic back into client.coffee when autoReconnect is enabled. Or building a more robust watchdog.

Export models

I am unable to stub the models (such as message) returned by the various methods of the slack client here because those models cannot be imported.

Please expose the models used here so I can properly mock this library.

Exception: Cannot set property 'services_only_admins' of undefined

My bot based on the slack-client node module crashed a couple of times today. Looks like it got a message it couldn't handle. This is the mysterious backtrace.

/app/node_modules/slack-client/src/client.js:546
        return this.team.prefs[message.name] = message.value;
TypeError: Cannot set property 'services_only_admins' of undefined
    at Client.onMessage (/app/node_modules/slack-client/src/client.js:546:46)
    at WebSocket.<anonymous> (/app/node_modules/slack-client/src/client.js:142:24)
    at WebSocket.emit (events.js:98:17)
    at Receiver.self._receiver.ontext (/app/node_modules/slack-client/node_modules/ws/lib/WebSocket.js:697:10)
    at Receiver.opcodes.1.finish (/app/node_modules/slack-client/node_modules/ws/lib/Receiver.js:397:14)
    at Receiver.expectHandler (/app/node_modules/slack-client/node_modules/ws/lib/Receiver.js:384:31)
    at Receiver.add (/app/node_modules/slack-client/node_modules/ws/lib/Receiver.js:93:24)
    at CleartextStream.firstHandler (/app/node_modules/slack-client/node_modules/ws/lib/WebSocket.js:678:22)
    at CleartextStream.emit (events.js:95:17)
    at CleartextStream.<anonymous> (_stream_readable.js:765:14)

Reconnect doesn't work very well

I have hubot with slack adapter and it fails to reconnect after connection loss.

# docker logs -f slack-hubot

> [email protected] start /app
> coffee ./node_modules/.bin/hubot --adapter slack

Sat, 13 Dec 2014 13:41:55 GMT connect deprecated multipart: use parser (multiparty, busboy, formidable) npm module instead at node_modules/hubot/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:56:20
Sat, 13 Dec 2014 13:41:55 GMT connect deprecated limit: Restrict request size at location of read at node_modules/hubot/node_modules/express/node_modules/connect/lib/middleware/multipart.js:86:15
[Sat Dec 13 2014 13:41:55 GMT+0000 (UTC)] DEBUG Loading adapter slack
[Sat Dec 13 2014 13:41:55 GMT+0000 (UTC)] INFO Connecting...
[Sat Dec 13 2014 13:41:57 GMT+0000 (UTC)] INFO Logged in as hubot of topface, but not yet connected
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] INFO Slack client now connected
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Loading scripts from /app/scripts
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Parsing help for /app/scripts/deploy.coffee
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Loading scripts from /app/src/scripts
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Loading hubot-scripts from /app/node_modules/hubot-scripts/src/scripts
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Parsing help for /app/node_modules/hubot-scripts/src/scripts/applause.coffee
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Loading external-scripts from npm packages
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Parsing help for /app/node_modules/hubot-help/src/help.coffee
[Sat Dec 13 2014 13:41:58 GMT+0000 (UTC)] DEBUG Parsing help for /app/node_modules/hubot-google-images/src/google-images.coffee
[Sat Dec 13 2014 13:42:02 GMT+0000 (UTC)] DEBUG Received message: '<censored>' in channel: stage-deploy, from: bobrik
[Sat Dec 13 2014 13:47:50 GMT+0000 (UTC)] DEBUG Received message: '<censored>' in channel: stage-deploy, from: ivanpochtar
[Sat Dec 13 2014 13:47:50 GMT+0000 (UTC)] DEBUG Message '<censored>' matched regex //^\s*[@]?hubot[:,]?\s*(?:deploy me (.*)$)/i/
[Sat Dec 13 2014 13:47:50 GMT+0000 (UTC)] DEBUG Sending to stage-deploy: <censored>
[Sat Dec 13 2014 13:52:06 GMT+0000 (UTC)] DEBUG Sending to stage-deploy: <censored>
[Sat Dec 13 2014 13:53:42 GMT+0000 (UTC)] DEBUG Received message: '<censored>' in channel: stage-deploy, from: ivanpochtar
[Sat Dec 13 2014 15:14:46 GMT+0000 (UTC)] DEBUG Received message: '<censored>' in channel: tf-mobile-random, from: topolog
[Sat Dec 13 2014 15:14:56 GMT+0000 (UTC)] DEBUG Received message: '<censored>' in channel: tf-mobile-random, from: topolog
[Sat Dec 13 2014 17:59:35 GMT+0000 (UTC)] DEBUG Received message: '<censored>' in channel: general, from: tony
[Sat Dec 13 2014 22:38:26 GMT+0000 (UTC)] DEBUG Received message: '<https://vk.com/public3861590?w=wall-3861590_1319>' in channel: random, from: amberovsky
[Sat Dec 13 2014 22:53:33 GMT+0000 (UTC)] ERROR Last pong is too old: 14.895
[Sat Dec 13 2014 22:53:33 GMT+0000 (UTC)] INFO Reconnecting in 1000ms
[Sat Dec 13 2014 22:53:33 GMT+0000 (UTC)] INFO Slack client closed
[Sat Dec 13 2014 22:53:34 GMT+0000 (UTC)] INFO Attempting reconnect
[Sat Dec 13 2014 22:53:34 GMT+0000 (UTC)] INFO Connecting...

and then nothing happens.

Is this repo in maintenance mode or deprecated?

I do not see a lot of activity.

The change log is untouched since February.

The README encourage to contribute with pull requests but there are 19 open and some of them have no feedback.
I see a few pull requests that seems pretty safe to merge:

One that seem particularly important for me is that the client cannot be used in node 0.12 or 4.x because the ws module does not compile. It seems that upgrading ws as specified in #47 will fix the problem.

There is also #56 that rebased #22 so it could be merged but because it was not merged promptly, now it needs again some work to be merged.

#66 seems also a good candidate to be merged

On active repositories, PR are either rejected with an explanation or merged. So, is this an obsolete repo? Is a new version of the slack node client about to be released?

@bots isn't populated on login

When connecting to the service, @bots isn't populated in _onLogin. It's only ever modified when bots are added/changed.

team_rename and team_domain_change events

Hey, Guys! I am trying to listen to the team_rename and team_domain_change and, apparently, the library is not firing them.

I can see that the team inside the client is setting the new attributes to the team object, but I do not understand how my code can receive a message (so I cna also update it into my database)

  when "team_rename"
    @team.name = message.name

  when "team_domain_change"
    @team.domain = message.domain

Can you guys help me?

DM In Channel

Is there anyway for a bot to be able to send a DM directly in the channel ? So that other users cannot see it?

Add ability to update messages

To be able to add update functionallity to messages there needs to be a capability put into place in this library. Please see slackapi/hubot-slack#91 for the requirements in hubot.
I'd be happy to implement this capability, however I don't understand in which ways the message can be updated. I've found this method, but it uses the HTTP API: https://api.slack.com/methods/chat.update Is there also a way to do this via the realtime API?

Usage behind proxy

I'm trying to use this library behind a corporate proxy. How can this be configured, if possible?

Handle team_migration_started events

The client seems to be missing handling for team_migration_started events.

[Tue May 26 2015 18:24:22 GMT+0000 (UTC)] DEBUG Unknown message type: team_migration_started
[Tue May 26 2015 18:24:22 GMT+0000 (UTC)] DEBUG { type: 'team_migration_started' }

When this event occurs the client gets disconnected and doesn't get back online. As stated in the docs, a reconnect should be initated when this message is received. This might be related to #5.

Error: stream.push() after EOF

I sometimes get this firing in my app:

Error: stream.push() after EOF

I have a listener:

slack.on('error', function(error) {
  console.error('Error: ', error);
});

but if I look in a debugger, there isn't a listener to the error event on the EventEmitter.

image

This is coming from the rtm.start operation's onreadystatechange

image

Uncaught, unspecififed "error" event

We received the following error last night after upgrading to the new slack hubot adapter:

slack-client-error

I see some reconnect logic here, but the client wasn't able to reconnect for some reason. I had to restart the hubot process for it to successfully reconnect.

I'm not sure if this specific error has been addressed in v1.2.0.

hubot-slack is currently locked to v1.1.0.

Custom Log Handlers

Would it be possible to expose logging rather than having the client handling it itself ? Currently, I have to simply turn it off through the SLACK_LOG_LEVEL env variable.

unable to send a url with <url|Click on this> formatting from my bot

I am using the slack client for my bot and i am trying to send a formatted message with a url as

var content = hello, <www.google.com|Click here> to do some awesome search. 
channel.send(content)

I am expecting to see,
Click here to do some awesome search with Click here hyper linked.
But this is not working.
Help ?

Use full url for api.slack.com

Right now if I use your library on a site being served from file:// it tries to hammer file://api.slack.com:80/api/rtm.start

Cannot upload binary using `files.upload` facet

Version: 2.0.0-beta2

Cannot send binary file to upload via files.upload. I tried using Buffer and ReadStream (via fs.createReadStream) but no luck.

Here's my code (more or less)

var api = new WebClient(token);
var opts = {
  filename: 'test.jpg',
  file: fs.createReadStream('test.jpg')
};
api.files.upload(opts, function (err, res) {
  console.log(res);
  // { ok: false, error: 'no_file_data' }
});

If I call api directly using request module, I can sent them (using r.form())

var r = request.post('https://slack.com/api/files.upload', function (err, res, body) {
  // this works
});

var form = r.form();
form.append(token, token);
form.append('filename', 'test.jpg');
form.append(file, fs.createReadStream('test.jpg');

2.0.0 beta: better name convention

in the constant file, we have:

  OPENING_WEBSOCKET: 'opening_ws',
  OPENED_WEBSOCKET: 'opened_ws',
  WS_CLOSE: 'ws_close',
  WS_ERROR: 'ws_error',

should be better to have:

  WS_OPENING: 'ws_opening',
  WS_OPENED: 'ws_opened',
  WS_CLOSE: 'ws_close',
  WS_ERROR: 'ws_error',

simple.js crashes when slackroom settings are changed

It looks like the module itself has trouble handling events related to team/admin settings:

  1. Create a bot through the Integrations page.
  2. Add its API token to simple.js
  3. node simple.js
  4. Change (as far as I can tell) any admin setting—for example, add a custom username policy:
/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/src/client.js:546
        return this.team.prefs[message.name] = message.value;
                                             ^
TypeError: Cannot set property 'username_policy' of undefined
    at Client.onMessage (/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/src/client.js:546:46)
    at WebSocket.<anonymous> (/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/src/client.js:142:24)
    at WebSocket.emit (events.js:98:17)
    at Receiver.self._receiver.ontext (/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/node_modules/ws/lib/WebSocket.js:697:10)
    at Receiver.opcodes.1.finish (/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/node_modules/ws/lib/Receiver.js:397:14)
    at Receiver.expectHandler (/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/node_modules/ws/lib/Receiver.js:384:31)
    at Receiver.add (/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/node_modules/ws/lib/Receiver.js:93:24)
    at CleartextStream.firstHandler (/Users/cat/Dropbox/projects/bots/slack/nerd/node_modules/slack-client/node_modules/ws/lib/WebSocket.js:678:22)
    at CleartextStream.emit (events.js:95:17)
    at CleartextStream.<anonymous> (_stream_readable.js:765:14)

sending attachments / images?

the demo examples here just send a text response, vis:

+       response = text.split('').reverse().join('');
+       channel.send(response);
+       console.log('@%s responded with "%s"', slack.self.name, response);

can this node package be used to send other types of messages, or attachments?

I've tried sending JSON like:

 if (reply) {
        // channel.send(reply.string);
        msgpack = {
          type: "message",
          text: reply.string,
          icon_url: "http://laorquesta.mx/wp-content/uploads/2014/12/bikers-300x225.jpg",
          attachment: {
            "color": "#36a64f",
            "title": "drifter bot",
            "title_link": "http://superscriptjs.com/starter/quickstart"
          }
        }
        // channel.send(JSON.stringify(msgpack))
        channel.send(msgpack)

but just get an error back:

{ code: 2, msg: 'message text is missing' }

Kicking user from room makes channel object inconsistent from starting outside of room.

When a user is kicked from a channel the channel object is stripped leaving only primitive properties. This removes references to _client which, in turn, throws exceptions when trying to send a message.

If the connection is started with the user outside the room, the _client property is populated and throws a recoverable 'invalid_channel_id' error. This should be consistent, so instead of a keep list on the 'channel_left' event there should be a delete list.

https://github.com/slackhq/node-slack-client/blob/master/src/client.coffee#L418

#channel_leave result
{ id: 'C0XXXXX',
  name: 'random',
  created: 1429047334,
  creator: 'U0XXXX',
  is_archived: false,
  is_general: false,
  is_member: false }
#User starts outside of channel
{ _client:
   { token: 'xoxb-XXXXXXXXXX',
     autoReconnect: false,
     autoMark: true,
     _onSetStatus: [Function],
     _onSetActive: [Function],
     _onSetPresence: [Function],
     _onCreateGroup: [Function],
     _onOpenDM: [Function],
     _onJoinChannel: [Function],
     _onLogin: [Function],
     authenticated: true,
     connected: true,
     self:
      { _client: [Circular],
        id: 'U0XXXX',
        name: 'relay-bot',
        prefs: [Object],
        created: 1429279921,
        manual_presence: 'active' },
     team:
      { _client: [Circular],
        id: 'T0XXXXP7',
        name: 'dkXXXst',
        domain: 'dkXXXst',
        prefs: {} },
     channels:
      { C0XXXX7: [Object],
        C04XXXX99E: [Object],
        C04XXXH: [Circular] },
     dms: { D04XXXX67: [Object], D04XXX69: [Object] },
     groups: {},
     users:
      { U04XXXXU: [Object],
        U0XXXX5: [Object],
        U04XXXXL: [Object],
        U04XXXX5: [Object],
        USLACKBOT: [Object] },
     bots: {},
     socketUrl: 'wss://ms148.slaXXXR4v
Q=',
     ws:
      { _socket: [Object],
        bytesReceived: 551,
        readyState: 1,
        supports: [Object],
        _isServer: false,
        url: 'wss://ms148.slack-XXXR4vQ='
,
        protocolVersion: 13,
        _events: [Object],
        _receiver: [Object],
        _sender: [Object] },
     _messageID: 1,
     _pending: {},
     _connAttempts: 0,
     logger: { level: 6, stream: [Object] },
     _events: { error: [Function], loggedIn: [Function], open: [Function] },
     _lastPong: 1431402947581,
     _pongTimeout:
      { _idleTimeout: 5000,
        _idlePrev: [Object],
        _idleNext: [Object],
        _idleStart: 2085000744,
        _onTimeout: [Function: wrapper],
        _repeat: true } },
  _onInvite: [Function],
  _onRename: [Function],
  _onSetPurpose: [Function],
  _onSetTopic: [Function],
  _onLeave: [Function],
  _onMark: [Function],
  _onFetchHistory: [Function],
  _onPostMessage: [Function],
  _typingTimeout: [Function],
  _typing: {},
  _history: {},
  id: 'C04XXXH',
  name: 'random',
  is_channel: true,
  created: 1429047334,
  creator: 'U0XXX5',
  is_archived: false,
  is_general: false,
  has_pins: false,
  is_member: false }
#properties included when is_member: true
last_read: '1431402495.000016',
  latest:
   { type: 'message',
     user: 'UXXXX65',
     text: 'a',
     ts: '1431402498.000017' },
  unread_count: 1,
  unread_count_display: 0,
  members: [ 'U0XXXX5L', 'U04XXXX5', 'UXXXX5', 'U0XXXXU' ],
  topic: { value: '', creator: '', last_set: 0 },
  purpose:
   { value: 'A place for non-work-related flimflam, faffing, hodge-podge or jibb
er-jabber you\'d prefer to keep out of more focused work-related channels.',
     creator: '',
     last_set: 0 } }

fetchHistory returns true

Disclaimer: I'm not familiar with coffescript, in order to read the source I had to compile channel.coffee to javascript. Here is the JS file I'm interpeting this from: http://sprunge.us/GRSP

I'm hoping to be able to load a channel's history, however, I don't see any history appearing in the console (I believe this is the current behavior), nor being returned by the function, when I use:

  var h = slackChannel.fetchHistory();

  console.log(h);

From what I understand, underneath the hood, after the parameters of fetchHistory are interpreted the client performs an appropriate _apiCall. It populates the api call's with the proper command based on where the bot is (channels.history or groups.history or im.history) and optional range params. Then we have the callback which is supposed to return the history call's data to return this._client.logger.debug(data)

Am I'm misinterpreting something or is the function incomplete?

Missing API Calls

A non-comprehensive list, but the following are API calls that are missing (and could be very useful) from the client.

  • channels.create
  • groups.setTopic
  • groups.setPurpose

Example failing with Error: Cannot find module '..' on MacOS 10.10.2

Sorry if this is a noob problem, as I am new to node.js and coffeescript.

When I try running the steps in example.js, I get the following error:

[RAZORBOAR ~/src/node-slack-client] npm install

> [email protected] install /Users/jelliott/src/node-slack-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
[email protected] node_modules/log

[email protected] node_modules/should

[email protected] node_modules/grunt-shell
└── [email protected]

[email protected] node_modules/coffee-script

[email protected] node_modules/grunt-release
├── [email protected]
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules/mocha
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected] ([email protected])

[email protected] node_modules/grunt-contrib-coffee
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
└── [email protected]

[email protected] node_modules/grunt-contrib-watch
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected])

[email protected] node_modules/grunt
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected])

[email protected] node_modules/ws
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
[RAZORBOAR ~/src/node-slack-client] cd examples
[RAZORBOAR ~/src/node-slack-client/examples] node simple.js 
module.js:338
    throw err;
          ^
Error: Cannot find module '..'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/jelliott/Documents/ws-src/node-slack-client/examples/simple.js:11:13)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

Interestingly, I can run bin/slack no problem:

[RAZORBOAR ~/src/node-slack-client/] bin/slack xoxb-TOKEN
[Tue Feb 17 2015 00:00:26 GMT-0800 (PST)] INFO Connecting...
Welcome to Slack. You are mrroboto of Team funslack
You are in: #general
> /help
Commands:
/msg channel text
/join channel
/leave channel
/quit

With other googling, I've seen some people ask for the npm ls

[RAZORBOAR ~/src/node-slack-client/] npm ls
[email protected] /Users/jelliott/src/node-slack-client
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └─┬ [email protected]
│ │ │   ├── [email protected]
│ │ │   └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   ├─┬ [email protected]
│ │   │ ├── [email protected]
│ │   │ └── [email protected]
│ │   ├── [email protected]
│ │   └─┬ [email protected]
│ │     ├── [email protected]
│ │     └── [email protected]
│ └─┬ [email protected]
│   ├── [email protected]
│   ├── [email protected]
│   ├─┬ [email protected]
│   │ └─┬ [email protected]
│   │   └── [email protected]
│   └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│   ├── [email protected]
│   ├── [email protected]
│   ├── [email protected]
│   ├── [email protected]
│   ├── [email protected]
│   ├── [email protected]
│   ├── [email protected]
│   └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   ├── [email protected]
│ │   └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├── [email protected]
└─┬ [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  └── [email protected]

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.