add tags in sentry
This commit is contained in:
parent
e4e645a075
commit
bf853827a4
@ -67,6 +67,30 @@ func ErrorCaptureHandler(client *raven.Client, errorsStacktrace bool) ErrorHandl
|
||||
"endpoint": c.Request.RequestURI,
|
||||
}
|
||||
|
||||
var (
|
||||
ok bool
|
||||
conn Connection
|
||||
)
|
||||
|
||||
connection, ok := c.Get("connection")
|
||||
if ok {
|
||||
conn = connection.(Connection)
|
||||
}
|
||||
|
||||
b, ok := c.Get("bot")
|
||||
if ok {
|
||||
tags["bot"] = b.(Bot).Token
|
||||
conn = *getConnectionById(b.(Bot).ConnectionID)
|
||||
}
|
||||
|
||||
if conn.APIURL != "" {
|
||||
tags["crm"] = conn.APIURL
|
||||
}
|
||||
|
||||
if conn.ClientID != "" {
|
||||
tags["clientID"] = conn.ClientID
|
||||
}
|
||||
|
||||
if recovery != nil {
|
||||
stacktrace := raven.NewStacktrace(4, 3, nil)
|
||||
recStr := fmt.Sprint(recovery)
|
||||
|
@ -406,17 +406,7 @@ func updateBots(conn *Connection, hashSettings string) {
|
||||
}
|
||||
|
||||
func telegramWebhookHandler(c *gin.Context) {
|
||||
token := c.Param("token")
|
||||
b, err := getBotByToken(token)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if b.ID == 0 {
|
||||
c.AbortWithStatus(http.StatusOK)
|
||||
return
|
||||
}
|
||||
b := c.MustGet("bot").(Bot)
|
||||
|
||||
conn := getConnectionById(b.ConnectionID)
|
||||
if !conn.Active {
|
||||
@ -559,17 +549,7 @@ func telegramWebhookHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
func mgWebhookHandler(c *gin.Context) {
|
||||
clientID := c.GetHeader("Clientid")
|
||||
if clientID == "" {
|
||||
c.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
conn := getConnection(clientID)
|
||||
if !conn.Active {
|
||||
c.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
conn := c.MustGet("connection").(Connection)
|
||||
|
||||
var msg v1.WebhookRequest
|
||||
if err := c.ShouldBindJSON(&msg); err != nil {
|
||||
|
42
src/run.go
42
src/run.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
@ -92,8 +93,8 @@ func setup() *gin.Engine {
|
||||
r.POST("/delete-bot/", checkBotForRequest(), deleteBotHandler)
|
||||
r.POST("/set-lang/", checkBotForRequest(), setLangBotHandler)
|
||||
r.POST("/actions/activity", activityHandler)
|
||||
r.POST("/telegram/:token", telegramWebhookHandler)
|
||||
r.POST("/webhook/", mgWebhookHandler)
|
||||
r.POST("/telegram/:token", checkBotForWebhook(), telegramWebhookHandler)
|
||||
r.POST("/webhook/", checkConnectionForWebhook(), mgWebhookHandler)
|
||||
|
||||
return r
|
||||
}
|
||||
@ -147,3 +148,40 @@ func checkConnectionForRequest() gin.HandlerFunc {
|
||||
c.Set("connection", conn)
|
||||
}
|
||||
}
|
||||
|
||||
func checkConnectionForWebhook() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
clientID := c.GetHeader("Clientid")
|
||||
if clientID == "" {
|
||||
c.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
conn := getConnection(clientID)
|
||||
if !conn.Active {
|
||||
c.AbortWithStatus(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("connection", *conn)
|
||||
}
|
||||
}
|
||||
|
||||
func checkBotForWebhook() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
token := c.Param("token")
|
||||
|
||||
b, err := getBotByToken(token)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if b.ID == 0 {
|
||||
c.AbortWithStatus(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("bot", *b)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user