From d26cb64bcb6087d7a55be3c4d4c0b25ff297fbc6 Mon Sep 17 00:00:00 2001 From: Vince Wong Date: Fri, 20 Jul 2018 20:51:59 +0800 Subject: [PATCH] Upgraded Graph API to v3.0 as v2.6 would be deprecated on July 13, 2018 (#67) --- src/Commands/AddGreetingText.php | 2 +- src/Commands/AddPersistentMenu.php | 2 +- src/Commands/AddStartButtonPayload.php | 2 +- src/Commands/WhitelistDomains.php | 2 +- src/FacebookDriver.php | 2 +- tests/FacebookDriverTest.php | 26 +++++++++++++------------- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Commands/AddGreetingText.php b/src/Commands/AddGreetingText.php index 9f2ade9..d5fae31 100644 --- a/src/Commands/AddGreetingText.php +++ b/src/Commands/AddGreetingText.php @@ -52,7 +52,7 @@ public function handle() } $response = $this->http->post( - 'https://graph.facebook.com/v2.6/me/messenger_profile?access_token='.config('botman.facebook.token'), + 'https://graph.facebook.com/v3.0/me/messenger_profile?access_token='.config('botman.facebook.token'), [], $payload); $responseObject = json_decode($response->getContent()); diff --git a/src/Commands/AddPersistentMenu.php b/src/Commands/AddPersistentMenu.php index 3b02c79..9203076 100644 --- a/src/Commands/AddPersistentMenu.php +++ b/src/Commands/AddPersistentMenu.php @@ -51,7 +51,7 @@ public function handle() exit; } - $response = $this->http->post('https://graph.facebook.com/v2.6/me/messenger_profile?access_token='.config('botman.facebook.token'), + $response = $this->http->post('https://graph.facebook.com/v3.0/me/messenger_profile?access_token='.config('botman.facebook.token'), [], $payload); $responseObject = json_decode($response->getContent()); diff --git a/src/Commands/AddStartButtonPayload.php b/src/Commands/AddStartButtonPayload.php index f8a72c2..11895c0 100644 --- a/src/Commands/AddStartButtonPayload.php +++ b/src/Commands/AddStartButtonPayload.php @@ -52,7 +52,7 @@ public function handle() } $response = $this->http->post( - 'https://graph.facebook.com/v2.6/me/messenger_profile?access_token='.config('botman.facebook.token'), + 'https://graph.facebook.com/v3.0/me/messenger_profile?access_token='.config('botman.facebook.token'), [], [ 'get_started' => [ diff --git a/src/Commands/WhitelistDomains.php b/src/Commands/WhitelistDomains.php index 976cfb0..588a5c1 100644 --- a/src/Commands/WhitelistDomains.php +++ b/src/Commands/WhitelistDomains.php @@ -51,7 +51,7 @@ public function handle() exit; } - $response = $this->http->post('https://graph.facebook.com/v2.6/me/messenger_profile?access_token='.config('botman.facebook.token'), + $response = $this->http->post('https://graph.facebook.com/v3.0/me/messenger_profile?access_token='.config('botman.facebook.token'), [], ['whitelisted_domains' => $payload]); $responseObject = json_decode($response->getContent()); diff --git a/src/FacebookDriver.php b/src/FacebookDriver.php index 7750728..eb153c4 100644 --- a/src/FacebookDriver.php +++ b/src/FacebookDriver.php @@ -66,7 +66,7 @@ class FacebookDriver extends HttpDriver implements VerifiesService /** @var DriverEventInterface */ protected $driverEvent; - protected $facebookProfileEndpoint = 'https://graph.facebook.com/v2.6/'; + protected $facebookProfileEndpoint = 'https://graph.facebook.com/v3.0/'; /** @var bool If the incoming request is a FB postback */ protected $isPostback = false; diff --git a/tests/FacebookDriverTest.php b/tests/FacebookDriverTest.php index 820aa72..334c0f1 100644 --- a/tests/FacebookDriverTest.php +++ b/tests/FacebookDriverTest.php @@ -202,7 +202,7 @@ public function it_returns_the_user_object() $facebookResponse = '{"first_name":"John","last_name":"Doe","profile_pic":"https://facebook.com/profilepic","locale":"en_US","timezone":2,"gender":"male","is_payment_enabled":true}'; $htmlInterface = m::mock(Curl::class); - $htmlInterface->shouldReceive('get')->once()->with('https://graph.facebook.com/v2.6/1433960459967306?fields=first_name,last_name,profile_pic,locale,timezone,gender,is_payment_enabled,last_ad_referral&access_token=Foo')->andReturn(new Response($facebookResponse)); + $htmlInterface->shouldReceive('get')->once()->with('https://graph.facebook.com/v3.0/1433960459967306?fields=first_name,last_name,profile_pic,locale,timezone,gender,is_payment_enabled,last_ad_referral&access_token=Foo')->andReturn(new Response($facebookResponse)); $driver = $this->getDriver($request, null, '', $htmlInterface); $message = $driver->getMessages()[0]; @@ -227,7 +227,7 @@ public function it_throws_exception_in_get_user() $request = '{"object":"page","entry":[{"id":"111899832631525","time":1480279487271,"messaging":[{"sender":{"id":"1433960459967306"},"recipient":{"id":"111899832631525"},"timestamp":1480279487147,"message":{"mid":"mid.1480279487147:4388d3b344","seq":36,"text":"Hi Julia"}}]}]}'; $htmlInterface = m::mock(Curl::class); - $htmlInterface->shouldReceive('get')->once()->with('https://graph.facebook.com/v2.6/1433960459967306?fields=first_name,last_name,profile_pic,locale,timezone,gender,is_payment_enabled,last_ad_referral&access_token=Foo')->andReturn(new Response('{}')); + $htmlInterface->shouldReceive('get')->once()->with('https://graph.facebook.com/v3.0/1433960459967306?fields=first_name,last_name,profile_pic,locale,timezone,gender,is_payment_enabled,last_ad_referral&access_token=Foo')->andReturn(new Response('{}')); $driver = $this->getDriver($request, null, '', $htmlInterface); $driver->getMessages()[0]; @@ -298,7 +298,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', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -347,7 +347,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', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -380,7 +380,7 @@ public function it_throws_exception_while_sending_message() $request = '{"object":"page","entry":[{"id":"111899832631525","time":1480279487271,"messaging":[{"sender":{"id":"1433960459967306"},"recipient":{"id":"111899832631525"},"timestamp":1480279487147,"message":{"mid":"mid.1480279487147:4388d3b344","seq":36,"text":"Hi Julia"}}]}]}'; $htmlInterface = m::mock(Curl::class); - $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -475,7 +475,7 @@ public function it_can_reply_questions() $question = Question::create('How are you doing?')->addButton(Button::create('Great')->value('great'))->addButton(Button::create('Good')->value('good')); $htmlInterface = m::mock(Curl::class); - $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -519,7 +519,7 @@ public function it_can_reply_questions_with_additional_button_parameters() $question = Question::create('How are you doing?')->addButton(Button::create('Great')->value('great')->additionalParameters(['foo' => 'bar']))->addButton(Button::create('Good')->value('good')); $htmlInterface = m::mock(Curl::class); - $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -567,7 +567,7 @@ public function it_can_reply_quick_replies_with_special_types() ->addAction(QuickReplyButton::create()->type('user_phone_number')); $htmlInterface = m::mock(Curl::class); - $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -659,7 +659,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', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -709,7 +709,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', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -764,7 +764,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', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -819,7 +819,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', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'messaging_type' => 'RESPONSE', 'recipient' => [ 'id' => '1234567890', @@ -941,7 +941,7 @@ public function it_calls_generic_event_for_unkown_facebook_events() public function it_can_reply_mark_seen_sender_action() { $htmlInterface = m::mock(Curl::class); - $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [ + $htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v3.0/me/messages', [], [ 'recipient' => [ 'id' => '1234567890', ],