xbytez / slackbotapi Goto Github PK
View Code? Open in Web Editor NEWnode.js Slack RTM API module
License: GNU Lesser General Public License v3.0
node.js Slack RTM API module
License: GNU Lesser General Public License v3.0
When there is a network problem it appears that no timeout occurs. This prevents being able to reconnect.
The constructor performs asynchronous request to the Slack rtm.start method. The getChannel method of this module relies on the information gathered from this request and may fail when called right after construction.
Hi,
It would be great if you could add an example HTML page using this API. I'm trying to use it at the moment but I keep getting the following error: "Uncaught ReferenceError: require is not defined".
I would be greatly appreciated if you could add this example to clear things up on how we can implement this into a web app.
Thanks,
Cathal.
Thank you man! This package is awesome to use! โค๏ธ
Hi all, great work on the code!
Is there a way to know if a message sent is a direct message?
23:09 56s 943ms [Transport] [SlackAPI] Recieved: {"type":"hello"}
23:13 31s 360ms [Transport] [SlackAPI] Recieved: {"type":"message","channel":"....","user":"....","text":"%debug","ts":"1440717210.0000
32","team":"...."}
/example.js:47
console.log(slack.data.ims);
^
TypeError: Cannot read property 'ims' of undefined
I feel like our README could use an image to further improve the looks of the README. Also a good hacktoberfest entry. No need to ask, feel free to submit a PR.
Feel free to take a look at the other issues as well.
On the lines:
https://github.com/xBytez/slackbotapi/blob/master/index.js#L91
https://github.com/xBytez/slackbotapi/blob/master/index.js#L100
process.exit(1)
is called, which fatally stops the current script from running. There is a use case where the caller might create an API instance as a response to an HTTP request that provides a token, for example, suppose the developer is creating a means of "installing" a bot by responding to a user who inputs a token - in this scenario the developer's "bot" is hosted on a server that runs on multiple slack clients.
If one user submits the token 'notvalid', the app crashes and the other users, who's tokens are valid, are left in the dark.
It is far better to throw errors instead.
There is a typo in the example file:
var slackAPI = require('slackAPI');
Should be:
var slackAPI = require('slackbotapi');
Using the example code, I get this error:
url.js:110
throw new TypeError("Parameter 'url' must be a string, not " + typeof url)
^
TypeError: Parameter 'url' must be a string, not undefined
at Url.parse (url.js:110:11)
at Object.urlParse [as parse] (url.js:104:5)
at WebSocket.initAsClient (./node_modules/ws/lib/WebSocket.js:550:23)
at new WebSocket (./node_modules/ws/lib/WebSocket.js:74:18)
at slackAPI.connectSlack (./node_modules/slackbotapi/index.js:172:15)
at ./node_modules/slackbotapi/index.js:121:14
at Request._callback (./node_modules/slackbotapi/index.js:142:24)
at Request.self.callback (./node_modules/request/request.js:198:22)
at Request.emit (events.js:110:17)
at Request.<anonymous> (./node_modules/request/request.js:1063:14)
deleted
This project has gotten kind of stale with out-of-date dependencies. It still works but could use some updates.
Feel free to look at the other issues too.
Please test before submitting PRs.
I am trying to PM a user when they join the team.
/home/ubuntu/node_modules/slackbotapi/index.js:238
for (var i in self.slackData.ims) {
^
ReferenceError: self is not defined
at slackAPI.getIM (/home/ubuntu/node_modules/slackbotapi/index.js:238:19)
I even tried defining self = this
there (probably not the right thing to do), but also no luck:
/home/ubuntu/node_modules/slackbotapi/index.js:245
if (self.slackData.ims[i_]['user'] === this.getUser(term).id) {
^
TypeError: Cannot read property 'id' of null
The code I'm using:
slack.on('team_join', function (data) {
slack.sendPM(data.user.id, "Welcome @" + data.user.name + "!");
});
TypeError: Cannot call method 'slice' of undefined
at EventEmitter.emit (/srv/www/experiments/ee-slackbot/node_modules/slackbotapi/node_modules/eventemitter2/lib/eventemitter2.js:302:77)
Got this weird problem where whenever I post a message using the slack.sendMsg
it emites an error event after the message has been sent containing a normal message sent response
{
ok: true,
reply_to: 0,
ts: '1470627489.001015',
text: 'text'
}
Any idea why it would be doing this?
This could be considered a more general JavaScript question.
I've made a 'greeter' bot - when someone joins, it'll message them a series of things.
For me to do this, I've needed to re-instantiate the slackAPI when someone joins:
slack.on('team_join', function (data) {
slack = new slackAPI({
'token': "abcdedfg",
'logging': true
});
I believe this resulted in multiple slackAPI instances being instantiated, and due to the lack of my JavaScript knowledge I do not know a better way to handle this.
The below code needs to be triggered to refresh the user list, as trying to PM a new user that has joined will error:
self.reqAPI('rtm.start', {}, function (data) {
self.slackData.self = data.self;
self.slackData.team = data.team;
self.slackData.channels = data.channels;
self.slackData.groups = data.groups;
self.slackData.users = data.users;
self.slackData.ims = data.ims;
self.connectSlack(data.url, function(err, data){
if (!err){
self.emit(events[data.type], data);
}
});
});
Any help is appreciated!
I'm getting
TypeError: self.ws.on is not a function
at slackAPI.213.slackAPI.connectSlack (index.js:174)
at index.js:121
at Request._callback (index.js:142)
at Request.322.Request.init.self.callback (request.js:198)
at Request.166.EventEmitter.emit (events.js:80)
at Request.<anonymous> (request.js:1073)
at Request.166.EventEmitter.emit (events.js:99)
at null.<anonymous> (request.js:1019)
at 166.EventEmitter.emit (events.js:99)
at endReadableNT (_stream_readable.js:944)
If I put a debugger, I see that self.ws
has a onClose
and an onOpen
, etc, but no on
. Is there a version mismatch somewhere? When I installed I ended up with version 0.8.0 of ws
.
This lib does not have any unit or integration tests yet.
I encountered a problem where the bot was disconnected from the internet, and the app didn't crash, nor try to connect again.
Since commit 9cb065e the bot won't connect anymore since this.token was changed to this.authtoken but not in the reqAPI function.
This project has gotten kind of stale with out-of-date dependencies. It still works but could use some updates.
Feel free to look at the other issues too.
This renders the greenkeeper bot PRs useless. You can ignore them and create one PR with all dependencies updated. Please extensively test before submitting PRs.
Hi again, do you know if it is possible to start a DM with a user just by the user ID/username? For example, to DM a user when they first join a Slack group.
I'm interested to see this bot support incoming webhooks in addition to the RTM api. The reason, I want to send the bot json payloads from other services, and have it post to channels using RTM.
I was testing multiple events using your code and I noticed that this block of code
} else if (data.type === 'presence_change') {
// update slackData presence when user becomes active/inactive
for (var i in self.slackData.users) {
if (self.slackData.users[i].id === data.user) {
self.slackData.users[i].presence = data.presence;
break;
}
}
}
is blocking the bot from processing presence_change
events.
Adding cb(null, messageData);
after the for loop easily solve this problem.
https://github.com/xBytez/slackbotapi/blob/master/lib/rtm.js#L240
There are a couple of fishy things going on when initializing the logger. I'll try a workaround for the moment, but you may want to check out this code.
logger = true;
logger.init();
https://github.com/xBytez/slackbotapi/blob/master/index.js#L89
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.