From 3f47d6477f8d7ae7f042fd8e13b71424f05d2afb Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Tue, 7 Feb 2017 19:19:26 -0800 Subject: [PATCH] adds chat.unfurl facet for web client --- lib/clients/helpers.js | 8 ++++++++ lib/clients/web/facets/chat.js | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/clients/helpers.js b/lib/clients/helpers.js index 8fd9ee6dd..e01df8c4a 100644 --- a/lib/clients/helpers.js +++ b/lib/clients/helpers.js @@ -29,6 +29,14 @@ var assignApiArgs = function assignApiArgs(target, source) { } else { target[key] = JSON.stringify(val); } + // For the web API, this should always be a JSON-encoded object, see: + // https://api.slack.com/methods/chat.unfurl + } else if (key === 'unfurls') { + if (isString(val)) { + target[key] = val; + } else { + target[key] = JSON.stringify(val); + } } else if (key !== 'opts') { target[key] = val; } diff --git a/lib/clients/web/facets/chat.js b/lib/clients/web/facets/chat.js index b7773ce82..3644286bc 100644 --- a/lib/clients/web/facets/chat.js +++ b/lib/clients/web/facets/chat.js @@ -123,5 +123,23 @@ ChatFacet.prototype.update = function update(ts, channel, text, opts, optCb) { return this.makeAPICall('chat.update', requiredArgs, opts, optCb); }; +/** + * Unfurl a URL within a message by defining its message attachment. + * @see {@link https://api.slack.com/methods/chat.unfurl|chat.unfurl} + * + * @param {?} ts - Timestamp of the message to be updated. + * @param {?} channel - Channel of the message to be updated. + * @param {string} unfurls - a map of URLs to structured message attachments + * @param {function=} optCb Optional callback, if not using promises. + */ +ChatFacet.prototype.unfurl = function unfurl(ts, channel, unfurls, optCb) { + var requiredArgs = { + ts: ts, + channel: channel, + unfurls: unfurls + }; + + return this.makeAPICall('chat.unfurl', requiredArgs, {}, optCb); +}; module.exports = ChatFacet;