npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodejslack

v1.4.0

Published

Slack APIs methods and WS ready to use in nodejs

Downloads

324

Readme

Nodejslack

Start using Slack's Web API in an easy way through this Node.js library.

Also, this library is built using the Promises pattern, powered by Bluebird .

Installation

npm install nodejslack

Methods

Bots

  • getBotInfo(id) (return: promise) - Gets information about a Bot

Channels

  • archiveChannel(id) (return: promise) - Archives a channel,
  • createChannel(name) (return: promise) - Creates a channel,
  • getChannelHistory(data) (return: promise) - Gets the history of a channel,
  • getChannelInfo(id) (return: promise) - Gets info of a channel,
  • inviteUserToChannel(channelId, userId) (return: promise) - Invites a user to a channel,
  • joinChannel(channelName) (return: promise) - Join(user) to a channel,
  • kickUserFromChannel(channelId, userId) (return: promise) - Kicks a user from a channel,
  • leaveChannelfunction(channelId) (return: promise) - Leaves a channel,
  • getChannels() (return: promise) - Get all channels,
  • markChannel(channelId, ts) (return: promise) - Moves the read cursor in a channel,
  • renameChannel(channelId, name) (return: promise) - Renames a channel,
  • setPurposeChannel(channelId, purpose) (return: promise) - Sets a purpose of a channel,
  • setTopicChannel(channelId, topic) (return: promise) - Sets a topic of a channel,
  • unarchiveChannel(channelId) (return: promise) - Unarchives a channel

Chats

  • meMessage(channelId, text) (return: promise) - Sends a me message to a channel from the calling user,
  • deleteMessage(ts, channelId, asUser) (return: promise) - Deletes a message,
  • postMessage(data) (return: promise) - Posts a message,
  • updateMessage(data) (return: promise) - Updates a message

dnd(Do not Disturb)

  • endDnd() (return: promise) - Ends dnd(Do not disturb) mode,
  • endSnooze() (return: promise) - Ends Snooze mode,
  • dndInfo(user) (return: promise) - Provides information about a user's current Do Not Disturb settings,
  • setSnooze(minutes) (return: promise) - Sets Snooze mode,
  • dndTeamInfo(users) (return: promise) - Provides information about a Team's Do Not Disturb settings

Emoji

  • getEmojiList() (return: promise) - Gets Emoji List

Files

  • fileUpload(params) (return: promise) - uploads a file,
  • getFilesList(params) (return: promise) - returns a list of uploaded files,
  • getFileInfo(id, count, page) (return: promise) - returns informations about the specified file
  • deleteFile(id) (return: promise) - Delete specified file
  • fileRevokePublicURL(id) (return: promise) - Disables public URL the specified file
  • fileEnablePublicURL(id) (return: promise) - Enables public URL the specified file

Files.comment

  • fileAddComment(id, comment) (return: promise) - Add a comment to a file,
  • fileEditComment(id, fileId, comment) (return: promise) - Edit an existing comment about a file
  • fileDeleteComment(id, fileId) (return: promise) - Delete a comment about a file

Users

  • deleteUserPhoto() (return: promise) - Deletes a photo from the user's profile,
  • getUserPresence(id) (return: promise) - Gets user's presence,
  • getUserIdentity() (return: promise) - Gets user's identity,
  • getUserInfo(id) (return: promise) - Gets user's info,
  • getUsersList() (return: promise) - Gets all users,
  • setUserActive() (return: promise) - Sets user's as active,
  • setUserPhoto(data) (return: promise) - Sets a photo to the user's profile,
  • setUserPresence(presence) (return: promise) - Sets user's presence(Either "auto" or "away")

Usage

slack.fileUpload(params)

var Slack = require('nodejslack');
var fs = require('fs');
var SLACK_TOKEN = process.env.SLACK_TOKEN || 'YOUR_GENERATED_SLACK_TOKEN';

var slack = new Slack(SLACK_TOKEN);

var form = {
  file: fs.createReadStream('test.csv'), // Optional, via multipart/form-data. If omitting this parameter, you MUST submit content
  // content: 'Your text here', // Optional, File contents. If omitting this parameter, you must provide a `file` 
  filename: 'test.csv', // Required 
  fileType: 'post', // Optional, See more file types in https://api.slack.com/types/file#file_types
  title: 'Title of your file!', // Optional
  initial_comment: 'First comment about this file.', // Optional
  channels: 'general' //Optional, If you want to put more than one channel, separate using comma, example: 'general,random'
};

slack.fileUpload(form)
.then(function(response){

	// Slack sends a json with a boolean var ok. 
	// Error example : data = { ok: false, error: 'user_not_found' }
	// Error example : data = { ok: true, file: 'user_not_found' }
	if(!response || !response.ok){
		return Promise.reject(new Error('Something wrong happened during the upload.'));
	}
	console.log('Uploaded Successfully:',response);

	return Promise.resolve(response);
})
.catch(function(err){
	return err;
});

slack.getFilesList(params)

var Slack = require('nodejslack');
var fs = require('fs');
var SLACK_TOKEN = process.env.SLACK_TOKEN || 'YOUR_GENERATED_SLACK_TOKEN';

var slack = new Slack(SLACK_TOKEN);

var form = {
  user: 'USER_ID', // Optional, User ID
  channel: 'CHANNEL_ID', // Optional, Channel ID
  ts_from: 342353452342, // Optional, Filter(Unix Timestamp) files created after this timestamp (inclusive).
  ts_to: 342353452342, // Optional, Filter(Unix Timestamp) files created before this timestamp (inclusive).
  types: 'zips,pdfs', // Optional, Filter files by type: all, spaces, snippets, images, gdocs, zips, pdfs.
  count: 20 // Optional, default: 100
  page: 2 // Optional, default: 1
};

