Bolt-js: How to make bot send response to user in the same thread where message is sent by user?

Created on 23 Sep 2020  路  2Comments  路  Source: slackapi/bolt-js

I wrote code for bot such that when certain message(which bot recognizes) is send by user then it will reply in thread
But if I enter the message in previous thread then bot is not responding in same previous thread.
It is sending response or the same message directly to the main conversation in the channel which is outside the thread.
Here is the code:

  await say({
          blocks: alertBlocks,thread_ts: message.ts 
        });

For now I tried by using thread_ts:message.ts in say() method.
I replace value of message.ts with event_ts, message.thread_ts, and different ts values present in body and message in props. But it didnt work out.
Basically I need continuity of messages in thread but it is sending responses out of thread when I message in thread.
Please tell me the logic or give sample code so that bot responds in previous thread where he posted the message to bot!

question

Most helpful comment

Hey @stevengill
After reading the links which you suggested I arrived at this solution. Now I am able to respond in previous thread!!
This is the logic I used to respond to user in thread

var threadTs;
  if(message.thread_ts){threadTs = message.thread_ts; }else{threadTs=message.ts;}
 await say({text:`<@${body.event.user}> Hello`,thread_ts:threadTs});

Thanks!!

All 2 comments

Hey @Mogadampalli-Jayanth,

Checkout this previous issue about using say to respond in thread. https://github.com/slackapi/bolt-js/issues/559

Also, you can read more about thread_ts at https://api.slack.com/methods/chat.postMessage#arg_thread_ts

Hey @stevengill
After reading the links which you suggested I arrived at this solution. Now I am able to respond in previous thread!!
This is the logic I used to respond to user in thread

var threadTs;
  if(message.thread_ts){threadTs = message.thread_ts; }else{threadTs=message.ts;}
 await say({text:`<@${body.event.user}> Hello`,thread_ts:threadTs});

Thanks!!

Was this page helpful?
0 / 5 - 0 ratings