I've been playing around with Bolt to replace Botkit and I'm having some trouble getting directMention to work for messages sent in direct message to the bot. Code snippet and debug logs below.
x in one of the [ ])x in each of the [ ])Filling out the following details about bugs will help us solve your issue sooner.
package version: 1.5.0
node version: 12.14.1
OS version(s): Windows 10
A channel of the type "im" should be considered a directMention.
app.message never executes if directMention is used.
app.js
const { App, directMention, LogLevel } = require('@slack/bolt');
// Initializes your app with your bot token and signing secret
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
logLevel: LogLevel.DEBUG
});
function logPayload({payload, next}) {
console.log(
`Inside logPayload
Type: ${payload.type}, Text: ${payload.text}, Channel Type: ${payload.channel_type}`
);
next()
}
app.use(logPayload);
(async () => {
// Start your app
await app.start(process.env.PORT || 3001);
console.log('鈿★笍 Bolt app is running!');
})();
app.message(directMention(), 'howdy', ({ message, say }) => {
console.log(
`Inside howdy
Type: ${message.type}, Text: ${message.text}, Channel Type: ${message.channel_type}`
);
say('Howdy back');
});
Debug logs with results from above.
[DEBUG] The logLevel given to WebClient was ignored as you also gave logger
[DEBUG] initialized
[DEBUG] apiCall('auth.test') start
[DEBUG] will perform http request
鈿★笍 Bolt app is running!
[DEBUG] http response received
[DEBUG] Conversation context not loaded: Conversation not found
Inside logPayload
Type: message, Text: howdy, Channel Type: im
Since creating this issue, I upgraded the bots OAuth scope from "bot" to the new granular permissions, leaving all of the existing permissions selected. Now the bot only responds in direct message when using directMention when I @botname someCommand. It no longer responds in channels when directMention is used in the same way.
This is likely a separate issue, but figured I would bring it up.
Hey @kmartin-isp,
One of the changes that came with granular bot permissions is that bots can only post in channels that they are already a member of. This is most likely why you aren't seeing the bot posting in those channels. You can invite the bot to a channel using the slack interface and the /invite command. Or you can invite them programmatically by using conversations.join method and channels:join.
We are working on offering a new scope that would allow bots to post to a public channel without joining it. You can see more about it at https://api.slack.com/authentication/quickstart#coming_soon.
Hope that answers your questions.
@stevengill is there any work being done to allow bots to post in private channels and direct messages as the bot (and not in response to a slash command or the user pressing a button) ?
I had another issue and was also curious if this will be possible in the future.
@jacklein Let me answer on behalf of him. Unfortunately, the Slack team doesn't have plans to offer a similar ability for private channels and DMs at the moment. As I guided at #401, your feedback from the Help Center would be greatly appreciated.
Digressing to the original ask (instead of creating a separate issue):
In Hubot, I could use robot.respond() and it would do two things:
Since directMention requires an @mention (regardless of the conversation type), I think a nice enhancement here would be for either a new middleware to act like this, or an update to directMention() that will handle both.
That way, developers can easily create something that doesn't require users to @mention the bot within a DM (which is somewhat redundant)
Most helpful comment
Digressing to the original ask (instead of creating a separate issue):
In Hubot, I could use
robot.respond()and it would do two things:Since directMention requires an @mention (regardless of the conversation type), I think a nice enhancement here would be for either a new middleware to act like this, or an update to directMention() that will handle both.
That way, developers can easily create something that doesn't require users to @mention the bot within a DM (which is somewhat redundant)