modify line command multiple reply or push message
This commit is contained in:
parent
afc0987d40
commit
cc67ba4738
@ -104,9 +104,9 @@ func checkMessageObject(m interface{}) interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PushMessage -
|
// PushMessage -
|
||||||
func PushMessage(target string, message interface{}) {
|
func PushMessage(target string, message ...interface{}) {
|
||||||
log.Println("push target :::: ", target)
|
log.Println("push target :::: ", target)
|
||||||
if len(target) == 0 {
|
if len(target) == 0 || len(message) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
urlPath := "/v2/bot/message/push"
|
urlPath := "/v2/bot/message/push"
|
||||||
@ -115,9 +115,19 @@ func PushMessage(target string, message interface{}) {
|
|||||||
To: target,
|
To: target,
|
||||||
}
|
}
|
||||||
|
|
||||||
message = checkMessageObject(message)
|
checked := make([]interface{}, 0)
|
||||||
|
for _, v := range message {
|
||||||
|
tmp := checkMessageObject(v)
|
||||||
|
if tmp == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
checked = append(checked, tmp)
|
||||||
|
}
|
||||||
|
|
||||||
body.Messages = append(body.Messages, message)
|
body.Messages = append(body.Messages, checked...)
|
||||||
|
if len(body.Messages) > 5 {
|
||||||
|
body.Messages = body.Messages[:5]
|
||||||
|
}
|
||||||
dataByte, err := json.Marshal(body)
|
dataByte, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("to json error ::::", err)
|
log.Println("to json error ::::", err)
|
||||||
@ -153,8 +163,8 @@ func PushMessage(target string, message interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReplyMessage -
|
// ReplyMessage -
|
||||||
func ReplyMessage(replyToken string, message interface{}) {
|
func ReplyMessage(replyToken string, message ...interface{}) {
|
||||||
if len(replyToken) == 0 {
|
if len(replyToken) == 0 || len(message) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
urlPath := "/v2/bot/message/reply"
|
urlPath := "/v2/bot/message/reply"
|
||||||
@ -163,9 +173,19 @@ func ReplyMessage(replyToken string, message interface{}) {
|
|||||||
ReplyToken: replyToken,
|
ReplyToken: replyToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
message = checkMessageObject(message)
|
checked := make([]interface{}, 0)
|
||||||
|
for _, v := range message {
|
||||||
|
tmp := checkMessageObject(v)
|
||||||
|
if tmp == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
checked = append(checked, tmp)
|
||||||
|
}
|
||||||
|
|
||||||
body.Messages = append(body.Messages, message)
|
body.Messages = append(body.Messages, checked...)
|
||||||
|
if len(body.Messages) > 5 {
|
||||||
|
body.Messages = body.Messages[:5]
|
||||||
|
}
|
||||||
dataByte, err := json.Marshal(body)
|
dataByte, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -51,9 +51,13 @@ func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
str := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
resStrs := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
||||||
m := parseResult(str)
|
msgs := make([]interface{}, 0)
|
||||||
line.ReplyMessage(replyToken, m)
|
for _, v := range resStrs {
|
||||||
|
m := parseResult(v)
|
||||||
|
msgs = append(msgs, m)
|
||||||
|
}
|
||||||
|
line.ReplyMessage(replyToken, msgs...)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// key cmd
|
// key cmd
|
||||||
@ -62,9 +66,13 @@ func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
str := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
resStrs := runCMD(strings.Join(strs[1:], " "), c.Message, source)
|
||||||
m := parseResult(str)
|
msgs := make([]interface{}, 0)
|
||||||
line.ReplyMessage(replyToken, m)
|
for _, v := range resStrs {
|
||||||
|
m := parseResult(v)
|
||||||
|
msgs = append(msgs, m)
|
||||||
|
}
|
||||||
|
line.ReplyMessage(replyToken, msgs...)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,12 +103,18 @@ func parseResult(str string) interface{} {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCMD(txt, c string, s *lineobj.SourceObject) (res string) {
|
func runCMD(txt, c string, s *lineobj.SourceObject) (res []string) {
|
||||||
|
cmds := strings.Split(c, "$#$")
|
||||||
|
if len(cmds) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, c := range cmds {
|
||||||
cmdAct := parseCMD(c)
|
cmdAct := parseCMD(c)
|
||||||
if len(cmdAct) == 0 {
|
if len(cmdAct) == 0 {
|
||||||
return c
|
res = append(res, c)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
res = c
|
tmpRes := c
|
||||||
for _, v := range cmdAct {
|
for _, v := range cmdAct {
|
||||||
if len(v) > 1 {
|
if len(v) > 1 {
|
||||||
// run cmd
|
// run cmd
|
||||||
@ -110,8 +124,10 @@ func runCMD(txt, c string, s *lineobj.SourceObject) (res string) {
|
|||||||
sub = strings.Join(m[1:], " ")
|
sub = strings.Join(m[1:], " ")
|
||||||
}
|
}
|
||||||
cmdRes := selectAct(m[0], sub, txt, s)
|
cmdRes := selectAct(m[0], sub, txt, s)
|
||||||
res = strings.Replace(res, v[0], cmdRes, 1)
|
tmpRes = strings.Replace(tmpRes, v[0], cmdRes, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
res = append(res, tmpRes)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user