From e4c2d9673ba45ec48c4cdd9122cda3d7dab78e0d Mon Sep 17 00:00:00 2001 From: Artyom Belousov Date: Sat, 11 May 2019 17:06:01 +0300 Subject: [PATCH] Added auth opportunity for VK callback API --- main.go | 2 +- vk/handlers.go | 5 ++++- vk/structs.go | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 0a49521..7d5c049 100644 --- a/main.go +++ b/main.go @@ -11,5 +11,5 @@ func main() { rand.Seed(time.Now().UTC().UnixNano()) r := gin.Default() r.POST("callback/message", vk.HandleMessage) - r.Run() + r.Run(":80") } diff --git a/vk/handlers.go b/vk/handlers.go index 45f41a1..7865a7c 100644 --- a/vk/handlers.go +++ b/vk/handlers.go @@ -7,12 +7,15 @@ import ( ) func HandleMessage(c *gin.Context) { - defer c.String(http.StatusOK, "ok") var req MessageRequest c.BindJSON(&req) + if (req.Type == "confirmation") && (req.GroupId == GROUPID) { + c.String(http.StatusOK, CONFIRMATION_STRING) + } if req.Secret != SECRET_KEY { return } cardName := cardsinfo.GetOriginalName(req.Object.Body) Message(req.Object.UserId, cardName) + c.String(http.StatusOK, "ok") } diff --git a/vk/structs.go b/vk/structs.go index ee1ef27..5593699 100644 --- a/vk/structs.go +++ b/vk/structs.go @@ -1,8 +1,10 @@ package vk type MessageRequest struct { - Object UserMessage `json:"object"` - Secret string `json:"secret"` + Type string `json:"type"` + GroupId int64 `json:"group_id"` + Object UserMessage `json:"object"` + Secret string `json:"secret"` } type UserMessage struct {