Skip to content

Commit

Permalink
Merge pull request #2 from BGR360/threads
Browse files Browse the repository at this point in the history
Add support for replying as a thread
  • Loading branch information
BGR360 committed Jan 28, 2019
2 parents d3f731d + 33b8bae commit 700f800
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"required": true,
"value": "https://piazza.com/class/CLASS_NOT_SET"
},
"REPLY_AS_THREAD": {
"description": "Should the bot reply as a thread? Leave empty for no, put any value for yes.",
"required": false
},
"RETRY_MEMORY": {
"description": "Number of message ids to hold in memory to prevent duplicate messages (linear search involved) (default=100)",
"required": false
Expand Down
5 changes: 5 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ var config = {
// The URL of your Piazza class.
piazza_base_url: process.env['PIAZZA_BASE_URL'],

// Should the bot reply as a thread? If not, just sends a message to the channel.
// If the message that triggers the bot is already in a thread, then the bot
// will always respond to that thread, no matter the value of this setting.
reply_as_thread: process.env['REPLY_AS_THREAD'] || false,

// Whether or not to use the Slack Real-Time Messaging API instead of the Events API.
use_rtm: process.env['USE_RTM'] || false,

Expand Down
16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ client.on('message', (message) => {

regexbot.respond(message.text, (reply) => {
console.log('Responding with: ' + reply);
postMessage({ channel: message.channel, text: reply, as_user: true });

var replyMessage = {
channel: message.channel,
text: reply,
as_user: true
};

// If bot is configured to reply as a thread, or if the message that
// triggered the bot was already a threaded reply, then add a 'thread_ts'
// so that the bot replies inside the thread.
if (config.reply_as_thread || message.thread_ts !== undefined) {
replyMessage.thread_ts = message.thread_ts || message.ts;
}

postMessage(replyMessage);
});
};

Expand Down

0 comments on commit 700f800

Please sign in to comment.