in user-center-slack/importer.go [159:193]
func (uc *UserCenter) SlashCommand(ctx *gin.Context) {
body, _ := io.ReadAll(ctx.Request.Body)
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(body))
cmd := ctx.PostForm("command")
if cmd != "/ask" {
log.Errorf("error: Invalid command")
ctx.JSON(http.StatusBadRequest, gin.H{"text": "Invalid command"})
return
}
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(body))
err := uc.verifySlackRequest(ctx)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"text": "Slack request verification faild"})
log.Errorf("error: %v", err)
return
}
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(body))
questionInfo, err := uc.GetQuestion(ctx)
if err != nil {
log.Errorf("error: %v", err)
ctx.JSON(200, gin.H{"text": err.Error()})
return
}
if uc.importerFunc == nil {
log.Errorf("error: importerFunc is not initialized")
return
}
err = uc.importerFunc.AddQuestion(ctx, questionInfo)
if err != nil {
log.Errorf("error: %v", err)
ctx.JSON(http.StatusBadRequest, gin.H{"text": "Failed to add question"})
return
}
ctx.JSON(http.StatusOK, gin.H{"text": "Question has been added successfully"})
}