Skip to content

Commit 24e3338

Browse files
drobeempociot
authored andcommitted
Added 'mark_seen' sender action (#49)
* Added 'mark_seen' sender action * Test for FacebookDriver::markSeen
1 parent c81a96a commit 24e3338

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/FacebookDriver.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ protected function validateSignature()
180180
'sha1='.hash_hmac('sha1', $this->content, $this->config->get('app_secret')));
181181
}
182182

183+
/**
184+
* @param IncomingMessage $matchingMessage
185+
* @return \Symfony\Component\HttpFoundation\Response
186+
*/
187+
public function markSeen(IncomingMessage $matchingMessage)
188+
{
189+
$parameters = [
190+
'recipient' => [
191+
'id' => $matchingMessage->getSender(),
192+
],
193+
'access_token' => $this->config->get('token'),
194+
'sender_action' => 'mark_seen',
195+
];
196+
197+
return $this->http->post($this->facebookProfileEndpoint.'me/messages', [], $parameters);
198+
}
199+
183200
/**
184201
* @param IncomingMessage $matchingMessage
185202
* @return \Symfony\Component\HttpFoundation\Response

tests/FacebookDriverTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,30 @@ public function it_calls_generic_event_for_unkown_facebook_events()
928928
}
929929

930930
/** @test */
931+
public function it_can_reply_mark_seen_sender_action()
932+
{
933+
$htmlInterface = m::mock(Curl::class);
934+
$htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [
935+
'recipient' => [
936+
'id' => '1234567890',
937+
],
938+
'sender_action' => 'mark_seen',
939+
'access_token' => 'Foo',
940+
])->andReturn(new Response());
941+
942+
$request = m::mock(\Symfony\Component\HttpFoundation\Request::class.'[getContent]');
943+
$request->shouldReceive('getContent')->andReturn('[]');
944+
945+
$driver = new FacebookDriver($request, [
946+
'facebook' => [
947+
'token' => 'Foo',
948+
],
949+
], $htmlInterface);
950+
951+
$message = new IncomingMessage('', '1234567890', '');
952+
$driver->markSeen($message);
953+
}
954+
931955
public function it_returns_the_quick_reply_postback()
932956
{
933957
$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"}}]}]}';

0 commit comments

Comments
 (0)