mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on speech rec
This commit is contained in:
parent
fcbc9bd885
commit
5128ca45a7
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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<p>";
|
||||
|
||||
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);
|
||||
|
18
app/Ninja/Intents/WebApp/CreateClientIntent.php
Normal file
18
app/Ninja/Intents/WebApp/CreateClientIntent.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreateClientIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$url = '/clients/create';
|
||||
|
||||
//$url = '/invoices/create/' . $clientPublicId . '?';
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
21
app/Ninja/Intents/WebApp/CreateCreditIntent.php
Normal file
21
app/Ninja/Intents/WebApp/CreateCreditIntent.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreateCreditIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$client = $this->requestClient();
|
||||
$clientPublicId = $client ? $client->public_id : null;
|
||||
|
||||
//$invoiceItems = $this->requestInvoiceItems();
|
||||
|
||||
$url = '/credits/create/' . $clientPublicId . '?';
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
18
app/Ninja/Intents/WebApp/CreateExpenseIntent.php
Normal file
18
app/Ninja/Intents/WebApp/CreateExpenseIntent.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreateExpenseIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$url = '/expenses/create';
|
||||
|
||||
//$url = '/invoices/create/' . $clientPublicId . '?';
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
21
app/Ninja/Intents/WebApp/CreatePaymentIntent.php
Normal file
21
app/Ninja/Intents/WebApp/CreatePaymentIntent.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreatePaymentIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$client = $this->requestClient();
|
||||
$clientPublicId = $client ? $client->public_id : null;
|
||||
|
||||
//$invoiceItems = $this->requestInvoiceItems();
|
||||
|
||||
$url = '/payments/create/' . $clientPublicId . '?';
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
21
app/Ninja/Intents/WebApp/CreateProductIntent.php
Normal file
21
app/Ninja/Intents/WebApp/CreateProductIntent.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\EntityModel;
|
||||
use App\Ninja\Intents\ProductIntent;
|
||||
use Exception;
|
||||
|
||||
class CreateProductIntent extends ProductIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$url = '/products/create';
|
||||
|
||||
//$url = '/invoices/create/' . $clientPublicId . '?';
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
22
app/Ninja/Intents/WebApp/CreateQuoteIntent.php
Normal file
22
app/Ninja/Intents/WebApp/CreateQuoteIntent.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreateQuoteIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$client = $this->requestClient();
|
||||
$clientPublicId = $client ? $client->public_id : null;
|
||||
|
||||
//$invoiceItems = $this->requestInvoiceItems();
|
||||
|
||||
$url = '/quotes/create/' . $clientPublicId . '?';
|
||||
$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
22
app/Ninja/Intents/WebApp/CreateRecurringInvoiceIntent.php
Normal file
22
app/Ninja/Intents/WebApp/CreateRecurringInvoiceIntent.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreateRecurringInvoiceIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$client = $this->requestClient();
|
||||
$clientPublicId = $client ? $client->public_id : null;
|
||||
|
||||
//$invoiceItems = $this->requestInvoiceItems();
|
||||
|
||||
$url = '/recurring_invoices/create/' . $clientPublicId . '?';
|
||||
$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
21
app/Ninja/Intents/WebApp/CreateTaskIntent.php
Normal file
21
app/Ninja/Intents/WebApp/CreateTaskIntent.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreateTaskIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$client = $this->requestClient();
|
||||
$clientPublicId = $client ? $client->public_id : null;
|
||||
|
||||
//$invoiceItems = $this->requestInvoiceItems();
|
||||
|
||||
$url = '/tasks/create/' . $clientPublicId . '?';
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
18
app/Ninja/Intents/WebApp/CreateVendorIntent.php
Normal file
18
app/Ninja/Intents/WebApp/CreateVendorIntent.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class CreateVendorIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
$url = '/vendors/create';
|
||||
|
||||
//$url = '/invoices/create/' . $clientPublicId . '?';
|
||||
//$url .= $this->requestFieldsAsString(Invoice::$requestFields);
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListClientIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListClientIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListClientIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/clients');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListCreditIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListCreditIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListCreditIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/credits');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListExpenseIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListExpenseIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListExpenseIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/expenses');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListInvoiceIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListInvoiceIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\InvoiceIntent;
|
||||
|
||||
class ListInvoiceIntent extends InvoiceIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/invoices');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListPaymentIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListPaymentIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListPaymentIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/payments');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListProductIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListProductIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListProductIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/products');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListQuoteIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListQuoteIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListQuotesIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/quotes');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListRecurringInvoiceIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/recurring_invoices');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListTaskIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListTaskIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListTaskIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/tasks');
|
||||
}
|
||||
}
|
13
app/Ninja/Intents/WebApp/ListVendorIntent.php
Normal file
13
app/Ninja/Intents/WebApp/ListVendorIntent.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Intents\WebApp;
|
||||
|
||||
use App\Ninja\Intents\BaseIntent;
|
||||
|
||||
class ListVendorIntent extends BaseIntent
|
||||
{
|
||||
public function process()
|
||||
{
|
||||
return redirect('/vendors');
|
||||
}
|
||||
}
|
@ -173,7 +173,9 @@
|
||||
}
|
||||
|
||||
function onMicrophoneClick() {
|
||||
$('#search').val('create new invoice for edgar a po number of 1234');
|
||||
//$('#search').val('create new invoice for edgar a po number of 1234');
|
||||
$('#search').val('create a task for edgar');
|
||||
//$('#search').val('show me all vendors');
|
||||
$('#search-form').submit();
|
||||
return;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user