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.
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
in a simple node app:
webClient.channels.create or webClient.groups.create method with a channel name as a first parameter AND { validate: true } as the second parameter.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)
undefined (instead of a promise, since the opt params is treated a cb)error: TypeError: apiCb is not a functionIn case this is the planned behavior, it might be a good idea to update the API docs.
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.
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:
this does use "private" API, so its not ideal, but i don't imagine the
_makeAPICall()method changing before any semver:major updates.