synapsecns / sanguine

Synapse Monorepo
MIT License
38 stars 29 forks source link

[opbot] not respinding in public channels #2850

Closed trajan0x closed 2 months ago

trajan0x commented 3 months ago
image image

Appears to be introduced here: #2806

greptile-apps[bot] commented 3 months ago

To resolve the issue of OpBot not responding in public channels, follow these steps:

  1. Check Bot Permissions: Ensure the bot has the necessary permissions to read and write in public channels.

  2. 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
}
  1. Implement Middleware: Add a new middleware function 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.

References

/contrib/opbot/botmd/botmd.go /contrib/opbot/botmd/middleware.go /contrib/opbot

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/synapsecns/sanguine/master) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)