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

Slack's chat.update should work with attachments #441

Merged
merged 1 commit into from
Nov 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions lib/Slack_web_api.js
Original file line number Diff line number Diff line change
@@ -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;