Skip to content

Commit 85da6b6

Browse files
committed
Add Laravel dependencies injection in ask() callbacks
1 parent c42cf17 commit 85da6b6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Traits/HandlesConversations.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait HandlesConversations
2020
*/
2121
public function startConversation(Conversation $instance, $recipient = null, $driver = null)
2222
{
23-
if (! is_null($recipient) && ! is_null($driver)) {
23+
if (!is_null($recipient) && !is_null($driver)) {
2424
$this->message = new IncomingMessage('', $recipient, '', null, $this->config['bot_id']);
2525
$this->driver = DriverManager::loadFromName($driver, $this->config);
2626
}
@@ -74,7 +74,7 @@ public function getStoredConversation($message = null)
7474
*/
7575
public function touchCurrentConversation()
7676
{
77-
if (! is_null($this->currentConversationData)) {
77+
if (!is_null($this->currentConversationData)) {
7878
$touched = $this->currentConversationData;
7979
$touched['time'] = microtime();
8080

@@ -119,7 +119,7 @@ public function removeStoredConversation($message = null)
119119
*/
120120
public function serializeClosure(Closure $closure)
121121
{
122-
if ($this->getDriver()->serializesCallbacks() && ! $this->runsOnSocket) {
122+
if ($this->getDriver()->serializesCallbacks() && !$this->runsOnSocket) {
123123
return serialize(new SerializableClosure($closure, true));
124124
}
125125

@@ -132,7 +132,7 @@ public function serializeClosure(Closure $closure)
132132
*/
133133
protected function unserializeClosure($closure)
134134
{
135-
if ($this->getDriver()->serializesCallbacks() && ! $this->runsOnSocket) {
135+
if ($this->getDriver()->serializesCallbacks() && !$this->runsOnSocket) {
136136
return unserialize($closure);
137137
}
138138

@@ -258,7 +258,7 @@ protected function callConversation($next, $convo, IncomingMessage $message, arr
258258
{
259259
/** @var \BotMan\BotMan\Messages\Conversations\Conversation $conversation */
260260
$conversation = $convo['conversation'];
261-
if (! $conversation instanceof ShouldQueue) {
261+
if (!$conversation instanceof ShouldQueue) {
262262
$conversation->setBot($this);
263263
}
264264
/*
@@ -303,6 +303,11 @@ protected function prepareConversationClosure($next, Conversation $conversation,
303303
}
304304

305305
$parameters[] = $conversation;
306-
call_user_func_array($next, $parameters);
306+
307+
if (class_exists('Illuminate\\Support\\Facades\\App')) {
308+
\Illuminate\Support\Facades\App::call($next, $parameters);
309+
} else {
310+
call_user_func_array($next, $parameters);
311+
}
307312
}
308313
}

0 commit comments

Comments
 (0)