diff --git a/src/FacebookDriver.php b/src/FacebookDriver.php index 41fec43..b4b8563 100644 --- a/src/FacebookDriver.php +++ b/src/FacebookDriver.php @@ -180,6 +180,23 @@ protected function validateSignature() 'sha1='.hash_hmac('sha1', $this->content, $this->config->get('app_secret'))); } + /** + * @param IncomingMessage $matchingMessage + * @return \Symfony\Component\HttpFoundation\Response + */ + public function markSeen(IncomingMessage $matchingMessage) + { + $parameters = [ + 'recipient' => [ + 'id' => $matchingMessage->getSender(), + ], + 'access_token' => $this->config->get('token'), + 'sender_action' => 'mark_seen', + ]; + + return $this->http->post($this->facebookProfileEndpoint.'me/messages', [], $parameters); + } + /** * @param IncomingMessage $matchingMessage * @return \Symfony\Component\HttpFoundation\Response diff --git a/tests/FacebookDriverTest.php b/tests/FacebookDriverTest.php index d1be928..6310867 100644 --- a/tests/FacebookDriverTest.php +++ b/tests/FacebookDriverTest.php @@ -928,6 +928,30 @@ public function it_calls_generic_event_for_unkown_facebook_events() } /** @test */ + 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', [], [ + 'recipient' => [ + 'id' => '1234567890', + ], + 'sender_action' => 'mark_seen', + 'access_token' => 'Foo', + ])->andReturn(new Response()); + + $request = m::mock(\Symfony\Component\HttpFoundation\Request::class.'[getContent]'); + $request->shouldReceive('getContent')->andReturn('[]'); + + $driver = new FacebookDriver($request, [ + 'facebook' => [ + 'token' => 'Foo', + ], + ], $htmlInterface); + + $message = new IncomingMessage('', '1234567890', ''); + $driver->markSeen($message); + } + public function it_returns_the_quick_reply_postback() { $request = '{"object":"page","entry":[{"id":"111899832631525","time":1480279487271,"messaging":[{"sender":{"id":"1433960459967306"},"recipient":{"id":"111899832631525"},"timestamp":1480279487147,"message":{"quick_reply":{"payload":"MY_PAYLOAD"},"mid":"mid.1480279487147:4388d3b344","seq":36,"text":"Red"}}]}]}';