Comments (13)
Yeah so that is what we are doing already with the im.open
piece, and it's working ok, although its a bit ugly. It also requires an existing msg
object, which is not ideal like you said. It definitely would be a lot better to have an independent method that wouldn't be coupled to or hacked on to an existing conversation. For example, what if I wanted to bot to message a user as soon as it is booted up?
Also in order to be able to add correctly to a queue, I assume there would need to be some extra logic here, making it even more compelling as a helper method.
from bolt-js.
Interesting, gonna think that through a bit.
In regards to having the bot message a different user, is it that you want the bot to @mention
the user in the current channel, or send a dm, or in a new channel?
from bolt-js.
For my particular use case, it would be sending a DM. Some type of method like:
slapp.directMessageUser('U12HSK2', 'hello there!').route('foobar')
Would be really great. In this case, the second argument would be the same as can normally be passed to msg.say()
, so while it's a string here, it could be an object if it has buttons, attachments, etc.
from bolt-js.
Gotcha, makes sense. I can see how it's awkward and error-prone trying to use the existing msg
object to accomplish that. There is some context stored on the existing msg
that would be needed to dm the new user (msg.meta.bot_token
). This is what it would look like to do something like that w/ the raw client library:
// assuming someone says "bug U12HSK2" - would probably parse out @mention though
slapp.message(/bug (.+)/, (msg, userToBug) => {
msg.say("you got it, I'll pester them now")
var token = msg.meta.bot_token
slapp.client.im.open({token, user: userToBug}, (err, data) => {
if (err) {
return console.error(err)
}
let channel = data.channel.id
// it would be nice to have a new msg object w/ the channel default to the dm channel we acquired somehow
msg.say({ channel: channel, text: 'Hi, just here to bug you!' })
})
})
The issue there is mainly that we're re-using the same msg
object, overriding the channel, and the way it is, route()
won't work (it would be tied to the original user that messaged still). We've had a use case for taking a msg
object and creating a new one from it w/ new context, i.e. a different user or channel (or both). This could be useful here too. Something like this, not sure on the name msg.copy
though:
// assuming someone says "bug U12HSK2" - would probably parse out @mention though
slapp.message(/bug (.+)/, (msg, userToBug) => {
msg.say("you got it, I'll pester them now")
var token = msg.meta.bot_token
slapp.client.im.open({token, user: userToBug}, (err, data) => {
if (err) {
return console.error(err)
}
let channel = data.channel.id
// something like this to create a new msg scoped to the new user/channel (retains tokens and other metadata this way)
msg.copy({ channel, user: userToBug })
.say('Hey, just here to bug you!')
.route('user-bugged')
})
})
On the fence w/ wrapping the slapp.client.im.open()
call with a helper, would be useful, but couples the library a bit more to a specific slack api (im.open
), and adds more surface area to test/maintain.
from bolt-js.
Good point about opening up a message outside the context of receiving a message, definitely a use case we need to consider. The main challenge there is acquiring the tokens/meta-data on demand for the specific team of the user we want to message. Currently those are all provided via a request-enrichment model (on beep boop extracted from headers). It would be nice to have a generic way to grab team-specific meta-data in more of an ad-hoc fashion, and was agnostic to the persistence of those (similar to the current context lookup middleware). I could see it being an extension of the current context lookup middleware, or related.
from bolt-js.
I'm entirely less experienced in this field, but is it not possible to get the token from the slapp
instance after it connects? Or perhaps on initialization it could be grabbed?
from bolt-js.
That approach would work if you were only concerned about a single slack team that your app has been added to, but you could potentially have many teams running your app.
from bolt-js.
Hmm so perhaps you could specify the team as a parameter to the method and it could get that team's token?
from bolt-js.
ya, something that generates a message
object for you based on a team, and it would have the corresponding message.meta
populated for you (with the tokens and all that other jazz you get via headers on beep boop currently).
from bolt-js.
I'm wondering if there's any progress on this feature. I'm working on a bot supplying a small stats message each day to some of our channels.
from bolt-js.
On the topic: is there currently any way to obtain the teams and bot tokens using BeepBoop platform? I want to implement a scheduled job per team sending a short message to one of the channels every morning.
from bolt-js.
For those interested in the topic this seems to be the answer (using Slack Teams or/with Chronos Scheduler): https://beepboophq.com/docs/api
from bolt-js.
I'm sorry to say, but the maintainers of this project (bolt-js) no longer support the slapp library. Please let us close this issue now.
from bolt-js.
Related Issues (20)
- `too_many_websockets` causes Cannot read properties of undefined (reading 'event') HOT 5
- Cannot respond to incoming message events with `say` using the Bun runtime HOT 5
- Keep getting Error: Cannot write headers after they are sent to the client HOT 3
- How do I create a custom ConsoleLogger? HOT 3
- Better typing for block actions payload HOT 3
- How to access Company ID during OAuth for Slack App Installation HOT 2
- Add docs/sample for using browser cookies to pass custom app data during OAuth flow
- chat.postMessage returns channel name in the response HOT 4
- How do i update "messages_tab_read_only_enabled" to true/false programmatically HOT 6
- Update Ruby version for documentation generation (2.7.6 is end-of-life) HOT 2
- Select menu of external data source - Max number - Problem HOT 5
- The 'value' property on ButtonAction is incorrectly typed HOT 3
- Typing support for built-in middleware handlers
- Japanese document updates reflecting #2136
- Bug: Adding block elements through code make actions disable HOT 12
- How to handle errors with invalid signing secret? HOT 5
- link_shared does not seem to be automatically calling ack() HOT 12
- Event triggered by unknown workspace HOT 3
- Change dependencies -> peerDependencies HOT 3
- Getting We had some trouble connecting. Try again? after updating a view. Using aws lambda. HOT 5
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.