Node-slack-sdk: Groups & Channel create method - no optional params

Created on 24 May 2017  路  2Comments  路  Source: slackapi/node-slack-sdk

  • [X] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [X] I've read and agree to the Code of Conduct.
  • [X] I've searched for any related issues and avoided creating a duplicate issue.

Description

The WebClient methods for creating a channel or a group does not expect an optional parameter in contradiction to the API documentation

Viewing the implementation is clear that the inner call to makeAPICall does not include optional parameters.

Reproducible in:

node-slack-sdk: 3.9.0
Device: Mac Book Pro E2015 (but probably any)
OS version: macOS 10.12.2 (but probably any)
Node version: 6.9.0

Steps to reproduce:

in a simple node app:

  1. Create a webClient using the node-slack-sdk
  2. Call the webClient.channels.create or webClient.groups.create method with a channel name as a first parameter AND { validate: true } as the second parameter.

Expected result:

Method should return a promise (or use a third parameter as cb), and in case validate is set to true, throw an error in case the channel/group does not meet Slack's naming convention (instead of modifying the given name)

Actual result:

  1. The method returns undefined (instead of a promise, since the opt params is treated a cb)
  2. An internal error is thrown: error: TypeError: apiCb is not a function

Notes:

In case this is the planned behavior, it might be a good idea to update the API docs.

bug major

Most helpful comment

hey @matanlb thanks for the bug report. you're totally right. i believe what happened here is that those optional parameters were added later and the SDK wasn't updated. and actually i can see at least one reason why: this would have to be released as a breaking change (semver:major). previous code that uses the callback parameter would stop working if i merge a fix.

the good news is that we've been working on a roadmap that will give us some timelines. but we're looking at a couple months for a new semver:major version.

in the meantime, fortunately the SDK has affordance for a workaround:

// `slack` is an instance of `WebClient`
slack._makeAPICall('channels.create', { name: 'channel_name' }, { validate: true }, callback);
slack._makeAPICall('groups.create', { name: 'group_name' }, { validate: true }, callback);

this does use "private" API, so its not ideal, but i don't imagine the _makeAPICall() method changing before any semver:major updates.

All 2 comments

I can confirm this issue.

see @slack/client/lib/clients/web/channels.js 45-58:

/**
 * Creates a channel.
 * @see {@link https://api.slack.com/methods/channels.create|channels.create}
 *
 * @param {?} name - Name of channel to create
 * @param {function=} optCb Optional callback, if not using promises.
 */
ChannelsFacet.prototype.create = function create(name, optCb) {
  var requiredArgs = {
    name: name
  };

  return this.makeAPICall('channels.create', requiredArgs, null, optCb);
};

hey @matanlb thanks for the bug report. you're totally right. i believe what happened here is that those optional parameters were added later and the SDK wasn't updated. and actually i can see at least one reason why: this would have to be released as a breaking change (semver:major). previous code that uses the callback parameter would stop working if i merge a fix.

the good news is that we've been working on a roadmap that will give us some timelines. but we're looking at a couple months for a new semver:major version.

in the meantime, fortunately the SDK has affordance for a workaround:

// `slack` is an instance of `WebClient`
slack._makeAPICall('channels.create', { name: 'channel_name' }, { validate: true }, callback);
slack._makeAPICall('groups.create', { name: 'group_name' }, { validate: true }, callback);

this does use "private" API, so its not ideal, but i don't imagine the _makeAPICall() method changing before any semver:major updates.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hckhanh picture hckhanh  路  21Comments

aoberoi picture aoberoi  路  12Comments

dcsan picture dcsan  路  12Comments

freder picture freder  路  12Comments

amkoehler picture amkoehler  路  13Comments