vk-webhook-flooder-mock/handler/mg.go
2023-01-13 13:28:05 +03:00

35 lines
795 B
Go

package handler
import (
"log"
"net/http"
"strings"
"sync/atomic"
"time"
"github.com/gin-gonic/gin"
v1 "github.com/retailcrm/mg-transport-api-client-go/v1"
"vk-webhook-flooder-mock/dto"
)
var totalUserless uint32 = 0
func NewMessageHandler(c *gin.Context) {
var snd v1.SendData
if err := c.ShouldBindJSON(&snd); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errors": []string{err.Error()}})
return
}
if strings.HasPrefix(snd.Customer.Firstname, "User #") {
total := atomic.AddUint32(&totalUserless, 1)
log.Printf("MG NewMessageHandler: [%d] Beware! Message external_id=%s has placeholder user.",
total, snd.Message.ExternalID)
}
c.JSON(http.StatusOK, dto.MessagesResponse{
MessageID: int(time.Now().UnixNano()),
Time: time.Now(),
})
}