Feature get templates with new type
[api] Add get_templates method with RetrievedTemplate class
This PR adds a new method 'get_templates' to retrieve templates from the WhatsApp API using a system user token. The method supports filtering by various parameters such as category, name, language, etc.
Key changes:
- Add 'get_templates' method to 'WhatsAppCloudApi' in api.py
- Add corresponding method to 'WhatsApp' in client.py
- Create a new 'RetrievedTemplate' class to represent templates as received from the API
- Add async versions of all methods for compatibility
- Add tests for new functionality
The 'RetrievedTemplate' class is distinct from the 'Template' class because:
- Templates retrieved from the API have a different structure than templates used for sending
- Retrieved templates include additional metadata like ID, status, parameter_format, etc.
- This approach allows for clear separation between templates for sending vs templates received
The implementation works by temporarily modifying request headers to use the system_user_token when making the API call, then restoring the original headers afterward.
Thanks, we will check this out in the next few days.
Hi, are there any news?
On Sun, Apr 6, 2025 at 2:01 PM Yehuda lev @.***> wrote:
Thanks, we will check this out in the next few days.
— Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/113#issuecomment-2781364259, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVNYCEFZTPO3IZOUCO32YECQXAVCNFSM6AAAAAB2OLMMKKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBRGM3DIMRVHE . You are receiving this because you authored the thread.Message ID: @.***> [image: yehuda-lev]yehuda-lev left a comment (david-lev/pywa#113) https://github.com/david-lev/pywa/pull/113#issuecomment-2781364259
Thanks, we will check this out in the next few days.
— Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/113#issuecomment-2781364259, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVNYCEFZTPO3IZOUCO32YECQXAVCNFSM6AAAAAB2OLMMKKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBRGM3DIMRVHE . You are receiving this because you authored the thread.Message ID: @.***>
@YonchRibak Great work! Have you implemented the RetrieveTemplate class? I can see it in the template.py file
Hi David.
It's been a while since I last submitted a pr for get_templates. I had to take a break from things..
As far as i can tell from looking at the PR I've removed RetrievedTemplate class...
On Sun, Apr 27, 2025 at 3:12 PM David Lev @.***> wrote:
david-lev left a comment (david-lev/pywa#113) https://github.com/david-lev/pywa/pull/113#issuecomment-2833427553
@YonchRibak https://github.com/YonchRibak Have you implemented the RetrieveTemplate class? I can see it in the template.py file
— Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/113#issuecomment-2833427553, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVNUEY5X25N3W5ICNLT23TCRZAVCNFSM6AAAAAB2OLMMKKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMZTGQZDONJVGM . You are receiving this because you were mentioned.Message ID: @.***>
Hi, did you receive my last pr? are there issues?
Hi, did you receive my last pr? are there issues?
I'm going to change the design of the templates (you can see the progress here https://github.com/david-lev/pywa/tree/templates-v2) I'll try to merge part of your changes. Appreciate your efforts
Hey David.. is there now a way to retrieve existing templates from your meta account? I browsed through the docs and saw you can now create a template using the api and get a response with it's status, but i was wondering is there something like get_templates that returns a list of your existing templates (even only names..). that is what I was suggesting and was in my PR..
On Mon, May 26, 2025 at 9:38 AM David Lev @.***> wrote:
david-lev left a comment (david-lev/pywa#113) https://github.com/david-lev/pywa/pull/113#issuecomment-2908720098
Hi, did you receive my last pr? are there issues?
I'm going to change the design of the templates (you can see the progress here https://github.com/david-lev/pywa/tree/templates-v2) I'll try to merge part of your changes. Appreciate your efforts
— Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/113#issuecomment-2908720098, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVOL7BHYFEWB7EOMMW33AKZHDAVCNFSM6AAAAAB2OLMMKKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMBYG4ZDAMBZHA . You are receiving this because you were mentioned.Message ID: @.***>
Hey David.. is there now a way to retrieve existing templates from your meta account?
Hi, we're working on it! You can see the PR template V2 We want to release a version in the coming days.
Hi @YonchRibak,
Thank you so much for this PR and for the time and thought you put into it 🙏 I really appreciate your effort in adding support for retrieving templates, including the clear separation between RetrievedTemplate and the sending-side Template, as well as the async support and tests.
Since the time this PR was opened, I ended up implementing get_templates myself in a slightly different way that better aligned with some internal changes in the library and overall design direction (e.g., unifying API access patterns and response models).
That said, your PR and design choices definitely helped shape my thinking on the feature — especially the idea of treating retrieved templates as a distinct class. I may revisit that idea again later for added clarity.
Thanks again for contributing to Pywa! Even if this specific PR won’t be merged, I’d love to see more contributions from you in the future. Let me know if you’d like help identifying other good issues to tackle.
Here is the docs for get_templates: https://pywa.readthedocs.io/en/v3/content/client/client_reference.html#pywa.client.WhatsApp.get_templates