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.2.5-0 to 0.2.5-1

5

lib/SlackOAuthClient.js

@@ -1,2 +0,2 @@

'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _querystring = require('querystring');var _querystring2 = _interopRequireDefault(_querystring);
'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;};var _querystring = require('querystring');var _querystring2 = _interopRequireDefault(_querystring);

@@ -63,2 +63,3 @@ var _axios = require('axios');var _axios2 = _interopRequireDefault(_axios);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return Promise.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};}

// https://api.slack.com/methods/users.list

@@ -97,3 +98,3 @@

}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) => this.callMethod('chat.postMessage', { channel, text });this.getUserList = cursor => this.callMethod('users.list', { cursor }).then(data => data.members);this.getAllUserList = _asyncToGenerator(function* () {let allUsers = [];let continuationCursor;do {var _ref2 = yield _this.callMethod('users.list', { cursor: continuationCursor });const users = _ref2.members;var _ref2$response_metada = _ref2.response_metadata;_ref2$response_metada = _ref2$response_metada === undefined ? {} : _ref2$response_metada;const next = _ref2$response_metada.next_cursor;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(
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 => data.members);this.getAllUserList = _asyncToGenerator(function* () {let allUsers = [];let continuationCursor;do {var _ref2 = yield _this.callMethod('users.list', { cursor: continuationCursor });const users = _ref2.members;var _ref2$response_metada = _ref2.response_metadata;_ref2$response_metada = _ref2$response_metada === undefined ? {} : _ref2$response_metada;const next = _ref2$response_metada.next_cursor;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);};

2

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

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

@@ -73,2 +73,70 @@ import querystring from 'querystring';

describe('#callMethod', () => {
it('should call slack api', async () => {
const { client, mock } = createMock();
const reply = {
ok: true,
ts: '1405895017.000506',
channel: 'C024BE91L',
message: {},
};
mock
.onPost(
'/chat.postMessage',
querystring.stringify({
channel: CHANNEL,
text: 'hello',
token: TOKEN,
}),
{
'Content-Type': 'application/x-www-form-urlencoded',
}
)
.reply(200, reply);
const res = await client.callMethod('chat.postMessage', {
channel: CHANNEL,
text: 'hello',
});
expect(res).toEqual(reply);
});
it('should throw if slack api return not ok', async () => {
expect.assertions(1);
const { client, mock } = createMock();
const reply = {
ok: false,
error: 'something wrong',
ts: '1405895017.000506',
};
mock
.onPost(
'/chat.postMessage',
querystring.stringify({
channel: CHANNEL,
text: 'hello',
token: TOKEN,
}),
{
'Content-Type': 'application/x-www-form-urlencoded',
}
)
.reply(200, reply);
try {
await client.callMethod('chat.postMessage', {
channel: CHANNEL,
text: 'hello',
});
} catch (e) {
expect(e).toEqual(new Error('something wrong'));
}
});
});
describe('#postMessage', () => {

@@ -103,2 +171,32 @@ it('should call chat.postMessage with channel and text', async () => {

});
it('should call chat.postMessage with channel and text and optional options', async () => {
const { client, mock } = createMock();
const reply = {
ok: true,
ts: '1405895017.000506',
channel: 'C024BE91L',
message: {},
};
mock
.onPost(
'/chat.postMessage',
querystring.stringify({
channel: CHANNEL,
text: 'hello',
as_user: true,
token: TOKEN,
}),
{
'Content-Type': 'application/x-www-form-urlencoded',
}
)
.reply(200, reply);
const res = await client.postMessage(CHANNEL, 'hello', { as_user: true });
expect(res).toEqual(reply);
});
});

@@ -209,2 +307,122 @@

describe('#getAllUserList', () => {
it('should call users.list api', async () => {
const { client, mock } = createMock();
const members = [
{
id: 'U023BECGF',
team_id: 'T021F9ZE2',
name: 'bobby',
deleted: false,
color: '9f69e7',
real_name: 'Bobby Tables',
tz: 'America/Los_Angeles',
tz_label: 'Pacific Daylight Time',
tz_offset: -25200,
profile: {
avatar_hash: 'ge3b51ca72de',
current_status: ':mountain_railway: riding a train',
first_name: 'Bobby',
last_name: 'Tables',
real_name: 'Bobby Tables',
email: 'bobby@slack.com',
skype: 'my-skype-name',
phone: '+1 (123) 456 7890',
image_24: 'https://...',
image_32: 'https://...',
image_48: 'https://...',
image_72: 'https://...',
image_192: 'https://...',
},
is_admin: true,
is_owner: true,
updated: 1490054400,
has_2fa: false,
},
{
id: 'W07QCRPA4',
team_id: 'T0G9PQBBK',
name: 'glinda',
deleted: false,
color: '9f69e7',
real_name: 'Glinda Southgood',
tz: 'America/Los_Angeles',
tz_label: 'Pacific Daylight Time',
tz_offset: -25200,
profile: {
avatar_hash: '8fbdd10b41c6',
image_24: 'https://a.slack-edge.com...png',
image_32: 'https://a.slack-edge.com...png',
image_48: 'https://a.slack-edge.com...png',
image_72: 'https://a.slack-edge.com...png',
image_192: 'https://a.slack-edge.com...png',
image_512: 'https://a.slack-edge.com...png',
image_1024: 'https://a.slack-edge.com...png',
image_original: 'https://a.slack-edge.com...png',
first_name: 'Glinda',
last_name: 'Southgood',
title: 'Glinda the Good',
phone: '',
skype: '',
real_name: 'Glinda Southgood',
real_name_normalized: 'Glinda Southgood',
email: 'glenda@south.oz.coven',
},
is_admin: true,
is_owner: false,
is_primary_owner: false,
is_restricted: false,
is_ultra_restricted: false,
is_bot: false,
updated: 1480527098,
has_2fa: false,
},
];
const reply1 = {
ok: true,
members: [members[0]],
cache_ts: 1498777272,
response_metadata: {
next_cursor: 'cursor1',
},
};
const reply2 = {
ok: true,
members: [members[1]],
cache_ts: 1498777272,
};
mock
.onPost(
'/users.list',
querystring.stringify({
cursor: undefined,
token: TOKEN,
}),
{
'Content-Type': 'application/x-www-form-urlencoded',
}
)
.replyOnce(200, reply1)
.onPost(
'/users.list',
querystring.stringify({
cursor: 'cursor1',
token: TOKEN,
}),
{
'Content-Type': 'application/x-www-form-urlencoded',
}
)
.replyOnce(200, reply2);
const res = await client.getAllUserList();
expect(res).toEqual(members);
});
});
describe('#getUserInfo', () => {

@@ -211,0 +429,0 @@ it('should call users.info with user id', async () => {

@@ -59,5 +59,6 @@ import querystring from 'querystring';

channel: string,
text: string
text: string,
options?: {} = {}
): Promise<SlackOAuthAPIResponse> =>
this.callMethod('chat.postMessage', { channel, text });
this.callMethod('chat.postMessage', { channel, text, ...options });

@@ -64,0 +65,0 @@ // https://api.slack.com/methods/users.list

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