Comments (6)
@TK95, v3.2.2 should fix the problem. Just make sure you call next()
in your middleware so the messageAction()
handler is matched.
from bolt-js.
Hi @TK95, can you try v3.2.1 and confirm the issue is resolved?
This is what I tested with BTW:
slapp.messageAction('my_action', (msg, message) => {
msg.respond({
text: `:tada: your action has been received :wink: - ${message.text}`,
response_type: 'ephemeral'
})
})
from bolt-js.
Hey, @mbrevoort and thanks for looking into it!
I installed v3.2.1 and did tests. Your snippet works just fine!
However, my case is a bit tricky and I still have the same problem. I'm sorry for not being precise.
Please, consider the following code:
Example 1:
const middlewareFn = (msg, next) => {
return msg.respond({
text: ':tada: Hello from middleware',
response_type: 'ephemeral'
})
}
bot.use(middlewareFn)
bot.messageAction('my_action', (msg) => {
return msg.respond({
text: ':tada: Hello from message action handler',
response_type: 'ephemeral'
})
})
The aforementioned code is very similar to my real one (Sorry I can't disclosure it). And this code doesn't work as expected.
If I trigger the message action I expect that "Hello from middleware" will be posted to the channel, but nothing is happening.
Please, see the second code fragment:
Example 2:
const middlewareFn = (msg, next) => {
return msg.respond({
text: ':tada: Hello from midllware',
response_type: 'ephemeral'
})
}
// bot.use(middlwareFn)
bot.messageAction('my_action', middlewareFn, (msg) => {
return msg.respond({
text: ':tada: Hello from message action handler',
response_type: 'ephemeral'
})
})
In this example, I commented out bot.use(middlewareFn)
line and placed middlewareFn
in bot.messageAction(...)
. And actually, this code works as expected, I see the message from middlewareFn
.
Are there any problems with using middlewares in message actions?
I tried to add a callback argument, like this msg.respond(msg, cb)
, there is no error.
If you need any other details, please let me know.
from bolt-js.
I think what may be causing the behavior you're seeing is that msg.respond()
is being called twice in the processing of the event. I think if you added a callback to the msg.respond
inside the messageAction
handler, you would see an error, but not w/ the msg.respond
call from inside the middleware (if I'm right 😄).
For some context, msg.respond()
is designed to be called once, as it ends up sending the response to the slack event request, which is how you can trigger things like ephemeral messages from certain types of events.
You could probably accomplish what you want in a few ways. Slack added an api to postEphemeral - which is a way to create an ephemeral message outside having to respond to an event request. You could make that api call either in your middleware, or from within your messageAction
handler. My suggestion would be to have the middleware call the chat.postEphemeral
api, which leaves the default behavior for msg.respond()
available inside any event handlers.
from bolt-js.
Fix coming. With this fix msg.respond
will work but your messageAction
handler will only be called if you call next()
in the middleware.
from bolt-js.
Thanks, @mbrevoort and @selfcontained. Everything works like a charm!
from bolt-js.
Related Issues (20)
- uploadV2 method always returns error `not_authed` but upload method works HOT 3
- How to built customisable form using slack api HOT 4
- Can I require choosing a channel when authorizing a Slack App? HOT 2
- Using AWS Lambda Handler while retrieving Bot Token and Signing Secret from Vault HOT 2
- Add slack_file object to image block element HOT 1
- How to document `optional` field from housing Block and how it applies to Block Elements within? HOT 8
- app_home_opened not firing on iOS client HOT 15
- Duplicate message getting created when trying to update bot message using chat.update HOT 1
- Unfurl links when the app is installed in the workspace HOT 2
- State verification during OAuth process HOT 8
- `context.matches.groups` becomes undefined after a Web API call HOT 8
- Is it possible to get typing event or indicator when a user in slack starts typing in a message HOT 1
- `files` property missing in `app_mention` event HOT 3
- How to track of deleted users HOT 3
- External select not refreshing HOT 4
- Issue with extracting headers from incoming requests HOT 1
- User scope not working in OAuth HOT 3
- Message event payloads missing `team_id` in enterprise on mobile slack clients HOT 9
- Issue with `respond` to update message returning cant_update_message HOT 10
- Way to disable message content being logged
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bolt-js.