I have a bot that's meant to reply to messages in a channel with certain keywords it's listening for. I have it deployed and it's working perfectly, but it replies in the channel rather than starting a thread to a user's message. Here's my code that's meant to start the thread:
app.message("ake up", async ({ command, say }) => {
try {
say({ text: "I'm awake! ⭐️ Do you need assistance?", thread_ts: message.ts });
} catch (error) {
console.log("err")
console.error(error);
}
});
Nothing happens when I send a message saying "wake up". When it's the same without thread_ts: message.ts and just says say("I'm awake! ⭐️ Do you need assistance?")}, it works perfectly. and responds with that.
Here's the beginning of my code for reference:
require("dotenv").config();
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode:true,
appToken: process.env.APP_TOKEN
});
This was answered on GitHub.
The trick here is that thread_ts is available only for threaded messages (it identifies the parent message which started the thread). If you want to start a thread, you can use ts value of the incoming message:
app.message("ake up", async ({ message, say }) => {
try {
await say({ text: "I'm awake! ⭐️ Do you need assistance?" , thread_ts: message.thread_ts || message.ts});
} catch (error) {
console.log("err")
console.error(error);
}
});
See also Spotting threads guide in Slack docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With