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
3
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.5.7 to 0.5.10

12

lib/SlackOAuthClient.js

@@ -238,2 +238,8 @@ '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;};

/**

@@ -258,5 +264,5 @@ * Gets information about a user.

*/}exports.default = SlackOAuthClient;SlackOAuthClient.connect = token => new SlackOAuthClient(token);var _initialiseProps = function _initialiseProps() {var _this = this;this.getHTTPClient = () => {(0, _warning2.default)(false, '`.getHTTPClient` method is deprecated. use `.axios` getter instead.');return this._axios;};this.callMethod = (() => {var _ref = _asyncToGenerator(function* (method, body = {}) {body.token = _this._token; // eslint-disable-line no-param-reassign
const response = yield _this._axios.post(method, _querystring2.default.stringify(body));const data = response.data,config = response.config,request = response.request;if (!data.ok) {throw new _axiosError2.default(`Slack API - ${data.error}`, { config, request, response });}return data;});return function (_x) {return _ref.apply(this, arguments);};})();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.getConversationInfo = (channelId, options = {}) => this.callMethod('conversations.info', _extends({ channel: channelId }, options)).then(data => data.channel);this.getConversationMembers = (channelId, options = {}) => this.callMethod('conversations.members', _extends({ channel: channelId }, options)).then(data => ({ members: data.members, next: data.response_metadata && data.response_metadata.next_cursor }));this.getAllConversationMembers = (() => {var _ref2 = _asyncToGenerator(function* (channelId) {let allMembers = [];let continuationCursor;do {var _ref3 = yield _this.getConversationMembers(channelId, { cursor: continuationCursor });const members = _ref3.members,next = _ref3.next;allMembers = allMembers.concat(members);continuationCursor = next;} while (continuationCursor);return allMembers;});return function (_x2) {return _ref2.apply(this, arguments);};})();this.getConversationList = (options = {}) => this.callMethod('conversations.list', options).then(data => ({ channels: data.channels, next: data.response_metadata && data.response_metadata.next_cursor }));this.getAllConversationList = (() => {var _ref4 = _asyncToGenerator(function* (options = {}) {let allChannels = [];let continuationCursor;do {var _ref5 = yield _this.getConversationList(_extends({}, options, { cursor: continuationCursor }));const channels = _ref5.channels,next = _ref5.next;allChannels = allChannels.concat(channels);continuationCursor = next;} while (continuationCursor);return allChannels;});return function () {return _ref4.apply(this, arguments);};})();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 =>
const response = yield _this._axios.post(method, _querystring2.default.stringify(body));const data = response.data,config = response.config,request = response.request;if (!data.ok) {throw new _axiosError2.default(`Slack API - ${data.error}`, { config, request, response });}return data;});return function (_x) {return _ref.apply(this, arguments);};})();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.getConversationInfo = (channelId, options = {}) => this.callMethod('conversations.info', _extends({ channel: channelId }, options)).then(data => data.channel);this.getConversationMembers = (channelId, options = {}) => this.callMethod('conversations.members', _extends({ channel: channelId }, options)).then(data => ({ members: data.members, next: data.response_metadata && data.response_metadata.next_cursor }));this.getAllConversationMembers = (() => {var _ref2 = _asyncToGenerator(function* (channelId) {let allMembers = [];let continuationCursor;do {var _ref3 = yield _this.getConversationMembers(channelId, { cursor: continuationCursor });const members = _ref3.members,next = _ref3.next;allMembers = allMembers.concat(members);continuationCursor = next;} while (continuationCursor);return allMembers;});return function (_x2) {return _ref2.apply(this, arguments);};})();this.getConversationList = (options = {}) => this.callMethod('conversations.list', options).then(data => ({ channels: data.channels, next: data.response_metadata && data.response_metadata.next_cursor }));this.getAllConversationList = (() => {var _ref4 = _asyncToGenerator(function* (options = {}) {let allChannels = [];let continuationCursor;do {var _ref5 = yield _this.getConversationList(_extends({}, options, { cursor: continuationCursor }));const channels = _ref5.channels,next = _ref5.next;allChannels = allChannels.concat(channels);continuationCursor = next;} while (continuationCursor);return allChannels;});return function () {return _ref4.apply(this, arguments);};})();this.postMessage = (channel, text, options = {}) => {if (options.attachments && typeof options.attachments !== 'string') {// A JSON-based array of structured attachments, presented as a URL-encoded string.
// eslint-disable-next-line no-param-reassign
options.attachments = JSON.stringify(options.attachments);}return 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 => ({

@@ -263,0 +269,0 @@ members: data.members,

{
"name": "messaging-api-slack",
"description": "Messaging API client for Slack",
"version": "0.5.7",
"version": "0.5.10",
"engines": {

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

@@ -89,2 +89,26 @@ # messaging-api-slack

If you send message with `attachments`, `messaging-api-slack` will automatically stringify the `attachments` field for you.
```js
client.postMessage('C8763', 'Hello!', {
as_user: true,
attachments: [
{
text: 'Choose a game to play',
fallback: 'You are unable to choose a game',
callback_id: 'wopr_game',
color: '#3AA3E3',
attachment_type: 'default',
actions: [
{
name: 'game',
text: 'Chess',
type: 'button',
value: 'chess',
},
],
},
],
});
```
<br />

@@ -91,0 +115,0 @@

@@ -200,2 +200,108 @@ import querystring from 'querystring';

});
it('should call chat.postMessage with optional options and not parse attachments string', 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',
attachments:
'[{"text":"Choose a game to play","fallback":"You are unable to choose a game","callback_id":"wopr_game","color":"#3AA3E3","attachment_type":"default","actions":[{"name":"game","text":"Chess","type":"button","value":"chess"},{"name":"game","text":"Falken\'s Maze","type":"button","value":"maze"},{"name":"game","text":"Thermonuclear War","style":"danger","type":"button","value":"war","confirm":{"title":"Are you sure?","text":"Wouldn\'t you prefer a good game of chess?","ok_text":"Yes","dismiss_text":"No"}}]}]',
as_user: true,
token: TOKEN,
}),
{
'Content-Type': 'application/x-www-form-urlencoded',
}
)
.reply(200, reply);
const res = await client.postMessage(CHANNEL, 'hello', {
attachments:
'[{"text":"Choose a game to play","fallback":"You are unable to choose a game","callback_id":"wopr_game","color":"#3AA3E3","attachment_type":"default","actions":[{"name":"game","text":"Chess","type":"button","value":"chess"},{"name":"game","text":"Falken\'s Maze","type":"button","value":"maze"},{"name":"game","text":"Thermonuclear War","style":"danger","type":"button","value":"war","confirm":{"title":"Are you sure?","text":"Wouldn\'t you prefer a good game of chess?","ok_text":"Yes","dismiss_text":"No"}}]}]',
as_user: true,
});
expect(res).toEqual(reply);
});
it('should call chat.postMessage with optional options and parse attachments to string', 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',
attachments:
'[{"text":"Choose a game to play","fallback":"You are unable to choose a game","callback_id":"wopr_game","color":"#3AA3E3","attachment_type":"default","actions":[{"name":"game","text":"Chess","type":"button","value":"chess"},{"name":"game","text":"Falken\'s Maze","type":"button","value":"maze"},{"name":"game","text":"Thermonuclear War","style":"danger","type":"button","value":"war","confirm":{"title":"Are you sure?","text":"Wouldn\'t you prefer a good game of chess?","ok_text":"Yes","dismiss_text":"No"}}]}]',
as_user: true,
token: TOKEN,
}),
{
'Content-Type': 'application/x-www-form-urlencoded',
}
)
.reply(200, reply);
const res = await client.postMessage(CHANNEL, 'hello', {
attachments: [
{
text: 'Choose a game to play',
fallback: 'You are unable to choose a game',
callback_id: 'wopr_game',
color: '#3AA3E3',
attachment_type: 'default',
actions: [
{
name: 'game',
text: 'Chess',
type: 'button',
value: 'chess',
},
{
name: 'game',
text: "Falken's Maze",
type: 'button',
value: 'maze',
},
{
name: 'game',
text: 'Thermonuclear War',
style: 'danger',
type: 'button',
value: 'war',
confirm: {
title: 'Are you sure?',
text: "Wouldn't you prefer a good game of chess?",
ok_text: 'Yes',
dismiss_text: 'No',
},
},
],
},
],
as_user: true,
});
expect(res).toEqual(reply);
});
});

@@ -202,0 +308,0 @@

@@ -235,4 +235,10 @@ /* @flow */

options?: PostMessageOptions = {}
): Promise<SlackOAuthAPIResponse> =>
this.callMethod('chat.postMessage', { channel, text, ...options });
): Promise<SlackOAuthAPIResponse> => {
if (options.attachments && typeof options.attachments !== 'string') {
// A JSON-based array of structured attachments, presented as a URL-encoded string.
// eslint-disable-next-line no-param-reassign
options.attachments = JSON.stringify(options.attachments);
}
return this.callMethod('chat.postMessage', { channel, text, ...options });
};

@@ -239,0 +245,0 @@ /**

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