Hubot-slack: Add thread support

Created on 20 Jan 2017  路  9Comments  路  Source: slackapi/hubot-slack

  • [X] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [X] I've read and agree to the Code of Conduct.
  • [X] I've searched for any related issues and avoided creating a duplicate issue.

Description

Slack added the support for threads.
It would be nice if hubot answers could be sent as threads. According to new Slack best practice, this is actually the recommended behavior: https://api.slack.com/docs/message-threading#best_practices

Here is the relevant link in the Slack API documentation: https://api.slack.com/docs/message-threading#using_the_rtm_api

I do not know the code of hubot_slack well enough, but here is how it is implemented for the flowdock adapter, which supports threads: https://github.com/flowdock/hubot-flowdock/blob/master/src/flowdock.coffee#L30

Attachments:

image

Also, a Slack platform blog post on bots and thread: https://medium.com/slack-developer-blog/bringing-your-bot-into-threaded-messages-cd272a42924f

Most helpful comment

Here's some example code to always reply in a new thread:

robot.adapter.client.web.chat.postMessage(
        res.message.user.room,
        message, // e.g. "your message here"
        {thread_ts: res.message.rawMessage.ts}
      );

All 9 comments

@ojacques I got a PR up that hopefully resolves this: https://github.com/slackapi/hubot-slack/pull/398

Very nice @ndaversa 馃憤 I updated our bots already. Works nicely as far as I can tell. Thanks!

Hey! Not sure if this is the correct place to pose this question, but I did not want to open a new issue.

I am trying to figure out how to get my bot to respond within a thread, instead of replying with an @{someUser}. I see the updated docs, which say:

This (thread_ts) field will automatically be passed along for you, as a result your bot will automatically reply in the context of the thread, if the message to your bot originated from one.

I am confused how to implement this, and I don't see a working example in the docs.

Here is some pseudo code:

robot.respond REGEX, id: 'foo', (botResp) ->
    robot.http(makeSomeRequest(cfg, params)).get() (err, res, body) ->
      if err
        botResp.reply "
          Could not build branch *#{params.branch}* on *#{params.target}*
          "
        botResp.send "Encountered error: `#{err}`"
        return

Should I be passing botResp.message.thread_ts into my call to botResp.reply and/or/ideally botResp.send somehow?

Maybe something like botResp.reply "some err message", {ts: robotResp.message.thread_ts}?

The docs say _something_ should happen automatically, which I think is why I am confused as to how replying to a thread works. I have sort of limited access to debugging at the moment, so any insight you can offer would be greatly appreciated.

Thanks so much! Let me know if I can give you any more info on my use case.

@mattyfresh are you using a version of hubot-slack with this feature included? Because if you invoke a bot command inside a thread it should just automatically reply back into that thread. Assuming you have the latest version.

Ah! That could be the issue, I assumed it was the latest version but perhaps it is not. Thanks!

Is it possible to create a thread with this functionality? I took a look at the PR and didn't see anything related to that. Just curious.

@cha55son No, I didn't add anything for that support. Though I'm sure @roach would welcome a PR

What should I do to make hubot reply via thread?

The bot I'm trying to update takes commands and replies in the context the message came from, channel or thread

I want the bot to reply in a different context sometimes.

It would reply to in the existing thread if we're in a thread, or start a new thread if the message was sent in a channel or a DM.

I just need to know how to tell hubot to reply to the slack message via a thread on the original message, if the original method wasn't in a thread.

It looks easy enough in the Slack docs:
https://api.slack.com/docs/message-threading#1._parent_messages_arrive_as_usual

I can't tell if hubot-slack is setup to do that out of the box & the docs don't seem to illustrate this specific example

Here's some example code to always reply in a new thread:

robot.adapter.client.web.chat.postMessage(
        res.message.user.room,
        message, // e.g. "your message here"
        {thread_ts: res.message.rawMessage.ts}
      );
Was this page helpful?
0 / 5 - 0 ratings