Skip to content

Commit 3ad45c2

Browse files
authored
Merge pull request #141 from ker0x/feature/ice-breakers-reaction
[n/a] add IceBreakers and Reaction
2 parents fb865f8 + 2a0bbda commit 3ad45c2

27 files changed

+456
-34
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
The Messenger library follows [SemVer](http://semver.org/).
44

55
## 3.x
6-
**Changelog** (since [`3.3.0`](https://github.com/ker0x/messenger/compare/3.2.0...3.3.0))
6+
7+
**Changelog** (since [`3.2.0`](https://github.com/ker0x/messenger/compare/3.2.0...3.3.0))
8+
79
- 3.3.0 (2019-11)
8-
- Support of `image_aspect_ratio` for Generic Template
10+
- Update API version to `v5.0`
11+
- Add Support of `image_aspect_ratio` property for Generic Template (Thanks to @BFoucher)
12+
- Add support of `ice_breakers` and `home_url` properties for Profile API
13+
- Add support of `reply_to` property for Message callback
14+
- Add support of `Reaction` event
15+
- Properties `payment_settings` and `target_audience` are now deprecated
916

10-
**Changelog** (since [`3.2.0`](https://github.com/ker0x/messenger/compare/3.1.1...3.2.0))
17+
**Changelog** (since [`3.1.1`](https://github.com/ker0x/messenger/compare/3.1.1...3.2.0))
1118

1219
- 3.2.0 (2019-08)
1320
- Update API version to `v3.3`

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
<a href="https://packagist.org/packages/kerox/messenger" title="License">
2121
<img src="https://img.shields.io/packagist/l/kerox/messenger.svg?style=for-the-badge" alt="License">
2222
</a>
23-
<a href="https://gitter.im/ker0x/messenger" title="Chat">
24-
<img src="https://img.shields.io/badge/chat-gitter-46bc99.svg?style=for-the-badge" alt="Chat">
25-
</a>
2623
</div>
2724

2825
# Messenger
@@ -58,8 +55,8 @@ Please, refer to the [wiki](https://github.com/ker0x/messenger/wiki) to learn ho
5855

5956
### API
6057

61-
- [x] Broadcast
62-
- [x] Code
58+
- [x] Broadcast (deprecated)
59+
- [x] Code (deprecated)
6360
- [x] Insights
6461
- [x] Nlp
6562
- [x] Persona
@@ -79,14 +76,14 @@ Please, refer to the [wiki](https://github.com/ker0x/messenger/wiki) to learn ho
7976
- [x] Buttons
8077
- [x] Account Link
8178
- [x] Account Unlink
82-
- [x] Nested
79+
- [x] Nested (deprecated)
8380
- [x] Payment
8481
- [x] Phone Number
8582
- [x] Postback
86-
- [x] Share
83+
- [x] Share (deprecated)
8784
- [x] Web Url
8885
- [x] Generic
89-
- [x] List
86+
- [x] List (deprecated)
9087
- [x] Media
9188
- [x] Receipt
9289

@@ -106,6 +103,7 @@ Please, refer to the [wiki](https://github.com/ker0x/messenger/wiki) to learn ho
106103
- [x] Postback
107104
- [x] Pre Checkout
108105
- [x] Read
106+
- [x] Reaction
109107
- [x] Referral
110108
- [x] RequestThreadControl
111109
- [x] TakeThreadControl

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
},
4343
"scripts": {
4444
"php-stan": "vendor/bin/phpstan --level=max --memory-limit=\"-1\" --no-progress analyze",
45-
"php-cs-fixer": "php-cs-fixer fix --diff --verbose --config=.php_cs",
46-
"test": "phpunit"
45+
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --verbose --config=.php_cs",
46+
"php-unit": "vendor/bin/phpunit"
4747
},
4848
"config": {
4949
"optimize-autoloader": true,

src/Api/Profile.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ private function isValidFields(array $fields): void
6464
private function getAllowedFields(): array
6565
{
6666
return [
67-
self::PERSISTENT_MENU,
6867
self::GET_STARTED,
6968
self::GREETING,
69+
self::ICE_BREAKERS,
70+
self::PERSISTENT_MENU,
7071
self::DOMAIN_WHITELISTING,
7172
self::ACCOUNT_LINKING_URL,
7273
self::PAYMENT_SETTINGS,
74+
self::HOME_URL,
7375
self::TARGET_AUDIENCE,
7476
];
7577
}

src/Event/EventFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class EventFactory
2323
'app_roles' => AppRolesEvent::class,
2424
'referral' => ReferralEvent::class,
2525
'game_play' => GamePlayEvent::class,
26+
'reaction' => ReactionEvent::class,
2627
];
2728

2829
/**

src/Event/GamePlayEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getName(): string
4747
}
4848

4949
/**
50-
* @return mixed
50+
* @return \Kerox\Messenger\Event\GamePlayEvent
5151
*/
5252
public static function create(array $payload)
5353
{

src/Event/ReactionEvent.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kerox\Messenger\Event;
6+
7+
use Kerox\Messenger\Model\Callback\Reaction;
8+
9+
class ReactionEvent extends AbstractEvent
10+
{
11+
public const NAME = 'reaction';
12+
13+
protected $timestamp;
14+
protected $reaction;
15+
16+
public function __construct(string $senderId, string $recipientId, int $timestamp, Reaction $reaction)
17+
{
18+
parent::__construct($senderId, $recipientId);
19+
20+
$this->timestamp = $timestamp;
21+
$this->reaction = $reaction;
22+
}
23+
24+
public function getTimestamp(): int
25+
{
26+
return $this->timestamp;
27+
}
28+
29+
public function getReaction(): Reaction
30+
{
31+
return $this->reaction;
32+
}
33+
34+
public function getName(): string
35+
{
36+
return self::NAME;
37+
}
38+
39+
/**
40+
* @return \Kerox\Messenger\Event\ReactionEvent
41+
*/
42+
public static function create(array $payload): self
43+
{
44+
$senderId = $payload['sender']['id'];
45+
$recipientId = $payload['recipient']['id'];
46+
$timestamp = $payload['timestamp'];
47+
$reaction = Reaction::create($payload['reaction']);
48+
49+
return new static($senderId, $recipientId, $timestamp, $reaction);
50+
}
51+
}

src/Messenger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Messenger
2323
{
2424
public const API_URL = 'https://graph.facebook.com/';
25-
public const API_VERSION = 'v3.3';
25+
public const API_VERSION = 'v5.0';
2626

2727
/**
2828
* @var string

src/Model/Callback/Message.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class Message
2626
*/
2727
protected $attachments;
2828

29+
/**
30+
* @var string|null
31+
*/
32+
protected $replyTo;
33+
2934
/**
3035
* @var array
3136
*/
@@ -42,12 +47,14 @@ public function __construct(
4247
?string $text = null,
4348
?string $quickReply = null,
4449
array $attachments = [],
50+
?string $replyTo = null,
4551
array $entities = []
4652
) {
4753
$this->messageId = $messageId;
4854
$this->text = $text;
4955
$this->quickReply = $quickReply;
5056
$this->attachments = $attachments;
57+
$this->replyTo = $replyTo;
5158
$this->entities = $entities;
5259
}
5360

@@ -86,6 +93,16 @@ public function hasAttachments(): bool
8693
return !empty($this->attachments);
8794
}
8895

96+
public function getReplyTo(): ?string
97+
{
98+
return $this->replyTo;
99+
}
100+
101+
public function isReply(): bool
102+
{
103+
return $this->replyTo !== null && $this->replyTo !== '';
104+
}
105+
89106
public function getEntities(): array
90107
{
91108
return $this->entities;
@@ -102,10 +119,11 @@ public function hasEntities(): bool
102119
public static function create(array $callbackData)
103120
{
104121
$text = $callbackData['text'] ?? null;
105-
$quickReply = $callbackData['quick_reply']['payload'] ?? null;
106122
$attachments = $callbackData['attachments'] ?? [];
123+
$quickReply = $callbackData['quick_reply']['payload'] ?? null;
124+
$replyTo = $callbackData['reply_to']['mid'] ?? null;
107125
$entities = $callbackData['nlp']['entities'] ?? [];
108126

109-
return new self($callbackData['mid'], $text, $quickReply, $attachments, $entities);
127+
return new self($callbackData['mid'], $text, $quickReply, $attachments, $replyTo, $entities);
110128
}
111129
}

src/Model/Callback/Reaction.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kerox\Messenger\Model\Callback;
6+
7+
class Reaction
8+
{
9+
public const REACTION_SMILE = 'smile';
10+
public const REACTION_ANGRY = 'angry';
11+
public const REACTION_SAD = 'sad';
12+
public const REACTION_WOW = 'wow';
13+
public const REACTION_LOVE = 'love';
14+
public const REACTION_LIKE = 'like';
15+
public const REACTION_DISLIKE = 'dislike';
16+
public const REACTION_OTHER = 'other';
17+
18+
public const ACTION_REACT = 'react';
19+
public const ACTION_UNREACT = 'unreact';
20+
21+
protected $reaction;
22+
protected $emoji;
23+
protected $action;
24+
protected $mid;
25+
26+
/**
27+
* Reaction constructor.
28+
*/
29+
public function __construct(string $reaction, string $emoji, string $action, string $mid)
30+
{
31+
$this->reaction = $reaction;
32+
$this->emoji = $emoji;
33+
$this->action = $action;
34+
$this->mid = $mid;
35+
}
36+
37+
public function getReaction(): string
38+
{
39+
return $this->reaction;
40+
}
41+
42+
public function getEmoji(): string
43+
{
44+
return $this->emoji;
45+
}
46+
47+
public function getAction(): string
48+
{
49+
return $this->action;
50+
}
51+
52+
public function getMid(): string
53+
{
54+
return $this->mid;
55+
}
56+
57+
/**
58+
* @return \Kerox\Messenger\Model\Callback\Reaction
59+
*/
60+
public static function create(array $callbackData): self
61+
{
62+
return new self(
63+
$callbackData['reaction'],
64+
$callbackData['emoji'],
65+
$callbackData['action'],
66+
$callbackData['mid']
67+
);
68+
}
69+
}

src/Model/Message/Attachment/Template/GenericTemplate.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ class GenericTemplate extends Template
2525
* Generic constructor.
2626
*
2727
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement[] $elements
28-
* @param string $imageRatio
2928
*
3029
* @throws \Kerox\Messenger\Exception\MessengerException
3130
*/
32-
public function __construct(array $elements, $imageRatio = self::IMAGE_RATIO_HORIZONTAL)
31+
public function __construct(array $elements, string $imageRatio = self::IMAGE_RATIO_HORIZONTAL)
3332
{
3433
parent::__construct();
3534

@@ -40,13 +39,11 @@ public function __construct(array $elements, $imageRatio = self::IMAGE_RATIO_HOR
4039
}
4140

4241
/**
43-
* @param string $imageRatio
44-
*
4542
* @throws \Kerox\Messenger\Exception\MessengerException
4643
*
4744
* @return \Kerox\Messenger\Model\Message\Attachment\Template\GenericTemplate
4845
*/
49-
public static function create(array $elements, $imageRatio = self::IMAGE_RATIO_HORIZONTAL): self
46+
public static function create(array $elements, string $imageRatio = self::IMAGE_RATIO_HORIZONTAL): self
5047
{
5148
return new self($elements, $imageRatio);
5249
}

0 commit comments

Comments
 (0)