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.13 to 0.5.15

28

lib/SlackOAuthClient.js

@@ -55,2 +55,3 @@ '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 {

@@ -245,2 +246,23 @@

/**

@@ -265,6 +287,6 @@ * 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 = {}) => {if (options.attachments && typeof options.attachments !== 'string') {// A JSON-based array of structured attachments, presented as a URL-encoded string.
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, message, 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 => ({
options.attachments = JSON.stringify(options.attachments);} else if (typeof message === 'object' && message.attachments && typeof message.attachments !== 'string') {// eslint-disable-next-line no-param-reassign
message.attachments = JSON.stringify(message.attachments);}if (typeof message === 'string') {return this.callMethod('chat.postMessage', _extends({ channel, text: message }, options));}return this.callMethod('chat.postMessage', _extends({ channel }, message, 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,

@@ -271,0 +293,0 @@ next: data.response_metadata && data.response_metadata.next_cursor }));this.

2

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

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

@@ -77,10 +77,12 @@ # messaging-api-slack

Param | Type | Description
------- | -------- | -----------
channel | `String` | Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name.
text | `String` | Text of the message to be sent.
options | `Object` | Other optional parameters.
Param | Type | Description
------- | --------------------------------- | -----------
channel | `String` | Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name.
message | <code>String &#124; Object</code> | The message to be sent, can be text message or attachment message.
options | `Object` | Other optional parameters.
Example:
```js
client.postMessage('C8763', { text: 'Hello!' });
client.postMessage('C8763', { attachments: [someAttachments] });
client.postMessage('C8763', 'Hello!');

@@ -92,22 +94,28 @@ client.postMessage('C8763', 'Hello!', { as_user: true });

```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',
},
],
},
],
});
client.postMessage(
'C8763',
{
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',
},
],
},
],
},
{
as_user: true,
}
);
```

@@ -114,0 +122,0 @@

@@ -142,2 +142,177 @@ import querystring from 'querystring';

describe('#postMessage', () => {
it('should call chat.postMessage with channel and text message', 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.postMessage(CHANNEL, { text: 'hello' });
expect(res).toEqual(reply);
});
it('should call chat.postMessage with channel and text and attachments message', 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,
{
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 }
);
expect(res).toEqual(reply);
});
it('should call chat.postMessage with channel and attachments message', async () => {
const { client, mock } = createMock();
const reply = {
ok: true,
ts: '1405895017.000506',
channel: 'C024BE91L',
message: {},
};
mock
.onPost(
'/chat.postMessage',
querystring.stringify({
channel: CHANNEL,
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,
{
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 channel and text', async () => {

@@ -144,0 +319,0 @@ const { client, mock } = createMock();

@@ -10,2 +10,3 @@ /* @flow */

import type {
SlackAttachment,
SlackOAuthAPIResponse,

@@ -234,3 +235,5 @@ SlackAvailableMethod,

channel: string,
text: string,
message:
| { text?: string, attachments: Array<SlackAttachment> | string }
| string,
options?: PostMessageOptions = {}

@@ -242,4 +245,23 @@ ): Promise<SlackOAuthAPIResponse> => {

options.attachments = JSON.stringify(options.attachments);
} else if (
typeof message === 'object' &&
message.attachments &&
typeof message.attachments !== 'string'
) {
// eslint-disable-next-line no-param-reassign
message.attachments = JSON.stringify(message.attachments);
}
return this.callMethod('chat.postMessage', { channel, text, ...options });
if (typeof message === 'string') {
return this.callMethod('chat.postMessage', {
channel,
text: message,
...options,
});
}
return this.callMethod('chat.postMessage', {
channel,
...message,
...options,
});
};

@@ -246,0 +268,0 @@

@@ -22,2 +22,18 @@ /* @flow */

footer_icon?: string,
callback_id?: string,
attachment_type?: string,
actions: Array<{
name?: string,
text?: string,
type?: string,
value?: string,
style?: string,
options?: Array<{ text: string, value: string }>,
confirm?: {
title?: string,
text?: string,
ok_text?: string,
dismiss_text?: string,
},
}>,
ts?: number,

@@ -24,0 +40,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