@@ -289,6 +289,10 @@ func buildMockD3MediaService(testChannels []courier.Channel, testCases []Channel
289
289
fileURL = "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=id_audio"
290
290
}
291
291
292
+ if strings .HasSuffix (r .URL .Path , "id_sticker" ) {
293
+ fileURL = "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=id_sticker"
294
+ }
295
+
292
296
w .WriteHeader (http .StatusOK )
293
297
w .Write ([]byte (fmt .Sprintf (`{ "url": "%s" }` , fileURL )))
294
298
}))
@@ -364,12 +368,12 @@ var SendTestCasesD3C = []ChannelSendTestCase{
364
368
Label : "Audio Send" ,
365
369
MsgText : "audio caption" ,
366
370
MsgURN : "whatsapp:250788123123" ,
367
- MsgAttachments : []string {"audio/mpeg:https ://foo.bar/audio .mp3" },
371
+ MsgAttachments : []string {"audio/mpeg:http ://mock.com/3456/test .mp3" },
368
372
MockResponses : map [MockedRequest ]* httpx.MockResponse {
369
373
{
370
374
Method : "POST" ,
371
375
Path : "/messages" ,
372
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` ,
376
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/3456/test .mp3"}}` ,
373
377
}: httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
374
378
{
375
379
Method : "POST" ,
@@ -385,10 +389,10 @@ var SendTestCasesD3C = []ChannelSendTestCase{
385
389
Label : "Document Send" ,
386
390
MsgText : "document caption" ,
387
391
MsgURN : "whatsapp:250788123123" ,
388
- MsgAttachments : []string {"application/pdf:https ://foo.bar/document .pdf" },
392
+ MsgAttachments : []string {"application/pdf:http ://mock.com/7890/test .pdf" },
389
393
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
390
394
MockResponseStatus : 201 ,
391
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"https ://foo.bar/document .pdf","caption":"document caption","filename":"document .pdf"}}` ,
395
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"document","document":{"link":"http ://mock.com/7890/test .pdf","caption":"document caption","filename":"test .pdf"}}` ,
392
396
ExpectedRequestPath : "/messages" ,
393
397
ExpectedMsgStatus : "W" ,
394
398
ExpectedExternalID : "157b5e14568e8" ,
@@ -398,10 +402,10 @@ var SendTestCasesD3C = []ChannelSendTestCase{
398
402
Label : "Image Send" ,
399
403
MsgText : "image caption" ,
400
404
MsgURN : "whatsapp:250788123123" ,
401
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
405
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
402
406
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
403
407
MockResponseStatus : 201 ,
404
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg","caption":"image caption"}}` ,
408
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg","caption":"image caption"}}` ,
405
409
ExpectedRequestPath : "/messages" ,
406
410
ExpectedMsgStatus : "W" ,
407
411
ExpectedExternalID : "157b5e14568e8" ,
@@ -411,10 +415,10 @@ var SendTestCasesD3C = []ChannelSendTestCase{
411
415
Label : "Sticker Send" ,
412
416
MsgText : "sticker caption" ,
413
417
MsgURN : "whatsapp:250788123123" ,
414
- MsgAttachments : []string {"image/webp:https ://foo.bar/sticker .webp" },
418
+ MsgAttachments : []string {"image/webp:http ://mock.com/8901/test .webp" },
415
419
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
416
420
MockResponseStatus : 201 ,
417
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"sticker","sticker":{"link":"https ://foo.bar/sticker .webp","caption":"sticker caption"}}` ,
421
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"sticker","sticker":{"link":"http ://mock.com/8901/test .webp","caption":"sticker caption"}}` ,
418
422
ExpectedRequestPath : "/messages" ,
419
423
ExpectedMsgStatus : "W" ,
420
424
ExpectedExternalID : "157b5e14568e8" ,
@@ -424,10 +428,10 @@ var SendTestCasesD3C = []ChannelSendTestCase{
424
428
Label : "Video Send" ,
425
429
MsgText : "video caption" ,
426
430
MsgURN : "whatsapp:250788123123" ,
427
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
431
+ MsgAttachments : []string {"video/mp4:http ://mock.com/5678/test .mp4" },
428
432
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
429
433
MockResponseStatus : 201 ,
430
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"https ://foo.bar/video .mp4","caption":"video caption"}}` ,
434
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"video","video":{"link":"http ://mock.com/5678/test .mp4","caption":"video caption"}}` ,
431
435
ExpectedRequestPath : "/messages" ,
432
436
ExpectedMsgStatus : "W" ,
433
437
ExpectedExternalID : "157b5e14568e8" ,
@@ -514,10 +518,10 @@ var SendTestCasesD3C = []ChannelSendTestCase{
514
518
MsgText : "Interactive Button Msg" ,
515
519
MsgURN : "whatsapp:250788123123" ,
516
520
MsgQuickReplies : []string {"BUTTON1" },
517
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
521
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
518
522
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
519
523
MockResponseStatus : 201 ,
520
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"image","image":{"link":"https ://foo.bar/image .jpg"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
524
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"image","image":{"link":"http ://mock.com/1234/test .jpg"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
521
525
ExpectedRequestPath : "/messages" ,
522
526
ExpectedMsgStatus : "W" ,
523
527
ExpectedExternalID : "157b5e14568e8" ,
@@ -528,10 +532,10 @@ var SendTestCasesD3C = []ChannelSendTestCase{
528
532
MsgText : "Interactive Button Msg" ,
529
533
MsgURN : "whatsapp:250788123123" ,
530
534
MsgQuickReplies : []string {"BUTTON1" },
531
- MsgAttachments : []string {"video/mp4:https ://foo.bar/video .mp4" },
535
+ MsgAttachments : []string {"video/mp4:http ://mock.com/5678/test .mp4" },
532
536
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
533
537
MockResponseStatus : 201 ,
534
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"video","video":{"link":"https ://foo.bar/video .mp4"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
538
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"video","video":{"link":"http ://mock.com/5678/test .mp4"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
535
539
ExpectedRequestPath : "/messages" ,
536
540
ExpectedMsgStatus : "W" ,
537
541
ExpectedExternalID : "157b5e14568e8" ,
@@ -542,10 +546,10 @@ var SendTestCasesD3C = []ChannelSendTestCase{
542
546
MsgText : "Interactive Button Msg" ,
543
547
MsgURN : "whatsapp:250788123123" ,
544
548
MsgQuickReplies : []string {"BUTTON1" },
545
- MsgAttachments : []string {"document/pdf:https ://foo.bar/document .pdf" },
549
+ MsgAttachments : []string {"document/pdf:http ://mock.com/7890/test .pdf" },
546
550
MockResponseBody : `{ "messages": [{"id": "157b5e14568e8"}] }` ,
547
551
MockResponseStatus : 201 ,
548
- ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"document","document":{"link":"https ://foo.bar/document .pdf","filename":"document .pdf"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
552
+ ExpectedRequestBody : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"interactive","interactive":{"type":"button","header":{"type":"document","document":{"link":"http ://mock.com/7890/test .pdf","filename":"test .pdf"}},"body":{"text":"Interactive Button Msg"},"action":{"buttons":[{"type":"reply","reply":{"id":"0","title":"BUTTON1"}}]}}}` ,
549
553
ExpectedRequestPath : "/messages" ,
550
554
ExpectedMsgStatus : "W" ,
551
555
ExpectedExternalID : "157b5e14568e8" ,
@@ -556,12 +560,12 @@ var SendTestCasesD3C = []ChannelSendTestCase{
556
560
MsgText : "Interactive Button Msg" ,
557
561
MsgURN : "whatsapp:250788123123" ,
558
562
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" },
559
- MsgAttachments : []string {"audio/mp3:https ://foo.bar/audio .mp3" },
563
+ MsgAttachments : []string {"audio/mp3:http ://mock.com/3456/test .mp3" },
560
564
MockResponses : map [MockedRequest ]* httpx.MockResponse {
561
565
{
562
566
Method : "POST" ,
563
567
Path : "/messages" ,
564
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"https ://foo.bar/audio .mp3"}}` ,
568
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"audio","audio":{"link":"http ://mock.com/3456/test .mp3"}}` ,
565
569
}: httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
566
570
{
567
571
Method : "POST" ,
@@ -578,12 +582,12 @@ var SendTestCasesD3C = []ChannelSendTestCase{
578
582
MsgText : "Interactive List Msg" ,
579
583
MsgURN : "whatsapp:250788123123" ,
580
584
MsgQuickReplies : []string {"ROW1" , "ROW2" , "ROW3" , "ROW4" },
581
- MsgAttachments : []string {"image/jpeg:https ://foo.bar/image .jpg" },
585
+ MsgAttachments : []string {"image/jpeg:http ://mock.com/1234/test .jpg" },
582
586
MockResponses : map [MockedRequest ]* httpx.MockResponse {
583
587
{
584
588
Method : "POST" ,
585
589
Path : "/messages" ,
586
- Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"https ://foo.bar/image .jpg"}}` ,
590
+ Body : `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"image","image":{"link":"http ://mock.com/1234/test .jpg"}}` ,
587
591
}: httpx .NewMockResponse (201 , nil , []byte (`{ "messages": [{"id": "157b5e14568e8"}] }` )),
588
592
{
589
593
Method : "POST" ,
@@ -629,6 +633,30 @@ var SendTestCasesD3C = []ChannelSendTestCase{
629
633
},
630
634
}
631
635
636
+ // setupMedia takes care of having the media files needed to our test server host
637
+ func setupMedia (mb * test.MockBackend ) {
638
+ imageJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/1234/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
639
+
640
+ audioM4A := test .NewMockMedia ("test.m4a" , "audio/mp4" , "http://mock.com/2345/test.m4a" , 1024 * 1024 , 0 , 0 , 200 , nil )
641
+ audioMP3 := test .NewMockMedia ("test.mp3" , "audio/mpeg" , "http://mock.com/3456/test.mp3" , 1024 * 1024 , 0 , 0 , 200 , []courier.Media {audioM4A })
642
+
643
+ thumbJPG := test .NewMockMedia ("test.jpg" , "image/jpeg" , "http://mock.com/4567/test.jpg" , 1024 * 1024 , 640 , 480 , 0 , nil )
644
+ videoMP4 := test .NewMockMedia ("test.mp4" , "video/mp4" , "http://mock.com/5678/test.mp4" , 1024 * 1024 , 0 , 0 , 1000 , []courier.Media {thumbJPG })
645
+
646
+ videoMOV := test .NewMockMedia ("test.mov" , "video/quicktime" , "http://mock.com/6789/test.mov" , 100 * 1024 * 1024 , 0 , 0 , 2000 , nil )
647
+
648
+ filePDF := test .NewMockMedia ("test.pdf" , "application/pdf" , "http://mock.com/7890/test.pdf" , 100 * 1024 * 1024 , 0 , 0 , 0 , nil )
649
+
650
+ stickerWEBP := test .NewMockMedia ("test.webp" , "image/webp" , "http://mock.com/8901/test.webp" , 50 * 1024 , 480 , 480 , 0 , nil )
651
+
652
+ mb .MockMedia (imageJPG )
653
+ mb .MockMedia (audioMP3 )
654
+ mb .MockMedia (videoMP4 )
655
+ mb .MockMedia (videoMOV )
656
+ mb .MockMedia (filePDF )
657
+ mb .MockMedia (stickerWEBP )
658
+ }
659
+
632
660
func TestSending (t * testing.T ) {
633
661
// shorter max msg length for testing
634
662
maxMsgLength = 100
@@ -639,7 +667,7 @@ func TestSending(t *testing.T) {
639
667
})
640
668
checkRedacted := []string {"the-auth-token" }
641
669
642
- RunChannelSendTestCases (t , ChannelWAC , newWAHandler (courier .ChannelType ("D3C" ), "360Dialog" ), SendTestCasesD3C , checkRedacted , nil )
670
+ RunChannelSendTestCases (t , ChannelWAC , newWAHandler (courier .ChannelType ("D3C" ), "360Dialog" ), SendTestCasesD3C , checkRedacted , setupMedia )
643
671
}
644
672
func TestGetSupportedLanguage (t * testing.T ) {
645
673
assert .Equal (t , languageInfo {"en" , "Menu" }, getSupportedLanguage (courier .NilLocale ))
0 commit comments