From 705e8e05001831581909f39e0d57b89f325654d9 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 7 May 2018 21:21:58 +0200 Subject: [PATCH] Add support for messaging_type as required per today. Fixes #39 --- src/FacebookDriver.php | 7 +++++++ tests/FacebookDriverTest.php | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/FacebookDriver.php b/src/FacebookDriver.php index b4b8563..7750728 100644 --- a/src/FacebookDriver.php +++ b/src/FacebookDriver.php @@ -34,6 +34,10 @@ class FacebookDriver extends HttpDriver implements VerifiesService { const HANDOVER_INBOX_PAGE_ID = '263902037430900'; + const TYPE_RESPONSE = 'RESPONSE'; + const TYPE_UPDATE = 'UPDATE'; + const TYPE_MESSAGE_TAG = 'MESSAGE_TAG'; + /** @var string */ protected $signature; @@ -347,6 +351,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam $recipient = ['id' => $matchingMessage->getSender()]; } $parameters = array_merge_recursive([ + 'messaging_type' => self::TYPE_RESPONSE, 'recipient' => $recipient, 'message' => [ 'text' => $message, @@ -384,6 +389,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam /** * @param mixed $payload * @return Response + * @throws FacebookException */ public function sendPayload($payload) { @@ -406,6 +412,7 @@ public function isConfigured() * * @param IncomingMessage $matchingMessage * @return User + * @throws FacebookException */ public function getUser(IncomingMessage $matchingMessage) { diff --git a/tests/FacebookDriverTest.php b/tests/FacebookDriverTest.php index 6310867..820aa72 100644 --- a/tests/FacebookDriverTest.php +++ b/tests/FacebookDriverTest.php @@ -299,6 +299,7 @@ public function it_can_reply_string_messages() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -347,6 +348,7 @@ public function it_can_reply_with_additional_parameters() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -379,6 +381,7 @@ public function it_throws_exception_while_sending_message() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -473,6 +476,7 @@ public function it_can_reply_questions() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -516,6 +520,7 @@ public function it_can_reply_questions_with_additional_button_parameters() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -563,6 +568,7 @@ public function it_can_reply_quick_replies_with_special_types() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -654,6 +660,7 @@ public function it_can_reply_message_objects() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -703,6 +710,7 @@ public function it_can_reply_message_objects_with_image() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -757,6 +765,7 @@ public function it_can_reply_message_objects_with_audio() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ], @@ -811,6 +820,7 @@ public function it_can_reply_message_objects_with_file() $htmlInterface = m::mock(Curl::class); $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', ],