New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

messaging-api-slack

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

messaging-api-slack - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

69

lib/SlackOAuthClient.js

@@ -24,2 +24,20 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};

class SlackOAuthClient {

@@ -61,3 +79,2 @@

// https://api.slack.com/methods/chat.postMessage

@@ -67,6 +84,10 @@

/**
* Gets information about a channel.
*
* https://api.slack.com/methods/channels.info
*/
// https://api.slack.com/methods/users.list

@@ -77,5 +98,16 @@

/**
* Lists all channels in a Slack team.
*
* https://api.slack.com/methods/channels.list
* FIXME: [breaking] support cursor, exclude_archived, exclude_members, limit
*/
/**
* Sends a message to a channel.
*
* https://api.slack.com/methods/chat.postMessage
*/

@@ -88,2 +120,7 @@

/**
* Gets information about a user.
*
* https://api.slack.com/methods/users.info
*/

@@ -97,15 +134,31 @@

/**
* Lists all users in a Slack team.
*
* https://api.slack.com/methods/users.list
* FIXME: [breaking] support include_locale, limit, presence
*/}exports.default = SlackOAuthClient;SlackOAuthClient.connect = token => new SlackOAuthClient(token);var _initialiseProps = function _initialiseProps() {var _this = this;this.getHTTPClient = () => this._http;this.callMethod = (method, body = {}) => {body.token = this._token; // eslint-disable-line no-param-reassign
return this._http.post(method, _querystring2.default.stringify(body)).then(res => {if (!res.data.ok) {const error = new Error(`Slack API error: ${res.data.error}`);error.config = res.config;error.headers = res.headers;error.data = res.data;throw error;}return res.data;});};this.getChannelInfo = (channelId, options = {}) => this.callMethod('channels.info', _extends({ channel: channelId }, options)).then(data => data.channel);this.getChannelList = () => this.callMethod('channels.list').then(data => data.channels);this.postMessage = (channel, text, options = {}) => this.callMethod('chat.postMessage', _extends({ channel, text }, options));this.getUserInfo = (userId, options = {}) => this.callMethod('users.info', _extends({ user: userId }, options)).then(data => data.user);this.getUserList =
cursor =>
this.callMethod('users.list', { cursor }).then(data => ({
members: data.members,
next: data.response_metadata && data.response_metadata.next_cursor }));this.
// https://api.slack.com/methods/users.info
getAllUserList = _asyncToGenerator(function* () {
let allUsers = [];
let continuationCursor;
do {var _ref2 =
// https://api.slack.com/methods/channels.list
// https://api.slack.com/methods/channels.info
}exports.default = SlackOAuthClient;SlackOAuthClient.connect = token => new SlackOAuthClient(token);var _initialiseProps = function _initialiseProps() {var _this = this;this.getHTTPClient = () => this._http;this.callMethod = (method, body = {}) => {body.token = this._token; // eslint-disable-line no-param-reassign
return this._http.post(method, _querystring2.default.stringify(body)).then(res => {if (!res.data.ok) {throw new Error(res.data.error);}return res.data;});};this.postMessage = (channel, text, options = {}) => this.callMethod('chat.postMessage', _extends({ channel, text }, options));this.getUserList = cursor => this.callMethod('users.list', { cursor }).then(data => ({ members: data.members, next: data.response_metadata && data.response_metadata.next_cursor }));this.getAllUserList = _asyncToGenerator(function* () {let allUsers = [];let continuationCursor;do {var _ref2 = yield _this.getUserList(continuationCursor);const users = _ref2.members,next = _ref2.next;allUsers = allUsers.concat(users);continuationCursor = next;} while (continuationCursor);return allUsers;});this.getUserInfo = userId => this.callMethod('users.info', { user: userId }).then(data => data.user);this.getChannelList = () => this.callMethod('channels.list').then(data => data.channels);this.getChannelInfo = channelId => this.callMethod('channels.info', { channel: channelId }).then(
data => data.channel);};
yield _this.getUserList(continuationCursor);const users = _ref2.members,next = _ref2.next;
allUsers = allUsers.concat(users);
continuationCursor = next;
} while (continuationCursor);
return allUsers;
});};

2

package.json
{
"name": "messaging-api-slack",
"description": "Messaging API client for Slack",
"version": "0.4.2",
"version": "0.4.3",
"engines": {

@@ -6,0 +6,0 @@ "node": ">=6"

@@ -136,3 +136,3 @@ import querystring from 'querystring';

} catch (e) {
expect(e).toEqual(new Error('something wrong'));
expect(e).toEqual(new Error('Slack API error: something wrong'));
}

@@ -139,0 +139,0 @@ });

