Add get_templates method to retrieve WhatsApp templates
This PR adds a new method get_templates that allows users to retrieve all templates for their WhatsApp Business Account. The implementation:
- Adds the method to WhatsAppCloudApi in api.py
- Adds a corresponding method to WhatsApp in client.py
- Adds async versions of both methods
- Includes tests for the new functionality
This method requires a system user access token rather than the regular phone ID token, so I've implemented it to temporarily update the headers for the request and then restore them.
Note: I encountered an issue with pre-commit getting stuck on "fix end of files" and had to bypass it for this PR.
Hey @YonchRibak , thanks for your PR! We really appreciate the contribution.
A couple of things:
In wa.get_templates(), you're returning a list of dict. Could you check if it's possible to return a list of typs.template.Template instead? You can add .from_dict() to typs.template.Template
We're experimenting with a new approach for handling responses in the results branch (e.g., get_flows() uses a Result class). You can see it here
The same applies to block_users (commits here)โif possible, aligning with this structure would be great.
We're quite busy, so updates have been slow, but we hope to merge this soon. Thanks again! ๐
I've made a new commit to pr addressing your request for typing. i've added a new type of RetrievedTemplate because what returns from META is slightly different from Template tyoe that is more suited for sending or creating a template.
On Wed, Apr 2, 2025 at 10:36โฏPM Yehuda lev @.***> wrote:
Hey @YonchRibak https://github.com/YonchRibak , thanks for your PR! We really appreciate the contribution.
A couple of things:
In wa.get_templates(), you're returning a list of dict. Could you check if it's possible to return a list of typs.template.Template instead? You can add .from_dict() to typs.template.Template https://github.com/david-lev/pywa/blob/a662c1632ab7b5e32ab59ce59bd40ae71579031a/pywa/types/template.py#L214
We're experimenting with a new approach for handling responses in the results branch (e.g., get_flows() uses a Result class). You can see it here https://github.com/david-lev/pywa/compare/master...results
The same applies to block_users (commits here https://github.com/david-lev/pywa/commits/block-users/)โif possible, aligning with this structure would be great.
We're quite busy, so updates have been slow, but we hope to merge this soon. Thanks again! ๐
โ Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/111#issuecomment-2773531894, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVJLQXKVMTB7EP257T32XQ32TAVCNFSM6AAAAAB2JNVJTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZTGUZTCOBZGQ . You are receiving this because you were mentioned.Message ID: @.***> [image: yehuda-lev]yehuda-lev left a comment (david-lev/pywa#111) https://github.com/david-lev/pywa/pull/111#issuecomment-2773531894
Hey @YonchRibak https://github.com/YonchRibak , thanks for your PR! We really appreciate the contribution.
A couple of things:
In wa.get_templates(), you're returning a list of dict. Could you check if it's possible to return a list of typs.template.Template instead? You can add .from_dict() to typs.template.Template https://github.com/david-lev/pywa/blob/a662c1632ab7b5e32ab59ce59bd40ae71579031a/pywa/types/template.py#L214
We're experimenting with a new approach for handling responses in the results branch (e.g., get_flows() uses a Result class). You can see it here https://github.com/david-lev/pywa/compare/master...results
The same applies to block_users (commits here https://github.com/david-lev/pywa/commits/block-users/)โif possible, aligning with this structure would be great.
We're quite busy, so updates have been slow, but we hope to merge this soon. Thanks again! ๐
โ Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/111#issuecomment-2773531894, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVJLQXKVMTB7EP257T32XQ32TAVCNFSM6AAAAAB2JNVJTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZTGUZTCOBZGQ . You are receiving this because you were mentioned.Message ID: @.***>
i eventually created a new pr and a new branch because i lost a battle to git https://github.com/david-lev/pywa/pull/113
โชOn Fri, Apr 4, 2025 at 12:45โฏPM โซืืื ืชื ืจืืืงโฌโ @.***> wrote:โฌ
I've made a new commit to pr addressing your request for typing. i've added a new type of RetrievedTemplate because what returns from META is slightly different from Template tyoe that is more suited for sending or creating a template.
On Wed, Apr 2, 2025 at 10:36โฏPM Yehuda lev @.***> wrote:
Hey @YonchRibak https://github.com/YonchRibak , thanks for your PR! We really appreciate the contribution.
A couple of things:
In wa.get_templates(), you're returning a list of dict. Could you check if it's possible to return a list of typs.template.Template instead? You can add .from_dict() to typs.template.Template https://github.com/david-lev/pywa/blob/a662c1632ab7b5e32ab59ce59bd40ae71579031a/pywa/types/template.py#L214
We're experimenting with a new approach for handling responses in the results branch (e.g., get_flows() uses a Result class). You can see it here https://github.com/david-lev/pywa/compare/master...results
The same applies to block_users (commits here https://github.com/david-lev/pywa/commits/block-users/)โif possible, aligning with this structure would be great.
We're quite busy, so updates have been slow, but we hope to merge this soon. Thanks again! ๐
โ Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/111#issuecomment-2773531894, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVJLQXKVMTB7EP257T32XQ32TAVCNFSM6AAAAAB2JNVJTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZTGUZTCOBZGQ . You are receiving this because you were mentioned.Message ID: @.***> [image: yehuda-lev]yehuda-lev left a comment (david-lev/pywa#111) https://github.com/david-lev/pywa/pull/111#issuecomment-2773531894
Hey @YonchRibak https://github.com/YonchRibak , thanks for your PR! We really appreciate the contribution.
A couple of things:
In wa.get_templates(), you're returning a list of dict. Could you check if it's possible to return a list of typs.template.Template instead? You can add .from_dict() to typs.template.Template https://github.com/david-lev/pywa/blob/a662c1632ab7b5e32ab59ce59bd40ae71579031a/pywa/types/template.py#L214
We're experimenting with a new approach for handling responses in the results branch (e.g., get_flows() uses a Result class). You can see it here https://github.com/david-lev/pywa/compare/master...results
The same applies to block_users (commits here https://github.com/david-lev/pywa/commits/block-users/)โif possible, aligning with this structure would be great.
We're quite busy, so updates have been slow, but we hope to merge this soon. Thanks again! ๐
โ Reply to this email directly, view it on GitHub https://github.com/david-lev/pywa/pull/111#issuecomment-2773531894, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2HCAVJLQXKVMTB7EP257T32XQ32TAVCNFSM6AAAAAB2JNVJTGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZTGUZTCOBZGQ . You are receiving this because you were mentioned.Message ID: @.***>
https://pywa.readthedocs.io/en/v3/content/client/client_reference.html#pywa.client.WhatsApp.get_templates
#113