From 3452662b720559356f412cd58fbf32df9e2a34c0 Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 29 Mar 2019 14:19:39 +0000 Subject: [PATCH] add line push message api --- router/api/line.go | 22 ++++++++++++++++++++++ router/routes/routes.go | 1 + 2 files changed, 23 insertions(+) diff --git a/router/api/line.go b/router/api/line.go index 28c8490..5142e7d 100644 --- a/router/api/line.go +++ b/router/api/line.go @@ -6,10 +6,32 @@ import ( "strconv" "git.trj.tw/golang/mtfosbot/model" + "git.trj.tw/golang/mtfosbot/module/apis/line" "git.trj.tw/golang/mtfosbot/module/context" "git.trj.tw/golang/mtfosbot/module/utils" ) +// PushMessage - +func PushLineMessage(c *context.Context) { + bodyData := struct { + Group string `json:"group,required"` + Message string `json:"message,required"` + }{} + + err := c.BindData(&bodyData) + if err != nil { + c.DataFormat(nil) + return + } + + textObj := line.TextMessage{} + textObj.Text = bodyData.Message + + line.PushMessage(bodyData.Group, textObj) + + c.Success(nil) +} + // GetLineList - func GetLineList(c *context.Context) { ls, err := model.GetLineGroupList() diff --git a/router/routes/routes.go b/router/routes/routes.go index 3d3ca8d..b49362c 100644 --- a/router/routes/routes.go +++ b/router/routes/routes.go @@ -76,6 +76,7 @@ func SetRoutes(r *gin.Engine) { }) apiGroup.POST("/login", context.PatchCtx(api.UserLogin)) apiGroup.POST("/logout", context.PatchCtx(api.UserLogout)) + apiGroup.POST("/line/push", context.PatchCtx(api.CheckSession), context.PatchCtx(api.PushLineMessage)) apiGroup.GET("/line/logs", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetLineMessageLog)) apiGroup.GET("/line/groups", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetLineList)) apiGroup.GET("/line/cmds", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetCommandList))