Skip to content

Commit

Permalink
Add support for messaging_type as required per today. Fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed May 7, 2018
1 parent 823f4ea commit 705e8e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/FacebookDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class FacebookDriver extends HttpDriver implements VerifiesService
{
const HANDOVER_INBOX_PAGE_ID = '263902037430900';

const TYPE_RESPONSE = 'RESPONSE';
const TYPE_UPDATE = 'UPDATE';
const TYPE_MESSAGE_TAG = 'MESSAGE_TAG';

/** @var string */
protected $signature;

Expand Down Expand Up @@ -347,6 +351,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
$recipient = ['id' => $matchingMessage->getSender()];
}
$parameters = array_merge_recursive([
'messaging_type' => self::TYPE_RESPONSE,
'recipient' => $recipient,
'message' => [
'text' => $message,
Expand Down Expand Up @@ -384,6 +389,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
/**
* @param mixed $payload
* @return Response
* @throws FacebookException
*/
public function sendPayload($payload)
{
Expand All @@ -406,6 +412,7 @@ public function isConfigured()
*
* @param IncomingMessage $matchingMessage
* @return User
* @throws FacebookException
*/
public function getUser(IncomingMessage $matchingMessage)
{
Expand Down
10 changes: 10 additions & 0 deletions tests/FacebookDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,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', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -347,6 +348,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', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -379,6 +381,7 @@ public function it_throws_exception_while_sending_message()

$htmlInterface = m::mock(Curl::class);
$htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -473,6 +476,7 @@ public function it_can_reply_questions()

$htmlInterface = m::mock(Curl::class);
$htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -516,6 +520,7 @@ public function it_can_reply_questions_with_additional_button_parameters()

$htmlInterface = m::mock(Curl::class);
$htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -563,6 +568,7 @@ public function it_can_reply_quick_replies_with_special_types()

$htmlInterface = m::mock(Curl::class);
$htmlInterface->shouldReceive('post')->once()->with('https://graph.facebook.com/v2.6/me/messages', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -654,6 +660,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', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -703,6 +710,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', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -757,6 +765,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', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down Expand Up @@ -811,6 +820,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', [], [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => '1234567890',
],
Expand Down

0 comments on commit 705e8e0

Please sign in to comment.