Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'mark_seen' sender action #49

Merged
merged 4 commits into from Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/FacebookDriver.php
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
Expand Up @@ -884,6 +884,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