I exposed to you my problem with ephemeral message and update of user message
A simplified user case can :
when you write "hi" in a channel, that triggers an ephemeral message with a button "click", and when you click that button, it updates your first "hi" message, to "goodbye" for instance.
This is the code I tried. Unfortunatly, I think I have the wrong message_ts for the update. It seems to be the message_ts of the ephemeral message. Not the one of the original message. What do you think about it?
Have you an idea about how to achieve my goal?
const { WebClient } = require("@slack/web-api");
const slack_bot_token = process.env.SLACK_BOT_TOKEN;
const signing_secret = process.env.SLACK_SIGNING_SECRET;
const webClient = new WebClient(process.env.SLACK_BOT_TOKEN);
const { App } = require("@slack/bolt");
const app = new App({
token: slack_bot_token,
signingSecret: signing_secret,
});
app.message("hi", async ({ message, channel, say }) => {
// Respond to action with an ephemeral message
let channelID = message.channel;
let userID = message.user;
let ts = message.timestamp;
await webClient.chat.postEphemeral({
channel: channelID,
user: userID,
text: ` Hi <@${message.user}>`,
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: ` Hey <@${message.user}>`,
},
accessory: {
type: "button",
text: {
type: "plain_text",
text: "Click me",
emoji: true,
},
action_id: "click",
},
},
],
});
});
// when the button with action_id "click" is clicked, the ephemeral message is discarded, and the user message is updated
app.action("click", async ({ ack, body, client, respond }) => {
// Acknowledge action request before anything else
await ack();
let channelID = body.channel.id;
let userID = body.user.id;
let message_ts = body.container.message_ts;
// erase original ephemeral message
respond({
response_type: "ephemeral",
text: "",
replace_original: true,
delete_original: true,
});
// update the original "hi" message
console.log (body.container);
webClient.chat.update({
token: slack_bot_token,
channel: body.container.channel_id,
ts: body.container.message_ts,
text: "goodbye",
replace_original: true,
delete_original: true,
});
});
(async () => {
// Start your app
await app.start(process.env.PORT || 3000);
console.log("⚡️ Bolt app is running!!");
})();
Thanks for your help