Skip to content
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

Add Single Product #193

Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
194497d
fix-send-document-caption-optional: document caption is not required,…
limsenkeat Jan 11, 2024
63c7b07
revert the change in DocumentMessage.php
limsenkeat Apr 8, 2024
0424115
Add react to message
derrickobedgiu1 Apr 23, 2024
db2eadc
Add Catalog Message
derrickobedgiu1 Apr 23, 2024
9074cf8
Add Location Request
derrickobedgiu1 Apr 23, 2024
d92f1e1
Add Single Product
derrickobedgiu1 Apr 23, 2024
05e2343
adding flow message support
pravnyadv Jun 27, 2024
2b65f33
Merge pull request #192 from derrickobedgiu1/location-request
aalbarca Jul 2, 2024
25622bf
patch tests
derrickobedgiu1 Jul 3, 2024
a7ead6c
patch test
derrickobedgiu1 Jul 3, 2024
b4aaffb
Update README.md
aindot Jul 4, 2024
3f968a7
Merge pull request #190 from derrickobedgiu1/react-to-message
aalbarca Jul 10, 2024
79632d0
Merge pull request #191 from derrickobedgiu1/catalog-message
aalbarca Jul 10, 2024
9550310
Merge pull request #162 from limsenkeat/fix-send-document-caption-opt…
aalbarca Jul 14, 2024
955728a
Merge pull request #198 from aindot/patch-1
aalbarca Jul 14, 2024
349f05f
patch integration test
derrickobedgiu1 Jul 15, 2024
70a43ac
Updated WhatsAppCloudApiTestConfiguration.php.dist and Integration test
derrickobedgiu1 Jul 19, 2024
858fcfb
fix styling issue
pravnyadv Jul 30, 2024
cdfe9b0
running csfix
pravnyadv Jul 30, 2024
8e98f7a
Merge pull request #197 from pravnyadv/main
aalbarca Aug 6, 2024
3866cb3
Add Single Product
derrickobedgiu1 Apr 23, 2024
09e478b
Updated WhatsAppCloudApiTestConfiguration.php.dist and Integration test
derrickobedgiu1 Jul 19, 2024
b9e671f
Merge remote-tracking branch 'origin/single-product-message' into sin…
derrickobedgiu1 Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ $whatsapp_cloud_api->sendDocument('34676104574', $link_id, $document_name, $docu
```php
<?php

$whatsapp_cloud_api->sendTemplate('34676104574', 'hello_world', 'en_US'); // Language is optional
$whatsapp_cloud_api->sendTemplate('34676104574', 'hello_world', 'en_US'); // If not specified, Language will be default to en_US and otherwise it will be required.
```

You also can build templates with parameters:
@@ -179,6 +179,15 @@ $whatsapp_cloud_api->sendSticker('<destination-phone-number>', $media_id);
$whatsapp_cloud_api->sendLocation('<destination-phone-number>', $longitude, $latitude, $name, $address);
```

### Send a location request message

```php
<?php

$body = 'Let\'s start with your pickup. You can either manually *enter an address* or *share your current location*.';
$whatsapp_cloud_api->sendLocationRequest('<destination-phone-number>', $body);
```

### Send a contact message

```php
@@ -241,6 +250,23 @@ $whatsapp_cloud_api->sendCtaUrl(
);
```

### Send Catalog Message

```php
<?php

$body = 'Hello! Thanks for your interest. Ordering is easy. Just visit our catalog and add items you\'d like to purchase.';
$footer = 'Best grocery deals on WhatsApp!';
$sku_thumbnail = '<product-sku-id>'; // product sku id to use as header thumbnail

$whatsapp_cloud_api->sendCatalog(
'<destination-phone-number>',
$body,
$footer, // optional
$sku_thumbnail // optional
);
```

### Send a button reply message

```php
@@ -271,6 +297,24 @@ $whatsapp_cloud_api->sendButton(
);
```

### Send Single Product Message
```php
<?php

$catalog_id = '<catalog-id>';
$sku_id = '<product-sku-id>';
$body = 'Hello! Here\'s your requested product. Thanks for shopping with us.';
$footer = 'Subject to T&C';

$whatsapp_cloud_api->sendSingleProduct(
'<destination-phone-number>',
$catalog_id,
$sku_id,
$body, // body: optional
$footer // footer: optional
);
```

### Replying messages

You can reply a previous sent message:
@@ -286,6 +330,27 @@ $whatsapp_cloud_api
);
```

### React to a Message

You can react to a message from your conversations if you know the messageid

```php
<?php

$whatsapp_cloud_api->sendReaction(
'<destination-phone-number>',
'<message-id-to-react-to>',
'👍', // the emoji
);

// Unreact to a message
$whatsapp_cloud_api->sendReaction(
'<destination-phone-number>',
'<message-id-to-unreact-to>'
);

```

## Media messages
### Upload media resources
Media messages accept as identifiers an Internet URL pointing to a public resource (image, video, audio, etc.). When you try to send a media message from a URL you must instantiate the `LinkID` object.
@@ -407,12 +472,15 @@ Fields list: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/b
- Send Videos
- Send Stickers
- Send Locations
- Send Location Request
- Send Contacts
- Send Lists
- Send Buttons
- Send Single Product
- Upload media resources to WhatsApp servers
- Download media resources from WhatsApp servers
- Mark messages as read
- React to a Message
- Get/Update Business Profile
- Webhook verification
- Webhook notifications
44 changes: 44 additions & 0 deletions src/Message/CatalogMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Netflie\WhatsAppCloudApi\Message;

final class CatalogMessage extends Message
{
/**
* {@inheritdoc}
*/
protected string $type = 'catalog_message';

private string $body;

private ?string $footer;

private ?string $thumbnail_product_retailer_id;

/**
* {@inheritdoc}
*/
public function __construct(string $to, string $body, ?string $footer, ?string $thumbnail_product_retailer_id, ?string $reply_to)
{
$this->body = $body;
$this->footer = $footer;
$this->thumbnail_product_retailer_id = $thumbnail_product_retailer_id;

parent::__construct($to, $reply_to);
}

public function body(): string
{
return $this->body;
}

public function footer(): ?string
{
return $this->footer;
}

public function thumbnail_product_retailer_id(): ?string
{
return $this->thumbnail_product_retailer_id;
}
}
2 changes: 0 additions & 2 deletions src/Message/CtaUrl/TitleHeader.php
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@

namespace Netflie\WhatsAppCloudApi\Message\CtaUrl;

use Netflie\WhatsAppCloudApi\Message\CtaUrl\Header;

final class TitleHeader extends Header
{
protected string $title;
28 changes: 28 additions & 0 deletions src/Message/LocationRequestMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Netflie\WhatsAppCloudApi\Message;

final class LocationRequestMessage extends Message
{
/**
* {@inheritdoc}
*/
protected string $type = 'location_request_message';

private string $body;

/**
* {@inheritdoc}
*/
public function __construct(string $to, string $body, ?string $reply_to)
{
$this->body = $body;

parent::__construct($to, $reply_to);
}

public function body(): string
{
return $this->body;
}
}
36 changes: 36 additions & 0 deletions src/Message/ReactionMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Netflie\WhatsAppCloudApi\Message;

final class ReactionMessage extends Message
{
/**
* {@inheritdoc}
*/
protected string $type = 'reaction';

private $emoji;

private $message_id;

/**
* {@inheritdoc}
*/
public function __construct(string $to, string $message_id, string $emoji)
{
$this->emoji = $emoji;
$this->message_id = $message_id;

parent::__construct($to, null);
}

public function emoji(): string
{
return $this->emoji;
}

public function message_id(): string
{
return $this->message_id;
}
}
52 changes: 52 additions & 0 deletions src/Message/SingleProductMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Netflie\WhatsAppCloudApi\Message;

final class SingleProductMessage extends Message
{
/**
* {@inheritdoc}
*/
protected string $type = 'product';

private int $catalog_id;

private string $product_retailer_id;

private ?string $body;

private ?string $footer;

/**
* {@inheritdoc}
*/
public function __construct(string $to, int $catalog_id, string $product_retailer_id, ?string $body, ?string $footer, ?string $reply_to)
{
$this->catalog_id = $catalog_id;
$this->product_retailer_id = $product_retailer_id;
$this->body = $body;
$this->footer = $footer;

parent::__construct($to, $reply_to);
}

public function catalog_id(): int
{
return $this->catalog_id;
}

public function product_retailer_id(): string
{
return $this->product_retailer_id;
}

public function body(): ?string
{
return $this->body;
}

public function footer(): ?string
{
return $this->footer;
}
}
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public function body(): array
{
return array_merge(
[
'messaging_product' => 'whatsapp'
'messaging_product' => 'whatsapp',
],
$this->information
);
42 changes: 42 additions & 0 deletions src/Request/MessageRequest/RequestCatalogMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Netflie\WhatsAppCloudApi\Request\MessageRequest;

use Netflie\WhatsAppCloudApi\Request\MessageRequest;

final class RequestCatalogMessage extends MessageRequest
{
/**
* {@inheritdoc}
*/
public function body(): array
{
$body = [
'messaging_product' => $this->message->messagingProduct(),
'recipient_type' => $this->message->recipientType(),
'to' => $this->message->to(),
'type' => 'interactive',
'interactive' => [
'type' => $this->message->type(),
'body' => ['text' => $this->message->body()],
'action' => [
'name' => 'catalog_message',
],
],
];

if ($this->message->thumbnail_product_retailer_id()) {
$body['interactive']['action']['parameters'] = ['thumbnail_product_retailer_id' => $this->message->thumbnail_product_retailer_id()];
}

if ($this->message->footer()) {
$body['interactive']['footer'] = ['text' => $this->message->footer()];
}

if ($this->message->replyTo()) {
$body['context']['message_id'] = $this->message->replyTo();
}

return $body;
}
}
34 changes: 34 additions & 0 deletions src/Request/MessageRequest/RequestLocationRequestMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Netflie\WhatsAppCloudApi\Request\MessageRequest;

use Netflie\WhatsAppCloudApi\Request\MessageRequest;

final class RequestLocationRequestMessage extends MessageRequest
{
/**
* {@inheritdoc}
*/
public function body(): array
{
$body = [
'messaging_product' => $this->message->messagingProduct(),
'recipient_type' => $this->message->recipientType(),
'to' => $this->message->to(),
'type' => 'interactive',
'interactive' => [
'type' => $this->message->type(),
'body' => ['text' => $this->message->body()],
'action' => [
'name' => 'send_location',
],
],
];

if ($this->message->replyTo()) {
$body['context']['message_id'] = $this->message->replyTo();
}

return $body;
}
}
Loading