Working on speech rec

This commit is contained in:
Hillel Coren 2017-04-06 16:47:37 +03:00
parent c2d04d2d2d
commit cd532fd66a
9 changed files with 32 additions and 43 deletions

View File

@ -6,7 +6,6 @@ use App\Libraries\CurlUtils;
use App\Libraries\Skype\SkypeResponse; use App\Libraries\Skype\SkypeResponse;
use App\Models\SecurityCode; use App\Models\SecurityCode;
use App\Models\User; use App\Models\User;
use App\Models\Client;
use App\Ninja\Intents\BaseIntent; use App\Ninja\Intents\BaseIntent;
use App\Ninja\Mailers\UserMailer; use App\Ninja\Mailers\UserMailer;
use Auth; use Auth;
@ -100,27 +99,14 @@ class BotController extends Controller
public function handleCommand() public function handleCommand()
{ {
$data = $this->parseMessage(request()->command); $command = request()->command;
$data = $this->parseMessage($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;
}
}
try { try {
$intent = BaseIntent::createIntent(BOT_PLATFORM_WEB_APP, $state, $data); $intent = BaseIntent::createIntent(BOT_PLATFORM_WEB_APP, false, $data);
return $intent->process(); return $intent->process();
} catch (Exception $exception) { } catch (Exception $exception) {
$message = $exception->getMessage(); $message = sprintf('"%s"<br/>%s', $command, $exception->getMessage());
if (env('APP_DEBUG')) {
$message .= '<br/>' . request()->command . ' => ' . json_encode($data);
}
return redirect()->back()->withWarning($message); return redirect()->back()->withWarning($message);
} }
} }

View File

@ -3,6 +3,7 @@
namespace App\Ninja\Intents; namespace App\Ninja\Intents;
use App\Libraries\Skype\SkypeResponse; use App\Libraries\Skype\SkypeResponse;
use App\Models\Client;
use Exception; use Exception;
use stdClass; use stdClass;
@ -16,27 +17,31 @@ class BaseIntent
{ {
//if (true) { //if (true) {
if (! $state || is_string($state)) { 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->state = $state;
$this->data = $data; $this->data = $data;
//var_dump($state); // If they're viewing a client set it as the current state
} if (! $this->hasField('Filter', 'all')) {
$url = url()->previous();
public static function blankState() preg_match('/clients\/(\d*)/', $url, $matches);
{ if (count($matches) >= 2) {
$state = new stdClass(); if ($client = Client::scope($matches[1])->first()) {
foreach (['current', 'previous'] as $reference) { $this->state->current->client = $client;
$state->$reference = new stdClass(); }
$state->$reference->entityType = false;
foreach ([ENTITY_INVOICE, ENTITY_CLIENT, ENTITY_INVOICE_ITEM] as $entityType) {
$state->$reference->$entityType = [];
} }
} }
return $state; //var_dump($state);
} }
public static function createIntent($platform, $state, $data) public static function createIntent($platform, $state, $data)
@ -71,10 +76,8 @@ class BaseIntent
$className = "App\\Ninja\\Intents\\{$intent}Intent"; $className = "App\\Ninja\\Intents\\{$intent}Intent";
} }
//echo "Intent: $intent<p>";
if (! class_exists($className)) { 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); return new $className($state, $data);

View File

@ -10,7 +10,7 @@ class ListCreditIntent extends BaseIntent
{ {
$this->loadStates(ENTITY_CREDIT); $this->loadStates(ENTITY_CREDIT);
if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { if ($client = $this->requestClient()) {
$url = $client->present()->url . '#credits'; $url = $client->present()->url . '#credits';
} else { } else {
$url = '/credits'; $url = '/credits';

View File

@ -11,7 +11,7 @@ class ListInvoiceIntent extends InvoiceIntent
$this->loadStates(ENTITY_INVOICE); $this->loadStates(ENTITY_INVOICE);
$this->loadStatuses(ENTITY_INVOICE); $this->loadStatuses(ENTITY_INVOICE);
if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { if ($client = $this->requestClient()) {
$url = $client->present()->url . '#invoices'; $url = $client->present()->url . '#invoices';
} else { } else {
$url = '/invoices'; $url = '/invoices';

View File

@ -10,7 +10,7 @@ class ListPaymentIntent extends BaseIntent
{ {
$this->loadStates(ENTITY_PAYMENT); $this->loadStates(ENTITY_PAYMENT);
if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { if ($client = $this->requestClient()) {
$url = $client->present()->url . '#payments'; $url = $client->present()->url . '#payments';
} else { } else {
$url = '/payments'; $url = '/payments';

View File

@ -11,7 +11,7 @@ class ListQuoteIntent extends InvoiceIntent
$this->loadStates(ENTITY_QUOTE); $this->loadStates(ENTITY_QUOTE);
$this->loadStatuses(ENTITY_QUOTE); $this->loadStatuses(ENTITY_QUOTE);
if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { if ($client = $this->requestClient()) {
$url = $client->present()->url . '#quotes'; $url = $client->present()->url . '#quotes';
} else { } else {
$url = '/quotes'; $url = '/quotes';

View File

@ -10,7 +10,7 @@ class ListRecurringInvoiceIntent extends BaseIntent
{ {
$this->loadStates(ENTITY_RECURRING_INVOICE); $this->loadStates(ENTITY_RECURRING_INVOICE);
if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { if ($client = $this->requestClient()) {
$url = $client->present()->url . '#recurring_invoices'; $url = $client->present()->url . '#recurring_invoices';
} else { } else {
$url = '/recurring_invoices'; $url = '/recurring_invoices';

View File

@ -10,7 +10,7 @@ class ListTaskIntent extends BaseIntent
{ {
$this->loadStates(ENTITY_TASK); $this->loadStates(ENTITY_TASK);
if (! $this->hasField('Filter', 'all') && $client = $this->requestClient()) { if ($client = $this->requestClient()) {
$url = $client->present()->url . '#tasks'; $url = $client->present()->url . '#tasks';
} else { } else {
$url = '/tasks'; $url = '/tasks';

View File

@ -172,9 +172,9 @@
} }
function onMicrophoneClick() { 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("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(); //$('#search-form').submit();
//return; //return;