Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Callback/CallbackEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tgallice\FBMessenger\Callback;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

abstract class CallbackEvent extends Event
{
Expand Down
57 changes: 57 additions & 0 deletions src/Callback/MessageDeleteEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Tgallice\FBMessenger\Callback;

use Tgallice\FBMessenger\Model\Callback\MessageDelete;

class MessageDeleteEvent extends CallbackEvent
{
const NAME = 'message_delete_event';

/**
* @var int
*/
private $timestamp;

/**
* @var MessageEcho
*/
private $messageDelete;

/**
* @param string $senderId
* @param string $recipientId
* @param int $timestamp
* @param MessageEcho $messageEcho
*/
public function __construct($senderId, $recipientId, $timestamp, MessageDelete $messageDelete)
{
parent::__construct($senderId, $recipientId);
$this->timestamp = $timestamp;
$this->messageDelete = $messageDelete;
}

/**
* @return int
*/
public function getTimestamp()
{
return $this->timestamp;
}

/**
* @return MessageEcho
*/
public function getMessageDelete()
{
return $this->messageDelete;
}

/**
* @return string
*/
public function getName()
{
return self::NAME;
}
}
21 changes: 21 additions & 0 deletions src/CallbackEventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Tgallice\FBMessenger\Callback\CallbackEvent;
use Tgallice\FBMessenger\Callback\MessageDeliveryEvent;
use Tgallice\FBMessenger\Callback\MessageEchoEvent;
use Tgallice\FBMessenger\Callback\MessageDeleteEvent;
use Tgallice\FBMessenger\Callback\MessageEvent;
use Tgallice\FBMessenger\Callback\MessageReadEvent;
use Tgallice\FBMessenger\Callback\PostbackEvent;
Expand All @@ -16,6 +17,7 @@
use Tgallice\FBMessenger\Model\Callback\Delivery;
use Tgallice\FBMessenger\Model\Callback\Message;
use Tgallice\FBMessenger\Model\Callback\MessageEcho;
use Tgallice\FBMessenger\Model\Callback\MessageDelete;
use Tgallice\FBMessenger\Model\Callback\Optin;
use Tgallice\FBMessenger\Model\Callback\Postback;
use Tgallice\FBMessenger\Model\Callback\Read;
Expand All @@ -36,6 +38,10 @@ public static function create(array $payload)
return self::createMessageEchoEvent($payload);
}

if (isset($payload['message']['is_deleted'])) {
return self::createMessageDeleteEvent($payload);
}

return self::createMessageEvent($payload);
}

Expand Down Expand Up @@ -102,6 +108,21 @@ public static function createMessageEchoEvent(array $payload)
return new MessageEchoEvent($senderId, $recipientId, $timestamp, $message);
}

/**
* @param array $payload
*
* @return MessageDeleteEvent
*/
public static function createMessageDeleteEvent(array $payload)
{
$message = MessageDelete::create($payload['message']);
$senderId = $payload['sender']['id'];
$recipientId = $payload['recipient']['id'];
$timestamp = $payload['timestamp'];

return new MessageDeleteEvent($senderId, $recipientId, $timestamp, $message);
}

/**
* @param array $payload
*
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Client
*/
private $lastResponse;

