From 439a601da4f3def8f66e1f1a55009b2d3b6557da Mon Sep 17 00:00:00 2001 From: Cole Furfaro-Strode Date: Tue, 19 Jul 2016 22:28:13 -0400 Subject: [PATCH] clear attachments if parsing fails on postMessage --- lib/Slack_web_api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Slack_web_api.js b/lib/Slack_web_api.js index 2dfca019b..5eeb53d0f 100755 --- a/lib/Slack_web_api.js +++ b/lib/Slack_web_api.js @@ -152,7 +152,12 @@ module.exports = function(bot, config) { // overwrite default behavior slack_api.chat.postMessage = function(options, cb) { if (options.attachments && typeof(options.attachments) != 'string') { - options.attachments = JSON.stringify(options.attachments); + try { + options.attachments = JSON.stringify(options.attachments); + } catch(err) { + delete options.attachments; + bot.log.error('Could not parse attachments', err); + } } slack_api.callAPI('chat.postMessage', options, cb); };