add video message type

This commit is contained in:
Jay 2018-12-14 15:55:49 +08:00
parent 07281f2ff1
commit 2d622ba31e

View File

@ -29,6 +29,13 @@ type ImageMessage struct {
PreviewImageURL string `json:"previewImageUrl"` PreviewImageURL string `json:"previewImageUrl"`
} }
// VideoMessage - line video message object
type VideoMessage struct {
Type string `json:"type"`
OriginalContentURL string `json:"OriginalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
}
// LineUserInfo - // LineUserInfo -
type LineUserInfo struct { type LineUserInfo struct {
DisplayName string `json:"displayName"` DisplayName string `json:"displayName"`
@ -67,6 +74,35 @@ func getHeaders() map[string]string {
return m return m
} }
func checkMessageObject(m interface{}) interface{} {
if m == nil {
return nil
}
var obj interface{}
switch m.(type) {
case ImageMessage:
tmp := (m.(ImageMessage))
tmp.Type = "image"
obj = tmp
break
case TextMessage:
tmp := (m.(TextMessage))
tmp.Type = "text"
obj = tmp
break
case VideoMessage:
tmp := (m.(VideoMessage))
tmp.Type = "video"
obj = tmp
break
default:
return nil
}
return obj
}
// PushMessage - // PushMessage -
func PushMessage(target string, message interface{}) { func PushMessage(target string, message interface{}) {
log.Println("push target :::: ", target) log.Println("push target :::: ", target)
@ -79,21 +115,8 @@ func PushMessage(target string, message interface{}) {
To: target, To: target,
} }
switch message.(type) { message = checkMessageObject(message)
case ImageMessage:
m := (message.(ImageMessage))
m.Type = "image"
message = m
break
case TextMessage:
m := (message.(TextMessage))
m.Type = "text"
message = m
break
default:
log.Println("no match message type")
return
}
body.Messages = append(body.Messages, message) body.Messages = append(body.Messages, message)
dataByte, err := json.Marshal(body) dataByte, err := json.Marshal(body)
if err != nil { if err != nil {
@ -140,21 +163,7 @@ func ReplyMessage(replyToken string, message interface{}) {
ReplyToken: replyToken, ReplyToken: replyToken,
} }
switch message.(type) { message = checkMessageObject(message)
case *ImageMessage:
m := (message.(*ImageMessage))
m.Type = "image"
message = m
break
case *TextMessage:
m := (message.(*TextMessage))
m.Type = "text"
message = m
break
default:
fmt.Println("input type error")
return
}
body.Messages = append(body.Messages, message) body.Messages = append(body.Messages, message)
dataByte, err := json.Marshal(body) dataByte, err := json.Marshal(body)