diff --git a/app/Http/Controllers/BotController.php b/app/Http/Controllers/BotController.php index c6663d0077cf..0a32a5b1f9e1 100644 --- a/app/Http/Controllers/BotController.php +++ b/app/Http/Controllers/BotController.php @@ -6,7 +6,6 @@ use App\Libraries\CurlUtils; use App\Libraries\Skype\SkypeResponse; use App\Models\SecurityCode; use App\Models\User; -use App\Models\Client; use App\Ninja\Intents\BaseIntent; use App\Ninja\Mailers\UserMailer; use Auth; @@ -100,27 +99,14 @@ class BotController extends Controller public function handleCommand() { - $data = $this->parseMessage(request()->command); - - // If they're viewing a client set it as the current state - $state = false; - $url = url()->previous(); - preg_match('/clients\/(\d*)/', $url, $matches); - if (count($matches) >= 2) { - if ($client = Client::scope($matches[1])->first()) { - $state = BaseIntent::blankState(); - $state->current->client = $client; - } - } + $command = request()->command; + $data = $this->parseMessage($command); try { - $intent = BaseIntent::createIntent(BOT_PLATFORM_WEB_APP, $state, $data); + $intent = BaseIntent::createIntent(BOT_PLATFORM_WEB_APP, false, $data); return $intent->process(); } catch (Exception $exception) { - $message = $exception->getMessage(); - if (env('APP_DEBUG')) { - $message .= '
' . request()->command . ' => ' . json_encode($data); - } + $message = sprintf('"%s"
%s', $command, $exception->getMessage()); return redirect()->back()->withWarning($message); } } diff --git a/app/Ninja/Intents/BaseIntent.php b/app/Ninja/Intents/BaseIntent.php index fa8d7da1d363..f65407283431 100644 --- a/app/Ninja/Intents/BaseIntent.php +++ b/app/Ninja/Intents/BaseIntent.php @@ -3,6 +3,7 @@ namespace App\Ninja\Intents; use App\Libraries\Skype\SkypeResponse; +use App\Models\Client; use Exception; use stdClass; @@ -16,27 +17,31 @@ class BaseIntent { //if (true) { if (! $state || is_string($state)) { - $state = static::blankState(); + $state = new stdClass(); + foreach (['current', 'previous'] as $reference) { + $state->$reference = new stdClass(); + $state->$reference->entityType = false; + foreach ([ENTITY_INVOICE, ENTITY_CLIENT, ENTITY_INVOICE_ITEM] as $entityType) { + $state->$reference->$entityType = []; + } + } } $this->state = $state; $this->data = $data; - - //var_dump($state); - } - - public static function blankState() - { - $state = new stdClass(); - foreach (['current', 'previous'] as $reference) { - $state->$reference = new stdClass(); - $state->$reference->entityType = false; - foreach ([ENTITY_INVOICE, ENTITY_CLIENT, ENTITY_INVOICE_ITEM] as $entityType) { - $state->$reference->$entityType = []; + + // If they're viewing a client set it as the current state + if (! $this->hasField('Filter', 'all')) { + $url = url()->previous(); + preg_match('/clients\/(\d*)/', $url, $matches); + if (count($matches) >= 2) { + if ($client = Client::scope($matches[1])->first()) { + $this->state->current->client = $client; + } } } - return $state; + //var_dump($state); } public static function createIntent($platform, $state, $data) @@ -71,10 +76,8 @@ class BaseIntent $className = "App\\Ninja\\Intents\\{$intent}Intent"; } - //echo "Intent: $intent

"; - if (! class_exists($className)) { - throw new Exception($intent . '... ' . trans('texts.intent_not_supported')); + throw new Exception(trans('texts.intent_not_supported')); } return new $className($state, $data); diff --git a/app/Ninja/Intents/WebApp/ListCreditIntent.php b/app/Ninja/Intents/WebApp/ListCreditIntent.php index 569ba3491537..dadc36080189 100644 --- a/app/Ninja/Intents/WebApp/ListCreditIntent.php +++ b/app/Ninja/Intents/WebApp/ListCreditIntent.php @@ -10,7 +10,7 @@ class ListCreditIntent extends BaseIntent { $this->loadStates(ENTITY_CREDIT); - if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { + if ($client = $this->requestClient()) { $url = $client->present()->url . '#credits'; } else { $url = '/credits'; diff --git a/app/Ninja/Intents/WebApp/ListInvoiceIntent.php b/app/Ninja/Intents/WebApp/ListInvoiceIntent.php index 7ca8bffa79e6..339493bb00f9 100644 --- a/app/Ninja/Intents/WebApp/ListInvoiceIntent.php +++ b/app/Ninja/Intents/WebApp/ListInvoiceIntent.php @@ -11,7 +11,7 @@ class ListInvoiceIntent extends InvoiceIntent $this->loadStates(ENTITY_INVOICE); $this->loadStatuses(ENTITY_INVOICE); - if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { + if ($client = $this->requestClient()) { $url = $client->present()->url . '#invoices'; } else { $url = '/invoices'; diff --git a/app/Ninja/Intents/WebApp/ListPaymentIntent.php b/app/Ninja/Intents/WebApp/ListPaymentIntent.php index 4dd30a3f471f..a545bd8559b3 100644 --- a/app/Ninja/Intents/WebApp/ListPaymentIntent.php +++ b/app/Ninja/Intents/WebApp/ListPaymentIntent.php @@ -10,7 +10,7 @@ class ListPaymentIntent extends BaseIntent { $this->loadStates(ENTITY_PAYMENT); - if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { + if ($client = $this->requestClient()) { $url = $client->present()->url . '#payments'; } else { $url = '/payments'; diff --git a/app/Ninja/Intents/WebApp/ListQuoteIntent.php b/app/Ninja/Intents/WebApp/ListQuoteIntent.php index 8faa4f04e280..1867d34e0dfe 100644 --- a/app/Ninja/Intents/WebApp/ListQuoteIntent.php +++ b/app/Ninja/Intents/WebApp/ListQuoteIntent.php @@ -11,7 +11,7 @@ class ListQuoteIntent extends InvoiceIntent $this->loadStates(ENTITY_QUOTE); $this->loadStatuses(ENTITY_QUOTE); - if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { + if ($client = $this->requestClient()) { $url = $client->present()->url . '#quotes'; } else { $url = '/quotes'; diff --git a/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php b/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php index a0d5c5a23f59..d8823dd7bbcb 100644 --- a/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php +++ b/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php @@ -10,7 +10,7 @@ class ListRecurringInvoiceIntent extends BaseIntent { $this->loadStates(ENTITY_RECURRING_INVOICE); - if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { + if ($client = $this->requestClient()) { $url = $client->present()->url . '#recurring_invoices'; } else { $url = '/recurring_invoices'; diff --git a/app/Ninja/Intents/WebApp/ListTaskIntent.php b/app/Ninja/Intents/WebApp/ListTaskIntent.php index da429572de34..05574761c836 100644 --- a/app/Ninja/Intents/WebApp/ListTaskIntent.php +++ b/app/Ninja/Intents/WebApp/ListTaskIntent.php @@ -10,7 +10,7 @@ class ListTaskIntent extends BaseIntent { $this->loadStates(ENTITY_TASK); - if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { + if ($client = $this->requestClient()) { $url = $client->present()->url . '#tasks'; } else { $url = '/tasks'; diff --git a/resources/views/partials/speech_recognition.blade.php b/resources/views/partials/speech_recognition.blade.php index d6519905135f..9f8cb98e7e13 100644 --- a/resources/views/partials/speech_recognition.blade.php +++ b/resources/views/partials/speech_recognition.blade.php @@ -172,9 +172,9 @@ } function onMicrophoneClick() { - //$('#search').val("show me all of edgar's credits"); + //$('#search').val("show me all deleted payments"); //$('#search').val("new invoice for joe, set the due date to today and the discount to ten percent"); - //$('#search').val("list joe's active and approved quotes"); + //$('#search').val("34123 1234123 1324"); //$('#search-form').submit(); //return;