@@ -9,5 +9,5 @@ /* @flow */

SlackOAuthAPIResponse,
AvailableMethod,
User,
Channel,
SlackAvailableMethod,
SlackUser,
SlackChannel,
} from './SlackTypes';

@@ -25,2 +25,20 @@

type PostMessageOptions = {
as_user?: boolean,
attachments?: string,
icon_emoji?: string,
icon_url?: string,
link_names?: boolean,
parse?: 'none' | 'full',
reply_broadcast?: boolean,
thread_ts?: string,
unfurl_links?: boolean,
unfurl_media?: boolean,
username?: string,
};
type GetInfoOptions = {
include_locale?: boolean,
};
export default class SlackOAuthClient {

@@ -50,3 +68,3 @@ static connect = (token: Token): SlackOAuthClient =>

callMethod = (
method: AvailableMethod,
method: SlackAvailableMethod,
body: Object = {}

@@ -57,3 +75,7 @@ ): Promise<SlackOAuthAPIResponse> => {

if (!res.data.ok) {
throw new Error(res.data.error);
const error = (new Error(`Slack API error: ${res.data.error}`): Object);
error.config = res.config;
error.headers = res.headers;
error.data = res.data;
throw error;
}

@@ -64,14 +86,58 @@ return res.data;

// https://api.slack.com/methods/chat.postMessage
/**
* Gets information about a channel.
*
* https://api.slack.com/methods/channels.info
*/
getChannelInfo = (
channelId: string,
options: GetInfoOptions = {}
): Promise<SlackChannel> =>
this.callMethod('channels.info', { channel: channelId, ...options }).then(
data => data.channel
);
/**
* Lists all channels in a Slack team.
*
* https://api.slack.com/methods/channels.list
* FIXME: [breaking] support cursor, exclude_archived, exclude_members, limit
*/
getChannelList = (): Promise<Array<SlackChannel>> =>
this.callMethod('channels.list').then(data => data.channels);
/**
* Sends a message to a channel.
*
* https://api.slack.com/methods/chat.postMessage
*/
postMessage = (
channel: string,
text: string,
options?: {} = {}
options?: PostMessageOptions = {}
): Promise<SlackOAuthAPIResponse> =>
this.callMethod('chat.postMessage', { channel, text, ...options });
// https://api.slack.com/methods/users.list
/**
* Gets information about a user.
*
* https://api.slack.com/methods/users.info
*/
getUserInfo = (
userId: string,
options: GetInfoOptions = {}
): Promise<SlackUser> =>
this.callMethod('users.info', { user: userId, ...options }).then(
data => data.user
);
/**
* Lists all users in a Slack team.
*
* https://api.slack.com/methods/users.list
* FIXME: [breaking] support include_locale, limit, presence
*/
getUserList = (
cursor?: string
): Promise<{ members: Array<User>, next: ?string }> =>
): Promise<{ members: Array<SlackUser>, next: ?string }> =>
this.callMethod('users.list', { cursor }).then(data => ({

@@ -82,3 +148,3 @@ members: data.members,

getAllUserList = async (): Promise<Array<User>> => {
getAllUserList = async (): Promise<Array<SlackUser>> => {
let allUsers = [];

@@ -99,16 +165,2 @@ let continuationCursor;

};
// https://api.slack.com/methods/users.info
getUserInfo = (userId: string): Promise<User> =>
this.callMethod('users.info', { user: userId }).then(data => data.user);
// https://api.slack.com/methods/channels.list
getChannelList = (): Promise<Array<Channel>> =>
this.callMethod('channels.list').then(data => data.channels);
// https://api.slack.com/methods/channels.info
getChannelInfo = (channelId: string): Promise<Channel> =>
this.callMethod('channels.info', { channel: channelId }).then(
data => data.channel
);
}
/* @flow */
export type Attachment = {
export type SlackAttachment = {
fallback: string,

@@ -32,10 +32,130 @@ pretext?: string,

export type AvailableMethod =
| 'chat.postMessage'
export type SlackAvailableMethod =
| 'api.test'
| 'apps.permissions.info'
| 'apps.permissions.request'
| 'auth.revoke'
| 'auth.test'
| 'bots.info'
| 'channels.archive'
| 'channels.create'
| 'channels.history'
| 'channels.info'
| 'channels.invite'
| 'channels.join'
| 'channels.kick'
| 'channels.leave'
| 'channels.list'
| 'channels.mark'
| 'channels.rename'
| 'channels.replies'
| 'channels.setPurpose'
| 'channels.setTopic'
| 'channels.unarchive'
| 'chat.delete'
| 'chat.meMessage'
| 'chat.postEphemeral'
| 'chat.postMessage'
| 'chat.unfurl'
| 'chat.update'
| 'conversations.archive'
| 'conversations.close'
| 'conversations.create'
| 'conversations.history'
| 'conversations.info'
| 'conversations.invite'
| 'conversations.join'
| 'conversations.kick'
| 'conversations.leave'
| 'conversations.list'
| 'conversations.members'
| 'conversations.open'
| 'conversations.rename'
| 'conversations.replies'
| 'conversations.setPurpose'
| 'conversations.setTopic'
| 'conversations.unarchive'
| 'dnd.endDnd'
| 'dnd.endSnooze'
| 'dnd.info'
| 'dnd.setSnooze'
| 'dnd.teamInfo'
| 'emoji.list'
| 'files.comments.add'
| 'files.comments.delete'
| 'files.comments.edit'
| 'files.delete'
| 'files.info'
| 'files.list'
| 'files.revokePublicURL'
| 'files.sharedPublicURL'
| 'files.upload'
| 'groups.archive'
| 'groups.create'
| 'groups.createChild'
| 'groups.history'
| 'groups.info'
| 'groups.invite'
| 'groups.kick'
| 'groups.leave'
| 'groups.list'
| 'groups.mark'
| 'groups.open'
| 'groups.rename'
| 'groups.replies'
| 'groups.setPurpose'
| 'groups.setTopic'
| 'groups.unarchive'
| 'im.close'
| 'im.history'
| 'im.list'
| 'im.mark'
| 'im.open'
| 'im.replies'
| 'oauth.access'
| 'oauth.token'
| 'pins.add'
| 'pins.list'
| 'pins.remove'
| 'reactions.add'
| 'reactions.get'
| 'reactions.list'
| 'reactions.remove'
| 'reminders.add'
| 'reminders.complete'
| 'reminders.delete'
| 'reminders.info'
| 'reminders.list'
| 'rtm.connect'
| 'rtm.start'
| 'search.all'
| 'search.files'
| 'search.messages'
| 'stars.add'
| 'stars.list'
| 'stars.remove'
| 'team.accessLogs'
| 'team.billableInfo'
| 'team.info'
| 'team.integrationLogs'
| 'team.profile.get'
| 'usergroups.create'
| 'usergroups.disable'
| 'usergroups.enable'
| 'usergroups.list'
| 'usergroups.update'
| 'usergroups.users.list'
| 'usergroups.users.update'
| 'users.deletePhoto'
| 'users.getPresence'
| 'users.identity'
| 'users.info'
| 'users.list';
| 'users.list'
| 'users.setActive'
| 'users.setPhoto'
| 'users.setPresence'
| 'users.profile.get'
| 'users.profile.set';
export type User = {
export type SlackUser = {
id: string,

@@ -46,6 +166,6 @@ name: string,

export type Channel = {
export type SlackChannel = {
id: string,
name: string,
members?: Array<User>,
members?: Array<SlackUser>,
};

@@ -5,3 +5,3 @@ /* @flow */

import type { Attachment, SendMessageSucessResponse } from './SlackTypes';
import type { SlackAttachment, SendMessageSucessResponse } from './SlackTypes';

@@ -16,6 +16,6 @@ type Axios = {

type Url = string;
type URL = string;
export default class SlackWebhookClient {
static connect = (url: Url): SlackWebhookClient =>
static connect = (url: URL): SlackWebhookClient =>
new SlackWebhookClient(url);

@@ -25,3 +25,3 @@

constructor(url: Url) {
constructor(url: URL) {
// incoming webhooks

@@ -50,8 +50,8 @@ // https://api.slack.com/incoming-webhooks

sendAttachments = (
attachments: Array<Attachment>
attachments: Array<SlackAttachment>
): Promise<SendMessageSucessResponse> => this.sendRawBody({ attachments });
sendAttachment = (
attachment: Attachment
attachment: SlackAttachment
): Promise<SendMessageSucessResponse> => this.sendAttachments([attachment]);
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc