Skip to content

Conversation

@krishna035
Copy link

  • Introduced CreateTemplateRequest and UpdateTemplateRequest classes
  • Added createTemplate() and updateTemplate() methods in Client
  • Exposed createTemplate and updateTemplateById in WhatsAppCloudApi

@aalbarca aalbarca requested a review from Copilot May 29, 2025 10:48
Copy link

Copilot AI left a 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 CreateTemplateRequest and UpdateTemplateRequest classes
  • Added createTemplate() and updateTemplateById() to WhatsAppCloudApi
  • Extended Client with createTemplate()/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 (and updateTemplateById) 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 UpdateTemplateRequest at the top and instantiate it directly (e.g., new UpdateTemplateRequest(...)) to mirror the CreateTemplateRequest usage and improve consistency.
new Request\TemplateRequest\UpdateTemplateRequest(


if (
isset($decoded['error']['error_subcode']) &&
(int)$decoded['error']['error_subcode'] === 2388024
Copy link

Copilot AI May 29, 2025

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.

Suggested change
(int)$decoded['error']['error_subcode'] === 2388024
$decoded['error']['error_subcode'] === 2388024

Copilot uses AI. Check for mistakes.
try {
return $this->client->createTemplate($request);
} catch (\Netflie\WhatsAppCloudApi\Response\ResponseException $e) {
$decoded = json_decode($e->getMessage(), true);
Copy link

Copilot AI May 29, 2025

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.

Suggested change
$decoded = json_decode($e->getMessage(), true);
$decoded = json_decode($e->getResponsePayload(), true);

Copilot uses AI. Check for mistakes.
src/Client.php Outdated
*
* @throws \Netflie\WhatsAppCloudApi\Response\ResponseException
*/
public function createTemplate(CreateTemplateRequest $request): Response
Copy link

Copilot AI May 29, 2025

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.

Copilot uses AI. Check for mistakes.

$whatsapp->createTemplate(
'seasonal_promotion',
'MARKETING', // UTILITY | MARKETING | AUTHENTICATION
Copy link

Copilot AI May 29, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant