add pre group one bot setting
This commit is contained in:
+14
-1
@@ -27,7 +27,20 @@ func PushLineMessage(c *context.Context) {
|
||||
textObj := line.TextMessage{}
|
||||
textObj.Text = bodyData.Message
|
||||
|
||||
line.PushMessage(bodyData.Group, textObj)
|
||||
group, err := model.GetLineGroup(bodyData.Group)
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
log.Println("get group :: ", err)
|
||||
return
|
||||
}
|
||||
bot, err := group.GetBot()
|
||||
if err != nil || bot == nil {
|
||||
log.Println("get group binding bot fail :: ", err)
|
||||
c.ServerError(nil)
|
||||
return
|
||||
}
|
||||
|
||||
line.PushMessage(bot.AccessToken, bodyData.Group, textObj)
|
||||
|
||||
c.Success(nil)
|
||||
}
|
||||
|
||||
@@ -129,6 +129,11 @@ func GetNotifyWebhook(c *context.Context) {
|
||||
|
||||
for _, v := range yt.Groups {
|
||||
log.Println("group data :::: ", v, v.Notify, v.Name, v.ID)
|
||||
bot, err := v.GetBot()
|
||||
if err != nil || bot == nil {
|
||||
log.Println("get group binding bot fail :: ", err)
|
||||
continue
|
||||
}
|
||||
if v.Notify == true {
|
||||
str := v.Tmpl
|
||||
log.Println("template :::: ", str)
|
||||
@@ -144,7 +149,7 @@ func GetNotifyWebhook(c *context.Context) {
|
||||
}
|
||||
log.Println("msg ::::: ", msg)
|
||||
|
||||
lineapi.PushMessage(v.ID, msg)
|
||||
lineapi.PushMessage(bot.AccessToken, v.ID, msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-6
@@ -7,9 +7,9 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
|
||||
"git.trj.tw/golang/mtfosbot/module/config"
|
||||
"git.trj.tw/golang/mtfosbot/model"
|
||||
"git.trj.tw/golang/mtfosbot/module/context"
|
||||
"git.trj.tw/golang/mtfosbot/module/line-message"
|
||||
linemsg "git.trj.tw/golang/mtfosbot/module/line-message"
|
||||
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
|
||||
)
|
||||
|
||||
@@ -42,10 +42,21 @@ func VerifyLine(c *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
conf := config.GetConf()
|
||||
botid, ok := c.GetQuery("id")
|
||||
if !ok || len(botid) == 0 {
|
||||
c.CustomRes(403, map[string]string{
|
||||
"message": "no bot data",
|
||||
})
|
||||
}
|
||||
|
||||
hash := hmac.New(sha256.New, []byte(conf.Line.Secret))
|
||||
_, err := hash.Write(raw)
|
||||
bot, err := model.GetBotInfo(botid)
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
return
|
||||
}
|
||||
|
||||
hash := hmac.New(sha256.New, []byte(bot.Secret))
|
||||
_, err = hash.Write(raw)
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
return
|
||||
@@ -70,6 +81,12 @@ func GetLineMessage(c *context.Context) {
|
||||
if raw, ok = rawbody.([]byte); !ok {
|
||||
c.DataFormat("body type error")
|
||||
}
|
||||
botid, ok := c.GetQuery("id")
|
||||
if !ok || len(botid) == 0 {
|
||||
c.CustomRes(403, map[string]string{
|
||||
"message": "no bot data",
|
||||
})
|
||||
}
|
||||
|
||||
events := struct {
|
||||
Events []*lineobj.EventObject `json:"events"`
|
||||
@@ -83,7 +100,7 @@ func GetLineMessage(c *context.Context) {
|
||||
|
||||
if len(events.Events) > 0 {
|
||||
for _, v := range events.Events {
|
||||
go linemsg.MessageEvent(v)
|
||||
go linemsg.MessageEvent(botid, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package private
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.trj.tw/golang/mtfosbot/model"
|
||||
@@ -107,6 +108,11 @@ func UpdateFacebookPagePost(c *context.Context) {
|
||||
|
||||
for _, g := range page.Groups {
|
||||
if g.Notify {
|
||||
bot, err := g.GetBot()
|
||||
if err != nil || bot == nil {
|
||||
log.Println("get group binding bot fail ::: ", err)
|
||||
continue
|
||||
}
|
||||
tmpl := g.Tmpl
|
||||
if len(tmpl) > 0 {
|
||||
tmpl = strings.Replace(tmpl, "{link}", v.Link, -1)
|
||||
@@ -117,7 +123,7 @@ func UpdateFacebookPagePost(c *context.Context) {
|
||||
msg := line.TextMessage{
|
||||
Text: tmpl,
|
||||
}
|
||||
line.PushMessage(g.ID, msg)
|
||||
line.PushMessage(bot.AccessToken, g.ID, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,6 +175,11 @@ func UpdateInstagramPost(c *context.Context) {
|
||||
|
||||
for _, g := range ig.Groups {
|
||||
if g.Notify {
|
||||
bot, err := g.GetBot()
|
||||
if err != nil || bot == nil {
|
||||
log.Println("get group binding bot fail :: ", err)
|
||||
continue
|
||||
}
|
||||
tmpl := g.Tmpl
|
||||
if len(tmpl) > 0 {
|
||||
tmpl = strings.Replace(tmpl, "{link}", v.Link, -1)
|
||||
@@ -178,7 +189,7 @@ func UpdateInstagramPost(c *context.Context) {
|
||||
}
|
||||
|
||||
msg := line.TextMessage{Text: tmpl}
|
||||
line.PushMessage(g.ID, msg)
|
||||
line.PushMessage(bot.AccessToken, g.ID, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user