Closed trajan0x closed 2 months ago
To resolve the issue of OpBot not responding in public channels, follow these steps:
Check Bot Permissions: Ensure the bot has the necessary permissions to read and write in public channels.
Modify Command Handling: Update the NewBot
function in botmd.go
to include a check for public channels.
func NewBot(handler metrics.Handler, cfg config.Config) *Bot {
server := slacker.NewClient(cfg.SlackBotToken, cfg.SlackAppToken)
bot := Bot{
handler: handler,
cfg: cfg,
server: server,
}
// Add a middleware to check for public channels
bot.addMiddleware(bot.publicChannelMiddleware())
if cfg.SignozPassword != "" && cfg.SignozEmail != "" && cfg.SignozBaseURL != "" {
bot.signozClient = signoz.NewClientFromUser(handler, cfg.SignozBaseURL, cfg.SignozEmail, cfg.SignozPassword)
bot.signozEnabled = true
}
bot.rpcClient = omnirpcClient.NewOmnirpcClient(cfg.OmniRPCURL, handler, omnirpcClient.WithCaptureReqRes())
bot.addMiddleware(bot.tracingMiddleware(), bot.metricsMiddleware())
bot.addCommands(bot.traceCommand(), bot.rfqLookupCommand(), bot.rfqRefund())
return &bot
}
publicChannelMiddleware
in middleware.go
to handle public channels.func (b *Bot) publicChannelMiddleware() slacker.CommandMiddlewareHandler {
return func(next slacker.CommandHandler) slacker.CommandHandler {
return func(cmdCtx *slacker.CommandContext) {
if cmdCtx.Event().Channel.IsPublic {
next(cmdCtx)
} else {
cmdCtx.Response().Reply("This command can only be used in public channels.")
}
}
}
}
These changes should ensure that the bot responds appropriately in public channels.
/contrib/opbot/botmd/botmd.go /contrib/opbot/botmd/middleware.go /contrib/opbot
Appears to be introduced here: #2806