From d4ea0304375ce829bc883193e53f138304c5590a Mon Sep 17 00:00:00 2001 From: Cole Furfaro-Strode Date: Thu, 5 Jan 2017 14:51:35 -0500 Subject: [PATCH] adds createPrivateConversation to Slack bots --- lib/Slackbot_worker.js | 10 ++++++++++ readme.md | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/Slackbot_worker.js b/lib/Slackbot_worker.js index 8bad17e7b..3cc444c3e 100755 --- a/lib/Slackbot_worker.js +++ b/lib/Slackbot_worker.js @@ -305,6 +305,16 @@ module.exports = function(botkit, config) { botkit.createConversation(this, message, cb); }; + bot.createPrivateConversation = function(message, cb) { + bot.api.im.open({ user: message.user }, function(err, channel) { + if (err) return cb(err); + + message.channel = channel.channel.id; + + botkit.createConversation(bot, message, cb); + }); + } + /** * Convenience method for creating a DM convo. diff --git a/readme.md b/readme.md index 63cd7d7f0..1392b2576 100755 --- a/readme.md +++ b/readme.md @@ -481,6 +481,17 @@ and the conversation will not collect responses until it is activated using [con Use `createConversation()` instead of `startConversation()` when you plan on creating more complex conversation structures using [threads](#conversation-threads) or [variables and templates](#using-variable-tokens-and-templates-in-conversation-threads) in your messages. +#### bot.createPrivateConversation() +| Argument | Description +|--- |--- +| message | message object containing {user: userId} of the user you would like to start a conversation with +| callback | a callback function in the form of function(err,conversation) { ... } + +`createPrivateConversation()` is a function that initiates a conversation with a specific user. Note function is currently *Slack-only!* + +Use `createPrivateConversation()` instead of `startPrivateConversation()` when you plan on creating more complex conversation structures using [threads](#conversation-threads) or [variables and templates](#using-variable-tokens-and-templates-in-conversation-threads) in your messages. + + ### Control Conversation Flow #### conversation.activate()