Sending with options overwrites extended slack object
Closed this issue · 1 comments
herkyl commented
Slack notify overwrites extended object when sending an object. I think that the wanted action is for a new message to get all the extended parameters and only overwrite when you explicitly define something.
Steps to produce:
const slackNotify = require('slack-notify')(slackWebhookURL);
// extend a base slack object
const slack = slackNotify.extend({
username: 'Slack Notify',
channel: '#user-events',
icon_emoji: ':mailbox_with_mail:'
});
// send a message to a specific channel with an emoji
slack({
text: 'User changed subscription plan',
icon_emoji: ':money_mouth_face:',
channel: 'billing',
});
// !!! when I now send this basic event it
// !!! instead goes to #billing channel and shows the :money_mouth_face: emoji
slack('A basic event that should go to the default #user-events channel');
herkyl commented
I think that the bug might happen due to possible misuse of extend.
https://github.com/andrewchilds/slack-notify/blob/master/slack-notify.js#L108
pub.send(_.extend(defaults, options), done);
this overwrites the defaults object, you can fix it like so:
pub.send(_.extend({}, defaults, options), done);