WhatsAppInteractiveMessageTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace CMText\RichContent\Messages\WhatsApp;
  3. use CMText\Channels;
  4. use CMText\Message;
  5. use CMText\RichContent\Messages\MediaContent;
  6. use CMText\TextClientRequest;
  7. use PHPUnit\Framework\TestCase;
  8. class WhatsAppInteractiveMessageTest extends TestCase
  9. {
  10. public function testWhatsAppInteractiveSectionMessage()
  11. {
  12. // test building a WhatsApp Interactive Message with Sections
  13. $message = new WhatsAppInteractiveMessage(
  14. new WhatsAppInteractiveContent(
  15. WhatsAppInteractiveContentTypes::LIST,
  16. new WhatsAppInteractiveHeader(
  17. WhatsAppInteractiveHeaderTypes::TEXT,
  18. 'List message example'
  19. ),
  20. new WhatsAppInteractiveBody('checkout our list message demo'),
  21. new WhatsAppInteractiveListAction(
  22. 'Descriptive list title',
  23. [new WhatsAppInteractiveSection(
  24. 'Select an option',
  25. [new WhatsAppInteractiveSectionRow(
  26. 'unique title 1',
  27. rand(),
  28. 'description text'
  29. ),new WhatsAppInteractiveSectionRow(
  30. 'unique title 2',
  31. rand()
  32. )]
  33. )]
  34. ),
  35. new WhatsAppInteractiveFooter('footer text')
  36. )
  37. );
  38. $this->assertInstanceOf(
  39. WhatsAppInteractiveMessage::class,
  40. $message
  41. );
  42. // test that it still compatible with a \CMText\Message
  43. $CMTextMessage = new Message();
  44. $CMTextMessage
  45. ->WithChannels([Channels::WHATSAPP])
  46. ->WithRichMessage($message);
  47. // echo json_encode($CMTextMessage);
  48. $this->assertInstanceOf(
  49. Message::class,
  50. $CMTextMessage
  51. );
  52. }
  53. /**
  54. * @throws \CMText\Exceptions\RecipientLimitException
  55. * @throws \CMText\Exceptions\ConversationLimitException
  56. */
  57. public function testWhatsAppInteractiveButtonsMessage()
  58. {
  59. // test building a WhatsApp Interactive Message with Buttons
  60. $message = new WhatsAppInteractiveMessage(
  61. new WhatsAppInteractiveContent(
  62. WhatsAppInteractiveContentTypes::BUTTON,
  63. new WhatsAppInteractiveHeader(
  64. WhatsAppInteractiveHeaderTypes::IMAGE,
  65. null,
  66. new MediaContent(
  67. 'media name',
  68. 'media.url',
  69. 'mime/type'
  70. )
  71. ),
  72. new WhatsAppInteractiveBody('checkout our list message demo'),
  73. new WhatsAppInteractiveButtonAction(
  74. [new WhatsAppInteractiveReplyButton(
  75. 'button 1 reply-text',
  76. rand()
  77. ),new WhatsAppInteractiveReplyButton(
  78. 'button 2 title',
  79. rand()
  80. )]
  81. ),
  82. new WhatsAppInteractiveFooter('footer text')
  83. )
  84. );
  85. $this->assertInstanceOf(
  86. WhatsAppInteractiveMessage::class,
  87. $message
  88. );
  89. }
  90. }