Skip to content

Commit adb1aa5

Browse files
committed
move facebook specific classes into their own namespace
1 parent c1b5df3 commit adb1aa5

File tree

4 files changed

+65
-65
lines changed

4 files changed

+65
-65
lines changed

src/Mpociot/BotMan/Button.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ class Button implements JsonSerializable
1818
/** @var string */
1919
protected $image_url;
2020

21-
/** @var string */
22-
protected $type;
23-
24-
/** @var string */
25-
protected $url;
26-
27-
/** @var string */
28-
protected $title;
29-
3021
/**
3122
* @param string $text
3223
*
@@ -46,14 +37,27 @@ public function __construct($text)
4637
}
4738

4839
/**
49-
* Shorter version of setter method.
50-
* @param string $methodName
51-
* @param array #arguments
52-
* @return object
40+
* Set the button value.
41+
*
42+
* @param string $value
43+
* @return $this
44+
*/
45+
public function value($value)
46+
{
47+
$this->value = $value;
48+
49+
return $this;
50+
}
51+
52+
/**
53+
* Set the button name (defaults to button text).
54+
*
55+
* @param string $name
56+
* @return $this
5357
*/
54-
public function __call($methodName, $arguments)
58+
public function name($name)
5559
{
56-
$this->{$methodName} = isset($arguments[0]) ? $arguments[0] : $arguments;
60+
$this->name = $name;
5761

5862
return $this;
5963
}
@@ -76,21 +80,13 @@ public function image($image_url)
7680
*/
7781
public function toArray()
7882
{
79-
if (isset($this->url)) {
80-
return [
81-
'type' => isset($this->type) ? $this->type : 'web_url',
82-
'url' => $this->url,
83-
'title' => isset($this->title) ? $this->title : $this->text,
84-
];
85-
} else {
86-
return [
87-
'name' => isset($this->name) ? $this->name : $this->text,
88-
'text' => $this->text,
89-
'image_url' => $this->image_url,
90-
'type' => 'button',
91-
'value' => $this->value,
92-
];
93-
}
83+
return [
84+
'name' => isset($this->name) ? $this->name : $this->text,
85+
'text' => $this->text,
86+
'image_url' => $this->image_url,
87+
'type' => 'button',
88+
'value' => $this->value,
89+
];
9490
}
9591

9692
/**
@@ -100,4 +96,4 @@ public function jsonSerialize()
10096
{
10197
return $this->toArray();
10298
}
103-
}
99+
}

src/Mpociot/BotMan/Drivers/FacebookDriver.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Mpociot\BotMan\Answer;
66
use Mpociot\BotMan\Message;
77
use Mpociot\BotMan\Question;
8-
use Mpociot\BotMan\Template;
98
use Illuminate\Support\Collection;
9+
use Mpociot\BotMan\Facebook\Template;
1010
use Symfony\Component\HttpFoundation\Request;
1111
use Symfony\Component\HttpFoundation\ParameterBag;
1212
use Mpociot\BotMan\Messages\Message as IncomingMessage;
@@ -147,9 +147,8 @@ public function isBot()
147147
private function convertQuestion(Question $question)
148148
{
149149
$questionData = $question->toArray();
150-
$buttonArray = $question->getButtons();
151150

152-
$replies = Collection::make($buttonArray)->map(function ($button) {
151+
$replies = Collection::make($question->getButtons())->map(function ($button) {
153152
return [
154153
'content_type' => 'text',
155154
'title' => $button['text'],
@@ -189,7 +188,6 @@ public function reply($message, $matchingMessage, $additionalParameters = [])
189188
} elseif ($message instanceof Template) {
190189
$parameters['message'] = $message->toArray();
191190
} elseif ($message instanceof IncomingMessage) {
192-
/* @todo add Audio & File content_types */
193191
if (! is_null($message->getImage())) {
194192
unset($parameters['message']['text']);
195193
$parameters['message']['attachment'] = [

src/Mpociot/BotMan/Facebook/Element.php

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Mpociot\BotMan;
3+
namespace Mpociot\BotMan\Facebook;
44

55
use JsonSerializable;
66

@@ -13,22 +13,14 @@ class Element implements JsonSerializable
1313
protected $image_url;
1414

1515
/** @var string */
16-
protected $subtitle;
17-
18-
/** @var string */
19-
protected $url;
16+
protected $item_url;
2017

2118
/** @var string */
22-
protected $fallback_url;
19+
protected $subtitle;
2320

2421
/** @var object */
2522
protected $buttons;
2623

27-
/** @var string */
28-
protected $messenger_extensions;
29-
30-
private $webview_height_ratio = 'full';
31-
3224
/**
3325
* @return static
3426
*/
@@ -46,14 +38,23 @@ public function __construct($title)
4638
}
4739

4840
/**
49-
* Shorter version of setter method.
50-
* @param string $methodName
51-
* @param array $arguments
41+
* @param string $title
5242
* @return $this
5343
*/
54-
public function __call($methodName, $arguments)
44+
public function title($title)
5545
{
56-
$this->{$methodName} = isset($arguments[0]) ? $arguments[0] : $arguments;
46+
$this->title = $title;
47+
48+
return $this;
49+
}
50+
51+
/**
52+
* @param string $subtitle
53+
* @return $this
54+
*/
55+
public function subtitle($subtitle)
56+
{
57+
$this->subtitle = $subtitle;
5758

5859
return $this;
5960
}
@@ -70,10 +71,21 @@ public function image($image_url)
7071
}
7172

7273
/**
73-
* @param Button $button
74+
* @param string $item_url
75+
* @return $this
76+
*/
77+
public function itemUrl($item_url)
78+
{
79+
$this->item_url = $item_url;
80+
81+
return $this;
82+
}
83+
84+
/**
85+
* @param ElementButton $button
7486
* @return $this
7587
*/
76-
public function addButton(Button $button)
88+
public function addButton(ElementButton $button)
7789
{
7890
$this->buttons[] = $button->toArray();
7991

@@ -88,7 +100,7 @@ public function addButtons(array $buttons)
88100
{
89101
if (isset($buttons) && is_array($buttons)) {
90102
foreach ($buttons as $button) {
91-
if ($button instanceof Button) {
103+
if ($button instanceof ElementButton) {
92104
$this->buttons[] = $button->toArray();
93105
}
94106
}
@@ -103,16 +115,10 @@ public function addButtons(array $buttons)
103115
public function toArray()
104116
{
105117
return [
106-
'title' => isset($this->title) ? $this->title : '',
107-
'image_url' => isset($this->image_url) ? $this->image_url : '',
108-
'subtitle' => isset($this->subtitle) ? $this->subtitle : '',
109-
'default_action' => [
110-
'type' => 'web_url',
111-
'url' => isset($this->url) ? $this->url : '',
112-
'messenger_extensions' => isset($this->messenger_extensions) ? $this->messenger_extensions : 'true',
113-
'webview_height_ratio' => isset($this->webview_height_ratio) ? $this->webview_height_ratio : 'compact',
114-
'fallback_url' => isset($this->fallback_url) ? $this->fallback_url : $this->url,
115-
],
118+
'title' => $this->title,
119+
'image_url' => $this->image_url,
120+
'item_url' => $this->item_url,
121+
'subtitle' => $this->subtitle,
116122
'buttons' => $this->buttons,
117123
];
118124
}

src/Mpociot/BotMan/Facebook/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Mpociot\BotMan;
3+
namespace Mpociot\BotMan\Facebook;
44

55
use JsonSerializable;
66

0 commit comments

Comments
 (0)