public function __construct($accessToken, ClientInterface $httpClient = null)
public function __construct($accessToken, ?ClientInterface $httpClient = null)
{
$this->accessToken = $accessToken;
$this->client = $httpClient ?: $this->defaultHttpClient();
Expand Down
23 changes: 6 additions & 17 deletions src/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public function getUserProfile(
UserProfile::FIRST_NAME,
UserProfile::LAST_NAME,
UserProfile::PROFILE_PIC,
UserProfile::LOCALE,
/*UserProfile::LOCALE,
UserProfile::TIMEZONE,
UserProfile::GENDER,
UserProfile::PAYMENT_ENABLED,
UserProfile::PAYMENT_ENABLED,*/
]
) {
$query = [
Expand Down Expand Up @@ -116,23 +116,12 @@ public function setGreetingText($text)
public function setStartedButton($payload)
{
$startedButton = new StartedButton($payload);
$setting = $this->buildSetting(
ThreadSetting::TYPE_CALL_TO_ACTIONS,
ThreadSetting::NEW_THREAD,
[$startedButton]
);

$this->postThreadSettings($setting);
$this->postThreadSettings(['get_started' => $startedButton]);
}

public function deleteStartedButton()
{
$setting = $this->buildSetting(
ThreadSetting::TYPE_CALL_TO_ACTIONS,
ThreadSetting::NEW_THREAD
);

$this->deleteThreadSettings($setting);
$this->deleteThreadSettings(['fields' => ['get_started']]);
}

/**
Expand Down Expand Up @@ -190,15 +179,15 @@ public static function create($token)
*/
private function postThreadSettings(array $setting)
{
$this->client->post('/me/thread_settings', $setting);
$this->client->post('/me/messenger_profile', $setting);
}

/**
* @param array $setting
*/
private function deleteThreadSettings(array $setting)
{
$this->client->send('DELETE', '/me/thread_settings', $setting);
$this->client->send('DELETE', '/me/messenger_profile', $setting);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Attachment/Template/ElementList.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ElementList extends Template
* @param ButtonModel|null $button
* @param string $topElementStyle
*/
public function __construct(array $elements, ButtonModel $button = null, $topElementStyle = self::TOP_STYLE_LARGE)
public function __construct(array $elements, ?ButtonModel $button = null, $topElementStyle = self::TOP_STYLE_LARGE)
{
if (empty($elements) || (count($elements) < 2 || count($elements) > 4)) {
throw new \InvalidArgumentException('You must provide between 2 and 4 elements.');
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Attachment/Template/ElementList/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Element extends AbstractElement
* @param Button|null $button
* @param DefaultAction|null $defaultAction
*/
public function __construct($title, $subtitle = null, $imageUrl = null, Button $button = null, DefaultAction $defaultAction = null)
public function __construct($title, $subtitle = null, $imageUrl = null, ?Button $button = null, ?DefaultAction $defaultAction = null)
{
parent::__construct($title, $subtitle, $imageUrl);
$this->button = $button;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Attachment/Template/Generic/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Element extends AbstractElement
/**
* @param string $title
*/
public function __construct($title, $subtitle = null, $imageUrl = null, array $buttons = null, DefaultAction $defaultAction = null)
public function __construct($title, $subtitle = null, $imageUrl = null, ?array $buttons = null, ?DefaultAction $defaultAction = null)
{
parent::__construct($title, $subtitle, $imageUrl);

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Attachment/Template/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function setOrderUrl($orderUrl)
/**
* @param null|Address $address
*/
public function setAddress(Address $address = null)
public function setAddress(?Address $address = null)
{
$this->address = $address;
}
Expand Down
1 change: 1 addition & 0 deletions src/Model/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function getType()
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
$json = [
Expand Down
14 changes: 12 additions & 2 deletions src/Model/Callback/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@ class Message
*/
private $quickReply;

private $isReply = false;

/**
* @param string $id
* @param int $sequence
* @param null|string $text
* @param array $attachments
* @param null|string $quickReply
*/
public function __construct($id, $sequence, $text = null, array $attachments = [], $quickReply = null)
public function __construct($id, $sequence, $text = null, array $attachments = [], $quickReply = null, $isReply = false)
{
$this->id = $id;
$this->sequence = $sequence;
$this->text = $text;
$this->attachments = $attachments;
$this->quickReply = $quickReply;
$this->isReply = $isReply;

}

/**
Expand All @@ -61,6 +65,11 @@ public function getSequence()
return $this->sequence;
}

public function hasReply()
{
return $this->isReply;
}

/**
* @return null|string
*/
Expand Down Expand Up @@ -143,7 +152,8 @@ public static function create(array $payload)
$text = isset($payload['text']) ? $payload['text'] : null;
$attachments = isset($payload['attachments']) ? $payload['attachments'] : [];
$quickReply = isset($payload['quick_reply']) ? $payload['quick_reply']['payload'] : null;
$isReply = isset($payload['reply_to']);

return new static($payload['mid'], $payload['seq'], $text, $attachments, $quickReply);
return new static($payload['mid'], $payload['seq'], $text, $attachments, $quickReply, $isReply);
}
}
78 changes: 78 additions & 0 deletions src/Model/Callback/MessageDelete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Tgallice\FBMessenger\Model\Callback;

class MessageDelete extends Message
{
/**
* @var bool
*/
private $isDelete;

/**
* @var int
*/
private $appId;

/**
* @var null|string
*/
private $metadata;

/**
* MessageEcho constructor.
*
* @param bool $isDelete
* @param int $appId
* @param string $id
* @param int $sequence
* @param null|string $metadata
* @param null|string $text
* @param array $attachments
*/
public function __construct($isDelete, $appId, $id, $sequence, $metadata = null, $text = null, array $attachments = [])
{
parent::__construct($id, $sequence, $text, $attachments);
$this->isDelete = $isDelete;
$this->appId = $appId;
$this->metadata = $metadata;
}

/**
* @return boolean
*/
public function isDelete()
{
return $this->isDelete;
}

/**
* @return int
*/
public function getAppId()
{
return $this->appId;
}

/**
* @return null|string
*/
public function getMetadata()
{
return $this->metadata;
}

/**
* @param array $payload
*
* @return static
*/
public static function create(array $payload)
{
$metadata = isset($payload['metadata']) ? $payload['metadata'] : null;
$text = isset($payload['text']) ? $payload['text'] : null;
$attachments = isset($payload['attachments']) ? $payload['attachments'] : [];

return new static(true, $payload['app_id'], $payload['mid'], $payload['seq'], $metadata, $text, $attachments);
}
}
2 changes: 1 addition & 1 deletion src/Model/Callback/Postback.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Postback
* @param string $payload
* @param Referral|null $referral
*/
public function __construct($payload, Referral $referral = null)
public function __construct($payload, ?Referral $referral = null)
{
$this->payload = $payload;
$this->referral = $referral;
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getMetadata()
/**
* @param null|QuickReply[] $quickReplies
*/
public function setQuickReplies(array $quickReplies = null)
public function setQuickReplies(?array $quickReplies = null)
{
if (count($quickReplies) > 10) {
throw new \InvalidArgumentException('A message can not have more than 10 quick replies.');
Expand Down Expand Up @@ -149,6 +149,7 @@ public function getFileStream()
/**
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return [
Expand Down
Loading