diff --git a/app/Http/Controllers/BotController.php b/app/Http/Controllers/BotController.php index d58b5f577e38..7596884192d4 100644 --- a/app/Http/Controllers/BotController.php +++ b/app/Http/Controllers/BotController.php @@ -100,9 +100,7 @@ class BotController extends Controller public function handleCommand() { $data = $this->parseMessage(request()->command); - //dd($data); $intent = BaseIntent::createIntent(BOT_PLATFORM_WEB_APP, false, $data); - return $intent->process(); } diff --git a/app/Ninja/Intents/BaseIntent.php b/app/Ninja/Intents/BaseIntent.php index f95391c8ca72..0c08c694847e 100644 --- a/app/Ninja/Intents/BaseIntent.php +++ b/app/Ninja/Intents/BaseIntent.php @@ -43,7 +43,7 @@ class BaseIntent foreach ($data->entities as $entity) { if ($entity->type === 'EntityType') { - $entityType = $entity->entity; + $entityType = rtrim($entity->entity, 's'); break; } } @@ -53,6 +53,9 @@ class BaseIntent } $entityType = ucwords(strtolower($entityType)); + if ($entityType == 'Recurring') { + $entityType = 'RecurringInvoice'; + } $intent = str_replace('Entity', $entityType, $intent); if ($platform == BOT_PLATFORM_WEB_APP) { @@ -64,7 +67,7 @@ class BaseIntent //echo "Intent: $intent
"; if (! class_exists($className)) { - throw new Exception(trans('texts.intent_not_supported')); + throw new Exception($intent . ': ' . trans('texts.intent_not_supported')); } return new $className($state, $data); @@ -183,6 +186,22 @@ class BaseIntent return $data; } + protected function requestFieldsAsString($fields) + { + $str = ''; + + foreach ($this->requestFields() as $field => $value) { + if (in_array($field, $fields)) { + $str .= $field . '=' . urlencode($value) . '&'; + } + } + + $str = rtrim($str, '?'); + $str = rtrim($str, '&'); + + return $str; + } + protected function processField($field) { $field = str_replace(' ', '_', $field); diff --git a/app/Ninja/Intents/WebApp/CreateClientIntent.php b/app/Ninja/Intents/WebApp/CreateClientIntent.php new file mode 100644 index 000000000000..f8b05eaed6ac --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateClientIntent.php @@ -0,0 +1,18 @@ +requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateCreditIntent.php b/app/Ninja/Intents/WebApp/CreateCreditIntent.php new file mode 100644 index 000000000000..147ed99d4491 --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateCreditIntent.php @@ -0,0 +1,21 @@ +requestClient(); + $clientPublicId = $client ? $client->public_id : null; + + //$invoiceItems = $this->requestInvoiceItems(); + + $url = '/credits/create/' . $clientPublicId . '?'; + //$url .= $this->requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateExpenseIntent.php b/app/Ninja/Intents/WebApp/CreateExpenseIntent.php new file mode 100644 index 000000000000..f247937451c7 --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateExpenseIntent.php @@ -0,0 +1,18 @@ +requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php b/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php index c954bd65ee1c..24982099d251 100644 --- a/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php +++ b/app/Ninja/Intents/WebApp/CreateInvoiceIntent.php @@ -17,15 +17,7 @@ class CreateInvoiceIntent extends InvoiceIntent //$invoiceItems = $this->requestInvoiceItems(); $url = '/invoices/create/' . $clientPublicId . '?'; - - foreach ($this->requestFields() as $field => $value) { - if (in_array($field, Invoice::$requestFields)) { - $url .= $field . '=' . urlencode($value) . '&'; - } - } - - $url = rtrim($url, '?'); - $url = rtrim($url, '&'); + $url .= $this->requestFieldsAsString(Invoice::$requestFields); return redirect($url); } diff --git a/app/Ninja/Intents/WebApp/CreatePaymentIntent.php b/app/Ninja/Intents/WebApp/CreatePaymentIntent.php new file mode 100644 index 000000000000..7f62428c1274 --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreatePaymentIntent.php @@ -0,0 +1,21 @@ +requestClient(); + $clientPublicId = $client ? $client->public_id : null; + + //$invoiceItems = $this->requestInvoiceItems(); + + $url = '/payments/create/' . $clientPublicId . '?'; + //$url .= $this->requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateProductIntent.php b/app/Ninja/Intents/WebApp/CreateProductIntent.php new file mode 100644 index 000000000000..d8989b3f0c05 --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateProductIntent.php @@ -0,0 +1,21 @@ +requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateQuoteIntent.php b/app/Ninja/Intents/WebApp/CreateQuoteIntent.php new file mode 100644 index 000000000000..e3a46b0707d5 --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateQuoteIntent.php @@ -0,0 +1,22 @@ +requestClient(); + $clientPublicId = $client ? $client->public_id : null; + + //$invoiceItems = $this->requestInvoiceItems(); + + $url = '/quotes/create/' . $clientPublicId . '?'; + $url .= $this->requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateRecurringInvoiceIntent.php b/app/Ninja/Intents/WebApp/CreateRecurringInvoiceIntent.php new file mode 100644 index 000000000000..bbf04871696c --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateRecurringInvoiceIntent.php @@ -0,0 +1,22 @@ +requestClient(); + $clientPublicId = $client ? $client->public_id : null; + + //$invoiceItems = $this->requestInvoiceItems(); + + $url = '/recurring_invoices/create/' . $clientPublicId . '?'; + $url .= $this->requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateTaskIntent.php b/app/Ninja/Intents/WebApp/CreateTaskIntent.php new file mode 100644 index 000000000000..b1ff8266d40e --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateTaskIntent.php @@ -0,0 +1,21 @@ +requestClient(); + $clientPublicId = $client ? $client->public_id : null; + + //$invoiceItems = $this->requestInvoiceItems(); + + $url = '/tasks/create/' . $clientPublicId . '?'; + //$url .= $this->requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/CreateVendorIntent.php b/app/Ninja/Intents/WebApp/CreateVendorIntent.php new file mode 100644 index 000000000000..ef187567e70b --- /dev/null +++ b/app/Ninja/Intents/WebApp/CreateVendorIntent.php @@ -0,0 +1,18 @@ +requestFieldsAsString(Invoice::$requestFields); + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/ListClientIntent.php b/app/Ninja/Intents/WebApp/ListClientIntent.php new file mode 100644 index 000000000000..d10e42bf2015 --- /dev/null +++ b/app/Ninja/Intents/WebApp/ListClientIntent.php @@ -0,0 +1,13 @@ +