Skip to content

Commit

Permalink
[n/a] add IceBreakers and Reaction
Browse files Browse the repository at this point in the history
[n/a] update README
  • Loading branch information
Romain Monteil committed Nov 12, 2019
1 parent fb865f8 commit 2a0bbda
Show file tree
Hide file tree
Showing 27 changed files with 456 additions and 34 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
The Messenger library follows [SemVer](http://semver.org/).

## 3.x
**Changelog** (since [`3.3.0`](https://github.com/ker0x/messenger/compare/3.2.0...3.3.0))

**Changelog** (since [`3.2.0`](https://github.com/ker0x/messenger/compare/3.2.0...3.3.0))

- 3.3.0 (2019-11)
- Support of `image_aspect_ratio` for Generic Template
- Update API version to `v5.0`
- Add Support of `image_aspect_ratio` property for Generic Template (Thanks to @BFoucher)
- Add support of `ice_breakers` and `home_url` properties for Profile API
- Add support of `reply_to` property for Message callback
- Add support of `Reaction` event
- Properties `payment_settings` and `target_audience` are now deprecated

**Changelog** (since [`3.2.0`](https://github.com/ker0x/messenger/compare/3.1.1...3.2.0))
**Changelog** (since [`3.1.1`](https://github.com/ker0x/messenger/compare/3.1.1...3.2.0))

- 3.2.0 (2019-08)
- Update API version to `v3.3`
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
<a href="https://packagist.org/packages/kerox/messenger" title="License">
<img src="https://img.shields.io/packagist/l/kerox/messenger.svg?style=for-the-badge" alt="License">
</a>
<a href="https://gitter.im/ker0x/messenger" title="Chat">
<img src="https://img.shields.io/badge/chat-gitter-46bc99.svg?style=for-the-badge" alt="Chat">
</a>
</div>

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

### API

- [x] Broadcast
- [x] Code
- [x] Broadcast (deprecated)
- [x] Code (deprecated)
- [x] Insights
- [x] Nlp
- [x] Persona
Expand All @@ -79,14 +76,14 @@ Please, refer to the [wiki](https://github.com/ker0x/messenger/wiki) to learn ho
- [x] Buttons
- [x] Account Link
- [x] Account Unlink
- [x] Nested
- [x] Nested (deprecated)
- [x] Payment
- [x] Phone Number
- [x] Postback
- [x] Share
- [x] Share (deprecated)
- [x] Web Url
- [x] Generic
- [x] List
- [x] List (deprecated)
- [x] Media
- [x] Receipt

Expand All @@ -106,6 +103,7 @@ Please, refer to the [wiki](https://github.com/ker0x/messenger/wiki) to learn ho
- [x] Postback
- [x] Pre Checkout
- [x] Read
- [x] Reaction
- [x] Referral
- [x] RequestThreadControl
- [x] TakeThreadControl
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
},
"scripts": {
"php-stan": "vendor/bin/phpstan --level=max --memory-limit=\"-1\" --no-progress analyze",
"php-cs-fixer": "php-cs-fixer fix --diff --verbose --config=.php_cs",
"test": "phpunit"
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --verbose --config=.php_cs",
"php-unit": "vendor/bin/phpunit"
},
"config": {
"optimize-autoloader": true,
Expand Down
4 changes: 3 additions & 1 deletion src/Api/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ private function isValidFields(array $fields): void
private function getAllowedFields(): array
{
return [
self::PERSISTENT_MENU,
self::GET_STARTED,
self::GREETING,
self::ICE_BREAKERS,
self::PERSISTENT_MENU,
self::DOMAIN_WHITELISTING,
self::ACCOUNT_LINKING_URL,
self::PAYMENT_SETTINGS,
self::HOME_URL,
self::TARGET_AUDIENCE,
];
}
Expand Down
1 change: 1 addition & 0 deletions src/Event/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class EventFactory
'app_roles' => AppRolesEvent::class,
'referral' => ReferralEvent::class,
'game_play' => GamePlayEvent::class,
'reaction' => ReactionEvent::class,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Event/GamePlayEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getName(): string
}

/**
* @return mixed
* @return \Kerox\Messenger\Event\GamePlayEvent
*/
public static function create(array $payload)
{
Expand Down
51 changes: 51 additions & 0 deletions src/Event/ReactionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Kerox\Messenger\Event;

use Kerox\Messenger\Model\Callback\Reaction;

class ReactionEvent extends AbstractEvent
{
public const NAME = 'reaction';

protected $timestamp;
protected $reaction;

public function __construct(string $senderId, string $recipientId, int $timestamp, Reaction $reaction)
{
parent::__construct($senderId, $recipientId);

$this->timestamp = $timestamp;
$this->reaction = $reaction;
}

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

public function getReaction(): Reaction
{
return $this->reaction;
}

public function getName(): string
{
return self::NAME;
}

/**
* @return \Kerox\Messenger\Event\ReactionEvent
*/
public static function create(array $payload): self
{
$senderId = $payload['sender']['id'];
$recipientId = $payload['recipient']['id'];
$timestamp = $payload['timestamp'];
$reaction = Reaction::create($payload['reaction']);

return new static($senderId, $recipientId, $timestamp, $reaction);
}
}
2 changes: 1 addition & 1 deletion src/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class Messenger
{
public const API_URL = 'https://graph.facebook.com/';
public const API_VERSION = 'v3.3';
public const API_VERSION = 'v5.0';

/**
* @var string
Expand Down
22 changes: 20 additions & 2 deletions src/Model/Callback/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Message
*/
protected $attachments;

/**
* @var string|null
*/
protected $replyTo;

/**
* @var array
*/
Expand All @@ -42,12 +47,14 @@ public function __construct(
?string $text = null,
?string $quickReply = null,
array $attachments = [],
?string $replyTo = null,
array $entities = []
) {
$this->messageId = $messageId;
$this->text = $text;
$this->quickReply = $quickReply;
$this->attachments = $attachments;
$this->replyTo = $replyTo;
$this->entities = $entities;
}

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

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

public function isReply(): bool
{
return $this->replyTo !== null && $this->replyTo !== '';
}

public function getEntities(): array
{
return $this->entities;
Expand All @@ -102,10 +119,11 @@ public function hasEntities(): bool
public static function create(array $callbackData)
{
$text = $callbackData['text'] ?? null;
$quickReply = $callbackData['quick_reply']['payload'] ?? null;
$attachments = $callbackData['attachments'] ?? [];
$quickReply = $callbackData['quick_reply']['payload'] ?? null;
$replyTo = $callbackData['reply_to']['mid'] ?? null;
$entities = $callbackData['nlp']['entities'] ?? [];

return new self($callbackData['mid'], $text, $quickReply, $attachments, $entities);
return new self($callbackData['mid'], $text, $quickReply, $attachments, $replyTo, $entities);
}
}
69 changes: 69 additions & 0 deletions src/Model/Callback/Reaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Kerox\Messenger\Model\Callback;

class Reaction
{
public const REACTION_SMILE = 'smile';
public const REACTION_ANGRY = 'angry';
public const REACTION_SAD = 'sad';
public const REACTION_WOW = 'wow';
public const REACTION_LOVE = 'love';
public const REACTION_LIKE = 'like';
public const REACTION_DISLIKE = 'dislike';
public const REACTION_OTHER = 'other';

public const ACTION_REACT = 'react';
public const ACTION_UNREACT = 'unreact';

protected $reaction;
protected $emoji;
protected $action;
protected $mid;

/**
* Reaction constructor.
*/
public function __construct(string $reaction, string $emoji, string $action, string $mid)
{
$this->reaction = $reaction;
$this->emoji = $emoji;
$this->action = $action;
$this->mid = $mid;
}

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

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

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

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

/**
* @return \Kerox\Messenger\Model\Callback\Reaction
*/
public static function create(array $callbackData): self
{
return new self(
$callbackData['reaction'],
$callbackData['emoji'],
$callbackData['action'],
$callbackData['mid']
);
}
}
7 changes: 2 additions & 5 deletions src/Model/Message/Attachment/Template/GenericTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ class GenericTemplate extends Template
* Generic constructor.
*
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\GenericElement[] $elements
* @param string $imageRatio
*
* @throws \Kerox\Messenger\Exception\MessengerException
*/
public function __construct(array $elements, $imageRatio = self::IMAGE_RATIO_HORIZONTAL)
public function __construct(array $elements, string $imageRatio = self::IMAGE_RATIO_HORIZONTAL)
{
parent::__construct();

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

/**
* @param string $imageRatio
*
* @throws \Kerox\Messenger\Exception\MessengerException
*
* @return \Kerox\Messenger\Model\Message\Attachment\Template\GenericTemplate
*/
public static function create(array $elements, $imageRatio = self::IMAGE_RATIO_HORIZONTAL): self
public static function create(array $elements, string $imageRatio = self::IMAGE_RATIO_HORIZONTAL): self
{
return new self($elements, $imageRatio);
}
Expand Down
Loading

0 comments on commit 2a0bbda

Please sign in to comment.