Closed pshriwise closed 7 years ago
I have been playing with this feature this morning and it seems fairly easy to implement by including the thread_id
in the message send to the API.
The question remains how Slackbot should be made aware that the message should be send to a thread. I would suggest something along the lines of the code below. Notice the extra in_thread
argument passed to reply
method.
@listen_to("Howdy")
def greet(message):
message.reply("Howdy to as well", in_thread=True)
Internally Slackbot would determine the thread's ID by looking at the message.body
property. For example the following property could be added to the message class:
@property
def thread_ts(self):
try:
thread = self.body['thread_ts']
except KeyError:
# This would mean there's no thread yet and one will be started
thread = self.body['ts']
return thread
If people are interested, I think I could implement this one of these days.
This would be highly appreciated :)
Just wondering if this enhancement is planned sometime soon :)
I must be honest, I kind of slipped my mind. I will see if I can make a decent start on it this weekend.
I created a pull request to add this functionality #153
Thanks a lot, @NiekKeijzer 😄
I was just trying the in_thread parameter using the code you provided for testing and i keep getting this error. Any idea why?
Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/slackbot/dispatcher.py", line 55, in _dispatch_msg_handler func(Message(self._client, msg), *args) File "/home/dev/Desktop/Github/securitybot/securitybot2/securitybot2/plugins.py", line 27, in help message.reply("Here's a threaded reply", in_thread=True) File "/usr/local/lib/python2.7/dist-packages/slackbot/dispatcher.py", line 175, in wrapped return func(self, text, *a, **kw) TypeError: reply() got an unexpected keyword argument 'in_thread'
Hi, @jaysig112 - are you using the latest code on the develop branch? You may want to rerun setup or pip install requirements.txt - the threaded reply option requires a relatively new version of one of our library dependencies (slacker>=0.9.50).
I just installed everything today and I checked slacker it is version 0.9.50
What version of slackbot do you have? The version with in_thread is not yet on pypi. You'll need to install slackbot from the develop branch of git.
Yep that fixed it! Thanks! While I have you here if I wanted to have it keep replying in the thread how would I go about that. Like I start a conversation with the bot it replies in the thread with a question then I answer in the thread and it keeps going until I answer all the bots questions.
How do I use this feature?
Is there a way to have the bot reply in a thread? Right now, our bot successfully listens to messages for threads in a channel, but it replies to the channel.
I'm aware that threads are a relatively new feature, but is there a way to reply within the thread? If not, will this be possible in the future?