Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #441 from sundeepgupta/chatUpdateSanitizeOptions
Browse files Browse the repository at this point in the history
Slack's `chat.update` should work with attachments
  • Loading branch information
Ben Brown authored Nov 7, 2016
2 parents ba8c91d + 56802e2 commit 8e8ffcc
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/Slack_web_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,27 @@ module.exports = function(bot, config) {

// overwrite default behavior
slack_api.chat.postMessage = function(options, cb) {
if (options.attachments && typeof(options.attachments) != 'string') {
try {
options.attachments = JSON.stringify(options.attachments);
} catch (err) {
delete options.attachments;
bot.log.error('Could not parse attachments', err);
}
}
sanitizeOptions(options);
slack_api.callAPI('chat.postMessage', options, cb);
};

slack_api.chat.update = function(options, cb) {
sanitizeOptions(options);
slack_api.callAPI('chat.update', options, cb);
};

function sanitizeOptions(options) {
if (options.attachments && typeof(options.attachments) != 'string') {
try {
options.attachments = JSON.stringify(options.attachments);
} catch (err) {
delete options.attachments;
bot.log.error('Could not parse attachments', err);
}
}
}


return slack_api;


Expand Down

0 comments on commit 8e8ffcc

Please sign in to comment.