Describe your issue here.
x in one of the [ ])x in each of the [ ])package version: 2.1.1
node version:v13.3.0
OS version(s):
I am trying to send an ephemeral message on member_joined_channel event trigger. When I try to use ack(), it throws an error TypeError: ack is not a function
Below is my code:
app.event('member_joined_channel', async ({ event, say, ack }) => {
try {
await ack({
text: 'blah'
});
} catch(e) {
console.log(e);
}
});
I want all the messages to be ephemeral and none of the messages should get posted on the channel. I can do the above in actions/commands but it's not working for the events. Basically, all I want is, be it a command, event or a simple message, all the replies from the bot to the users need to be ephemeral. The below code works though
app.event('member_joined_channel', async ({ event, say, ack }) => {
app.client.chat.postEphemeral({
token: process.env.SLACK_BOT_TOKEN,
channel: event.channel,
user: event.user,
text: `Ephemeral Message Test`
});
});
`TypeError: ack is not a function`
You cannot send a reply message as an HTTP response to Events API requests from Slack. So, ack() method is not available in app.event listeners (Bolt does the acknowledgment of requests for you under the hood). The only way you can post an ephemeral message in response to Events API is, as you did, utilizing chat.postEphemeral API method.
@seratch that is helpful. One last question, what is the difference between ack() and respond()? can I use them interchangeably? The reason am asking is, I can send ephemeral messages using respond() too, so can I change chat. postEphemeral to respond() instead?
As mentioned here, respond() is a utility method for easily utilizing response_url. To learn about response_url, refer to its document.
can I change
chat.postEphemeraltorespond()instead?
No, you can't because response_url doesn't exist in Events API payloads. Please use chat.postEphemeral in app.event listeners.
Perfect. Thank you
Most helpful comment
You cannot send a reply message as an HTTP response to Events API requests from Slack. So,
ack()method is not available inapp.eventlisteners (Bolt does the acknowledgment of requests for you under the hood). The only way you can post an ephemeral message in response to Events API is, as you did, utilizingchat.postEphemeralAPI method.