Skip to content

Commit 4549232

Browse files
authored
Merge pull request #135 from sugyan/issue-108
Update for playing videos in imagemap messages
2 parents 0359c69 + 17234fe commit 4549232

File tree

6 files changed

+85
-43
lines changed

6 files changed

+85
-43
lines changed

examples/kitchensink/server.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,35 @@ func (app *KitchenSink) handleText(message *linebot.TextMessage, replyToken stri
545545
linebot.NewImagemapMessage(
546546
app.appBaseURL+"/static/rich",
547547
"Imagemap alt text",
548-
linebot.ImagemapBaseSize{1040, 1040},
549-
linebot.NewURIImagemapAction("https://store.line.me/family/manga/en", linebot.ImagemapArea{0, 0, 520, 520}),
550-
linebot.NewURIImagemapAction("https://store.line.me/family/music/en", linebot.ImagemapArea{520, 0, 520, 520}),
551-
linebot.NewURIImagemapAction("https://store.line.me/family/play/en", linebot.ImagemapArea{0, 520, 520, 520}),
552-
linebot.NewMessageImagemapAction("URANAI!", linebot.ImagemapArea{520, 520, 520, 520}),
548+
linebot.ImagemapBaseSize{Width: 1040, Height: 1040},
549+
linebot.NewURIImagemapAction("https://store.line.me/family/manga/en", linebot.ImagemapArea{X: 0, Y: 0, Width: 520, Height: 520}),
550+
linebot.NewURIImagemapAction("https://store.line.me/family/music/en", linebot.ImagemapArea{X: 520, Y: 0, Width: 520, Height: 520}),
551+
linebot.NewURIImagemapAction("https://store.line.me/family/play/en", linebot.ImagemapArea{X: 0, Y: 520, Width: 520, Height: 520}),
552+
linebot.NewMessageImagemapAction("URANAI!", linebot.ImagemapArea{X: 520, Y: 520, Width: 520, Height: 520}),
553553
),
554554
).Do(); err != nil {
555555
return err
556556
}
557+
case "imagemap video":
558+
if _, err := app.bot.ReplyMessage(
559+
replyToken,
560+
linebot.NewImagemapMessage(
561+
app.appBaseURL+"/static/rich",
562+
"Imagemap with video alt text",
563+
linebot.ImagemapBaseSize{Width: 1040, Height: 1040},
564+
linebot.NewURIImagemapAction("https://store.line.me/family/manga/en", linebot.ImagemapArea{X: 0, Y: 0, Width: 520, Height: 520}),
565+
linebot.NewURIImagemapAction("https://store.line.me/family/music/en", linebot.ImagemapArea{X: 520, Y: 0, Width: 520, Height: 520}),
566+
linebot.NewURIImagemapAction("https://store.line.me/family/play/en", linebot.ImagemapArea{X: 0, Y: 520, Width: 520, Height: 520}),
567+
linebot.NewMessageImagemapAction("URANAI!", linebot.ImagemapArea{X: 520, Y: 520, Width: 520, Height: 520}),
568+
).WithVideo(&linebot.ImagemapVideo{
569+
OriginalContentURL: app.appBaseURL + "/static/imagemap/video.mp4",
570+
PreviewImageURL: app.appBaseURL + "/static/imagemap/preview.jpg",
571+
Area: linebot.ImagemapArea{X: 280, Y: 385, Width: 480, Height: 270},
572+
ExternalLink: &linebot.ImagemapVideoExternalLink{LinkURI: "https://line.me", Label: "LINE"},
573+
}),
574+
).Do(); err != nil {
575+
return err
576+
}
557577
case "quick":
558578
if _, err := app.bot.ReplyMessage(
559579
replyToken,
80.2 KB
Loading
1.73 MB
Binary file not shown.

linebot/imagemap.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ type ImagemapArea struct {
4343

4444
// ImagemapVideo type
4545
type ImagemapVideo struct {
46-
OriginalContentURL string `json:"originalContentUrl"`
47-
PreviewImageURL string `json:"previewImageUrl"`
48-
Area ImagemapArea `json:"area"`
49-
ExternalLink *ExternalLink `json:"externalLink,omitempty"`
46+
OriginalContentURL string `json:"originalContentUrl"`
47+
PreviewImageURL string `json:"previewImageUrl"`
48+
Area ImagemapArea `json:"area"`
49+
ExternalLink *ImagemapVideoExternalLink `json:"externalLink,omitempty"`
5050
}
5151

52-
// ExternalLink type
53-
type ExternalLink struct {
52+
// ImagemapVideoExternalLink type
53+
type ImagemapVideoExternalLink struct {
5454
LinkURI string `json:"linkUri"`
5555
Label string `json:"label"`
5656
}

linebot/message.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ func (m *ImagemapMessage) MarshalJSON() ([]byte, error) {
297297
})
298298
}
299299

300+
// WithVideo method
301+
func (m *ImagemapMessage) WithVideo(video *ImagemapVideo) *ImagemapMessage {
302+
m.Video = video
303+
return m
304+
}
305+
300306
// WithQuickReplies method of ImagemapMessage
301307
func (m *ImagemapMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
302308
m.quickReplyitems = items

linebot/send_message_test.go

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -326,43 +326,59 @@ func TestPushMessages(t *testing.T) {
326326
NewURIImagemapAction("https://example.com/", ImagemapArea{520, 0, 520, 1040}),
327327
NewMessageImagemapAction("hello", ImagemapArea{520, 0, 520, 1040}),
328328
),
329-
&ImagemapMessage{
330-
BaseURL: "https://example.com/bot/images/rm001",
331-
AltText: "this is an imagemap",
332-
BaseSize: ImagemapBaseSize{1040, 1040},
333-
Actions: []ImagemapAction{
334-
NewURIImagemapAction("https://example.com/", ImagemapArea{520, 0, 520, 1040}),
335-
NewMessageImagemapAction("hello", ImagemapArea{520, 0, 520, 1040}),
336-
},
337-
Video: &ImagemapVideo{
338-
OriginalContentURL: "https://example.com/original.mp4",
339-
PreviewImageURL: "https://example.com/preview.jpg",
340-
Area: ImagemapArea{10, 10, 100, 200},
341-
},
342-
},
343-
&ImagemapMessage{
344-
BaseURL: "https://example.com/bot/images/rm001",
345-
AltText: "this is an imagemap external link",
346-
BaseSize: ImagemapBaseSize{1040, 1040},
347-
Actions: []ImagemapAction{
348-
NewURIImagemapAction("https://example.com/", ImagemapArea{520, 0, 520, 1040}),
349-
NewMessageImagemapAction("hello", ImagemapArea{520, 0, 520, 1040}),
350-
},
351-
Video: &ImagemapVideo{
352-
OriginalContentURL: "https://example.com/original.mp4",
353-
PreviewImageURL: "https://example.com/preview.jpg",
354-
Area: ImagemapArea{10, 10, 100, 200},
355-
ExternalLink: &ExternalLink{
356-
LinkURI: "https://example.com/",
357-
Label: "external link",
358-
},
329+
},
330+
ResponseCode: 200,
331+
Response: []byte(`{}`),
332+
Want: want{
333+
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"imagemap","baseUrl":"https://example.com/bot/images/rm001","altText":"this is an imagemap","baseSize":{"width":1040,"height":1040},"actions":[{"type":"uri","linkUri":"https://example.com/","area":{"x":520,"y":0,"width":520,"height":1040}},{"type":"message","text":"hello","area":{"x":520,"y":0,"width":520,"height":1040}}]}]}` + "\n"),
334+
Response: &BasicResponse{},
335+
},
336+
},
337+
{
338+
// A imagemap messages with video 1
339+
Messages: []SendingMessage{
340+
NewImagemapMessage(
341+
"https://example.com/bot/images/rm001",
342+
"this is an imagemap with video",
343+
ImagemapBaseSize{1040, 1040},
344+
NewURIImagemapAction("https://example.com/", ImagemapArea{520, 0, 520, 1040}),
345+
NewMessageImagemapAction("hello", ImagemapArea{520, 0, 520, 1040}),
346+
).WithVideo(&ImagemapVideo{
347+
OriginalContentURL: "https://example.com/original.mp4",
348+
PreviewImageURL: "https://example.com/preview.jpg",
349+
Area: ImagemapArea{10, 10, 100, 200},
350+
}),
351+
},
352+
ResponseCode: 200,
353+
Response: []byte(`{}`),
354+
Want: want{
355+
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"imagemap","baseUrl":"https://example.com/bot/images/rm001","altText":"this is an imagemap with video","baseSize":{"width":1040,"height":1040},"actions":[{"type":"uri","linkUri":"https://example.com/","area":{"x":520,"y":0,"width":520,"height":1040}},{"type":"message","text":"hello","area":{"x":520,"y":0,"width":520,"height":1040}}],"video":{"originalContentUrl":"https://example.com/original.mp4","previewImageUrl":"https://example.com/preview.jpg","area":{"x":10,"y":10,"width":100,"height":200}}}]}` + "\n"),
356+
Response: &BasicResponse{},
357+
},
358+
},
359+
{
360+
// A imagemap messages with video 2
361+
Messages: []SendingMessage{
362+
NewImagemapMessage(
363+
"https://example.com/bot/images/rm001",
364+
"this is an imagemap with video and external link",
365+
ImagemapBaseSize{1040, 1040},
366+
NewURIImagemapAction("https://example.com/", ImagemapArea{520, 0, 520, 1040}),
367+
NewMessageImagemapAction("hello", ImagemapArea{520, 0, 520, 1040}),
368+
).WithVideo(&ImagemapVideo{
369+
OriginalContentURL: "https://example.com/original.mp4",
370+
PreviewImageURL: "https://example.com/preview.jpg",
371+
Area: ImagemapArea{10, 10, 100, 200},
372+
ExternalLink: &ImagemapVideoExternalLink{
373+
LinkURI: "https://example.com/",
374+
Label: "external link",
359375
},
360-
},
376+
}),
361377
},
362378
ResponseCode: 200,
363379
Response: []byte(`{}`),
364380
Want: want{
365-
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"imagemap","baseUrl":"https://example.com/bot/images/rm001","altText":"this is an imagemap","baseSize":{"width":1040,"height":1040},"actions":[{"type":"uri","linkUri":"https://example.com/","area":{"x":520,"y":0,"width":520,"height":1040}},{"type":"message","text":"hello","area":{"x":520,"y":0,"width":520,"height":1040}}]},{"type":"imagemap","baseUrl":"https://example.com/bot/images/rm001","altText":"this is an imagemap","baseSize":{"width":1040,"height":1040},"actions":[{"type":"uri","linkUri":"https://example.com/","area":{"x":520,"y":0,"width":520,"height":1040}},{"type":"message","text":"hello","area":{"x":520,"y":0,"width":520,"height":1040}}],"video":{"originalContentUrl":"https://example.com/original.mp4","previewImageUrl":"https://example.com/preview.jpg","area":{"x":10,"y":10,"width":100,"height":200}}},{"type":"imagemap","baseUrl":"https://example.com/bot/images/rm001","altText":"this is an imagemap external link","baseSize":{"width":1040,"height":1040},"actions":[{"type":"uri","linkUri":"https://example.com/","area":{"x":520,"y":0,"width":520,"height":1040}},{"type":"message","text":"hello","area":{"x":520,"y":0,"width":520,"height":1040}}],"video":{"originalContentUrl":"https://example.com/original.mp4","previewImageUrl":"https://example.com/preview.jpg","area":{"x":10,"y":10,"width":100,"height":200},"externalLink":{"linkUri":"https://example.com/","label":"external link"}}}]}` + "\n"),
381+
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"imagemap","baseUrl":"https://example.com/bot/images/rm001","altText":"this is an imagemap with video and external link","baseSize":{"width":1040,"height":1040},"actions":[{"type":"uri","linkUri":"https://example.com/","area":{"x":520,"y":0,"width":520,"height":1040}},{"type":"message","text":"hello","area":{"x":520,"y":0,"width":520,"height":1040}}],"video":{"originalContentUrl":"https://example.com/original.mp4","previewImageUrl":"https://example.com/preview.jpg","area":{"x":10,"y":10,"width":100,"height":200},"externalLink":{"linkUri":"https://example.com/","label":"external link"}}}]}` + "\n"),
366382
Response: &BasicResponse{},
367383
},
368384
},

0 commit comments

Comments
 (0)