Skip to content

Commit

Permalink
Add button text to conversation answer instead of button value for th…
Browse files Browse the repository at this point in the history
…e text field (#86)
  • Loading branch information
Christoph Rumpel authored Nov 14, 2018
1 parent 627d1b8 commit 5ccdd07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/FacebookDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function getConversationAnswer(IncomingMessage $message)
{
$payload = $message->getPayload();
if (isset($payload['message']['quick_reply'])) {
return Answer::create($message->getText())->setMessage($message)->setInteractiveReply(true)->setValue($payload['message']['quick_reply']['payload']);
return Answer::create($payload['message']['text'])->setMessage($message)->setInteractiveReply(true)->setValue($payload['message']['quick_reply']['payload']);
} elseif (isset($payload['postback']['payload'])) {
return Answer::create($payload['postback']['title'])->setMessage($message)->setInteractiveReply(true)->setValue($payload['postback']['payload']);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/FacebookDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,22 @@ public function it_can_reply_mark_seen_sender_action()
$driver->markSeen($message);
}

/** @test */
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"}}]}]}';

$driver = $this->getDriver($request);
$this->assertSame('MY_PAYLOAD', $driver->getMessages()[0]->getText());
}

/** @test */
public function it_returns_the_quick_reply_button_text_and_value_for_conversation_answer()
{
$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"}}]}]}';

$driver = $this->getDriver($request);
$this->assertSame('Red', $driver->getConversationAnswer($driver->getMessages()[0])->getText());
$this->assertSame('MY_PAYLOAD', $driver->getConversationAnswer($driver->getMessages()[0])->getValue());
}
}

0 comments on commit 5ccdd07

Please sign in to comment.