slack.getFilesList(form)
.then(function(response){

	// Slack sends a json with a boolean var ok. 
	// Error example : data = { ok: false, error: 'user_not_found' }
	// Error example : data = { ok: true, file: 'user_not_found' }
	if(!response || !response.ok){
		return Promise.reject(new Error('Something wrong happened during the request.'));
	}
	console.log('List of files:',response);

	return Promise.resolve(response);
})
.catch(function(err){
	return err;
});

slack.getFileInfo(id, count, page)

var Slack = require('nodejslack');
var fs = require('fs');
var SLACK_TOKEN = process.env.SLACK_TOKEN || 'YOUR_GENERATED_SLACK_TOKEN';

var slack = new Slack(SLACK_TOKEN);


var fileId = 'UH45344543'; // File ID
var count = 20; // Optional, Number of items to return per page.
var page = 2; // Optional, Page number of results to return.

slack.getFileInfo(fileId, count, page)
.then(function(response){

	// Slack sends a json with a boolean var ok. 
	// Error example : data = { ok: false, error: 'user_not_found' }
	// Error example : data = { ok: true, file: 'user_not_found' }
	if(!response || !response.ok){
		return Promise.reject(new Error('Something wrong happened during the request.'));
	}
	console.log('File Info:',response);

	return Promise.resolve(response);
})
.catch(function(err){
	return err;
});

slack.deleteFile(id)

var Slack = require('nodejslack');
var fs = require('fs');
var SLACK_TOKEN = process.env.SLACK_TOKEN || 'YOUR_GENERATED_SLACK_TOKEN';

var slack = new Slack(SLACK_TOKEN);


var fileId = 'UH45344543'; // File ID

slack.deleteFile(fileId)
.then(function(response){

	// Slack sends a json with a boolean var ok. 
	// Error example : data = { ok: false, error: 'user_not_found' }
	// Error example : data = { ok: true, file: 'user_not_found' }
	if(!response || !response.ok){
		return Promise.reject(new Error('Something wrong happened during the request.'));
	}
	console.log('File successfully deleted:',response);

	return Promise.resolve(response);
})
.catch(function(err){
	return err;
});

slack.fileRevokePublicURL(id)

var Slack = require('nodejslack');
var fs = require('fs');
var SLACK_TOKEN = process.env.SLACK_TOKEN || 'YOUR_GENERATED_SLACK_TOKEN';

var slack = new Slack(SLACK_TOKEN);


var fileId = 'UH45344543'; // File ID

slack.fileRevokePublicURL(fileId)
.then(function(response){

	// Slack sends a json with a boolean var ok. 
	// Error example : data = { ok: false, error: 'user_not_found' }
	// Error example : data = { ok: true, file: 'user_not_found' }
	if(!response || !response.ok){
		return Promise.reject(new Error('Something wrong happened during the request.'));
	}
	console.log('File URL successfully disabled:',response);

	return Promise.resolve(response);
})
.catch(function(err){
	return err;
});

slack.fileEnablePublicURL(id)

var Slack = require('nodejslack');
var fs = require('fs');
var SLACK_TOKEN = process.env.SLACK_TOKEN || 'YOUR_GENERATED_SLACK_TOKEN';

var slack = new Slack(SLACK_TOKEN);


var fileId = 'UH45344543'; // File ID

slack.fileEnablePublicURL(fileId)
.then(function(response){

	// Slack sends a json with a boolean var ok. 
	// Error example : data = { ok: false, error: 'user_not_found' }
	// Error example : data = { ok: true, file: 'user_not_found' }
	if(!response || !response.ok){
		return Promise.reject(new Error('Something wrong happened during the request.'));
	}
	console.log('File URL successfully enabled:',response);

	return Promise.resolve(response);
})
.catch(function(err){
	return err;
});
  • fileAddComment(id, comment) (return: promise) - Add a comment to a file,
  • fileEditComment(id, fileId, comment) (return: promise) - Edit an existing comment about a file
  • fileDeleteComment(id, fileId) (return: promise) - Delete a comment about a file

slack.fileAddComment(id, comment) + slack.fileEditComment(id, fileId, comment) + slack.fileDeleteComment(id, fileId)

var Slack = require('nodejslack');
var fs = require('fs');
var SLACK_TOKEN = process.env.SLACK_TOKEN || 'YOUR_GENERATED_SLACK_TOKEN';

var slack = new Slack(SLACK_TOKEN);


var fileId = 'UH45344543'; // File ID

slack.fileAddComment(fileId, 'New Comment being added')
.then(function(answer){
	if (!answer.ok && answer.error) {
		return Promise.reject(new Error(answer.error));
	}
	console.log('Comment Added:',answer);
	
	return slack.fileEditComment(answer.comment.id, fileId, 'New Comment being edited');
})
.then(function(answer){
	if (!answer.ok && answer.error) {
		return Promise.reject(new Error(answer.error));
	}
	console.log('Comment Edited:',answer);
	
	return slack.fileDeleteComment(answer.comment.id, fileId);
})

.then(function(answer){
	if (!answer.ok && answer.error) {
		return Promise.reject(new Error(answer.error));
	}
	console.log('Comment Deleted:',answer);
	
	return Promise.resolve(answer);
})
.catch(function(err){
	console.log('Did not ADD/EDIT/DELETE File Comment:',err);
	return err;
});