Added auth opportunity for VK callback API

This commit is contained in:
Artyom Belousov 2019-05-11 17:06:01 +03:00
parent 657f967a49
commit e4c2d9673b
3 changed files with 9 additions and 4 deletions

View file

@ -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")
}

View file

@ -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 {