|
86 | 86 | FlowRequest, |
87 | 87 | GroupMessageStatuses, |
88 | 88 | IdentityChange, |
| 89 | + ImageCarouselCard, |
89 | 90 | Industry, |
90 | 91 | MediaURL, |
91 | 92 | Message, |
|
106 | 107 | URLButton, |
107 | 108 | User, |
108 | 109 | UserMarketingPreferences, |
| 110 | + VideoCarouselCard, |
109 | 111 | VoiceCallButton, |
110 | 112 | ) |
111 | 113 | from .types.base_update import BaseUpdate |
| 114 | +from .types.callback import BaseCarouselCard |
112 | 115 | from .types.calls import CallPermissions, SessionDescription |
113 | 116 | from .types.flows import ( |
114 | 117 | CreatedFlow, |
@@ -1819,6 +1822,63 @@ def send_products( |
1819 | 1822 | interactive_type=InteractiveType.PRODUCT_LIST, |
1820 | 1823 | ) |
1821 | 1824 |
|
| 1825 | + def send_carousel( |
| 1826 | + self, |
| 1827 | + to: str | int, |
| 1828 | + *, |
| 1829 | + body: str, |
| 1830 | + cards: list[ImageCarouselCard | VideoCarouselCard | BaseCarouselCard], |
| 1831 | + reply_to_message_id: str | None = None, |
| 1832 | + tracker: str | CallbackData | None = None, |
| 1833 | + identity_key_hash: str | None = None, |
| 1834 | + sender: str | int | None = None, |
| 1835 | + ) -> SentMessage: |
| 1836 | + """ |
| 1837 | + Interactive media carousel messages display a set of horizontally scrollable media cards. |
| 1838 | +
|
| 1839 | + - See `Carousel messages <https://developers.facebook.com/documentation/business-messaging/whatsapp/messages/interactive-media-carousel-messages>`_. |
| 1840 | +
|
| 1841 | + Args: |
| 1842 | + to: The user phone number, WhatsApp ID, BSUID or group ID to send the message to. |
| 1843 | + body: Text to appear in the message body (up to 1024 characters). |
| 1844 | + cards: The carousel cards to send (up to 10). |
| 1845 | + reply_to_message_id: The message ID to quote (optional). |
| 1846 | + tracker: The data to track the message with (optional, up to 512 characters, for complex data you can use :class:`~pywa.types.callback.CallbackData`). |
| 1847 | + identity_key_hash: The message would only be delivered if the hash value matches the customer's current hash (Optional, See `Identity Change Check <https://developers.facebook.com/docs/whatsapp/cloud-api/reference/phone-numbers#identity-change-check>`_). |
| 1848 | + sender: The phone ID to send the message from (optional, overrides the client's phone ID). |
| 1849 | +
|
| 1850 | + Returns: |
| 1851 | + The sent carousel message. |
| 1852 | + """ |
| 1853 | + sender = helpers.resolve_arg( |
| 1854 | + wa=self, value=sender, method_arg="sender", client_arg="phone_id" |
| 1855 | + ) |
| 1856 | + |
| 1857 | + recipient, recipient_type = helpers.resolve_recipient(to) |
| 1858 | + return SentMessage.from_sent_update( |
| 1859 | + client=self, |
| 1860 | + update=self.api.send_message( |
| 1861 | + sender=sender, |
| 1862 | + **recipient, |
| 1863 | + typ="interactive", |
| 1864 | + msg=helpers.get_interactive_msg( |
| 1865 | + typ=InteractiveType.CAROUSEL, |
| 1866 | + action={ |
| 1867 | + "cards": [ |
| 1868 | + card.to_dict(idx=idx) for idx, card in enumerate(cards) |
| 1869 | + ] |
| 1870 | + }, |
| 1871 | + body=body, |
| 1872 | + ), |
| 1873 | + reply_to_message_id=reply_to_message_id, |
| 1874 | + biz_opaque_callback_data=helpers.resolve_tracker_param(tracker), |
| 1875 | + recipient_identity_key_hash=identity_key_hash, |
| 1876 | + ), |
| 1877 | + from_phone_id=sender, |
| 1878 | + recipient_type=recipient_type, |
| 1879 | + interactive_type=InteractiveType.PRODUCT_LIST, |
| 1880 | + ) |
| 1881 | + |
1822 | 1882 | def mark_message_as_read( |
1823 | 1883 | self, |
1824 | 1884 | message_id: str, |
|
0 commit comments