I am sorry for openign this as an issue because I did not get any comment on my stackoverflow question.
have a slack bot which replies to a message send to a user. I do something like this:
import { slackbot } from 'botkit'
`startSlackRtm() {
this.slackObject = slackbot({
require_delivery: true
});
this.slackObject.log("Going to start the slack rtm connection. ");
const slackBot = this.slackObject.spawn({
retry: true,
token: this.botConstants.token
});
slackBot.startRTM((err, bot, payload) => {
if(err) {
this.slackObject.log('error', "RTM connection failed. I will retry in a few seconds. ");
return setTimeout(this.startSlackRtm(), 9000);
}
this.slackObject.log("Slack is running fine now. ");
})
}
reply(bot, username, reply) {
bot.reply({
channel: username
}, reply)
}
slackHears() {
this.slackObject.hears(['.*'], ['direct_message', 'mention'], (bot, message) => {
let userId = message.user, userProfile = {};
bot.api.users.info({
token: this.botConstants.token,
user: userId
}, async(err, res) => {
if (err) this.slackObject.log("error", err);
userProfile = res.user.profile;
let username = userProfile.email.split("@")[0];
this.reply(bot, this.botConstants.defaultChannel, feedbackDetail);
})
})
}`
But I have a use case where I just want to send a notification based on some kafka events or say simply I want to send a message to a user @tom without him interacting with my bot.
How can I do that.. any help will be highly appreciated. Please let me know if you are looking for any more information.
use bot.say() for that instead of bot.reply
can you please share a little more code (in my context)... because I have the bot object only when I hear for direct_message or mention... How can I directly use bot.say()?
Exa.
`this.slackObject.hears(['.*'], ['direct_message', 'mention'], (bot, message) => {
let userId = message.user, userProfile = {};
bot.api.users.info({
token: this.botConstants.token,
user: userId
}, async(err, res) => {
if (err) this.slackObject.log("error", err);
userProfile = res.user.profile;
let username = userProfile.email.split("@")[0];
this.reply(bot, this.botConstants.defaultChannel, feedbackDetail);
})
`})``
Wherever you are monitoring the alert that needs to be send out, inside that function, probably inside your if statement you can write:
controller.spawn({token: config.slack.token, retry: true}, function(bot) {
bot.say({
text: 'Some Text Here',
channel: config.slack.channel
});
});
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.