-
-
Notifications
You must be signed in to change notification settings - Fork 222
Add feature: add support for creating and updating WhatsApp message templates #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add feature: add support for creating and updating WhatsApp message templates #227
Conversation
krishna035
commented
May 19, 2025
- Introduced CreateTemplateRequest and UpdateTemplateRequest classes
- Added createTemplate() and updateTemplate() methods in Client
- Exposed createTemplate and updateTemplateById in WhatsAppCloudApi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for creating and updating WhatsApp message templates via the Cloud API.
- Introduced
CreateTemplateRequestandUpdateTemplateRequestclasses - Added
createTemplate()andupdateTemplateById()toWhatsAppCloudApi - Extended
ClientwithcreateTemplate()/updateTemplate()and updated README with usage examples
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/WhatsAppCloudApi.php | New wrapper methods createTemplate & updateTemplateById |
| src/Request/TemplateRequest/CreateTemplateRequest.php | Request class for creating message templates |
| src/Request/TemplateRequest/UpdateTemplateRequest.php | Request class for updating message templates |
| src/Client.php | Added createTemplate() & updateTemplate() handlers |
| README.md | Added code examples and updated feature list |
Comments suppressed due to low confidence (2)
src/WhatsAppCloudApi.php:627
- Consider adding unit or integration tests for
createTemplate(andupdateTemplateById) to exercise both success paths and error-subcode handling.
public function createTemplate(string $name, string $category, string $language, array $components): Response
src/WhatsAppCloudApi.php:670
- Import
UpdateTemplateRequestat the top and instantiate it directly (e.g.,new UpdateTemplateRequest(...)) to mirror theCreateTemplateRequestusage and improve consistency.
new Request\TemplateRequest\UpdateTemplateRequest(
src/WhatsAppCloudApi.php
Outdated
|
|
||
| if ( | ||
| isset($decoded['error']['error_subcode']) && | ||
| (int)$decoded['error']['error_subcode'] === 2388024 |
Copilot
AI
May 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unify how you check error_subcode between createTemplate and updateTemplateById. Either remove the explicit cast here or apply the same strict comparison pattern in both methods.
| (int)$decoded['error']['error_subcode'] === 2388024 | |
| $decoded['error']['error_subcode'] === 2388024 |
src/WhatsAppCloudApi.php
Outdated
| try { | ||
| return $this->client->createTemplate($request); | ||
| } catch (\Netflie\WhatsAppCloudApi\Response\ResponseException $e) { | ||
| $decoded = json_decode($e->getMessage(), true); |
Copilot
AI
May 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decoding the exception message may not reliably yield the raw API error body. Consider exposing or using a getter on ResponseException that returns the original response payload for parsing.
| $decoded = json_decode($e->getMessage(), true); | |
| $decoded = json_decode($e->getResponsePayload(), true); |
src/Client.php
Outdated
| * | ||
| * @throws \Netflie\WhatsAppCloudApi\Response\ResponseException | ||
| */ | ||
| public function createTemplate(CreateTemplateRequest $request): Response |
Copilot
AI
May 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in createTemplate and updateTemplate is almost identical. Extract the common request/response flow into a private helper to reduce duplication.
|
|
||
| $whatsapp->createTemplate( | ||
| 'seasonal_promotion', | ||
| 'MARKETING', // UTILITY | MARKETING | AUTHENTICATION |
Copilot
AI
May 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment lists common template categories but omits TRANSACTIONAL. Update this to reflect all supported categories for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the official documentation link and did not find a TRANSACTIONAL category listed.
Can you clarify where you found that category or if it might be a legacy or deprecated term?
- Extracted the common JSON request/response logic in Client class to a private sendJsonRequest helper method. - Replaced the usage of getMessage() with responseData() in ResponseException for better error body parsing. - Removed redundant error decoding logic in updateTemplateById and similar methods. - Updated docblocks throughout Client class for clarity and maintainability.