Skip to content

Commit

Permalink
Added 'mark_seen' sender action (#49)
Browse files Browse the repository at this point in the history
* Added 'mark_seen' sender action

* Test for FacebookDriver::markSeen
  • Loading branch information
drobee authored and mpociot committed Mar 10, 2018
1 parent c81a96a commit 24e3338
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/FacebookDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/FacebookDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}]}]}';
Expand Down

0 comments on commit 24e3338

Please sign in to comment.