2023-04-10 17:30:28 +05:30
|
|
|
package processor
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2023-06-13 03:23:24 +05:30
|
|
|
"github.com/slack-go/slack/socketmode"
|
2023-04-12 21:46:03 +05:30
|
|
|
"houston/internal/processor/action"
|
2023-11-02 13:11:52 +05:30
|
|
|
"houston/logger"
|
2023-05-11 17:56:34 +05:30
|
|
|
"houston/pkg/slackbot"
|
2024-02-01 15:23:15 +05:30
|
|
|
rcaService "houston/service/rca/impl"
|
2023-04-10 17:30:28 +05:30
|
|
|
)
|
|
|
|
|
|
2023-06-13 03:23:24 +05:30
|
|
|
type CommandProcessor interface {
|
|
|
|
|
ProcessSlashCommand(event *socketmode.Event)
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 17:30:28 +05:30
|
|
|
type SlashCommandProcessor struct {
|
|
|
|
|
socketModeClient *socketmode.Client
|
2023-11-30 11:56:32 +05:30
|
|
|
slashCommandAction *action.HoustonCommandAction
|
2023-04-10 17:30:28 +05:30
|
|
|
}
|
|
|
|
|
|
2023-06-13 03:23:24 +05:30
|
|
|
func NewSlashCommandProcessor(
|
2023-11-30 11:56:32 +05:30
|
|
|
socketModeClient *socketmode.Client,
|
|
|
|
|
slackBot *slackbot.Client,
|
2024-02-01 15:23:15 +05:30
|
|
|
rcaService *rcaService.RcaService,
|
2023-06-13 03:23:24 +05:30
|
|
|
) *SlashCommandProcessor {
|
2023-04-10 17:30:28 +05:30
|
|
|
return &SlashCommandProcessor{
|
|
|
|
|
socketModeClient: socketModeClient,
|
2023-11-30 11:56:32 +05:30
|
|
|
slashCommandAction: action.NewHoustonCommandAction(socketModeClient, slackBot, rcaService),
|
2023-04-10 17:30:28 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 03:23:24 +05:30
|
|
|
func (scp *SlashCommandProcessor) ProcessSlashCommand(event *socketmode.Event) {
|
2023-04-10 17:30:28 +05:30
|
|
|
defer func() {
|
|
|
|
|
if r := recover(); r != nil {
|
2023-11-02 13:11:52 +05:30
|
|
|
logger.Error(fmt.Sprintf("[SCP] Exception occurred: %v", r.(error)))
|
2023-04-10 17:30:28 +05:30
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
2023-06-13 03:23:24 +05:30
|
|
|
scp.slashCommandAction.PerformAction(event)
|
|
|
|
|
}
|