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\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 .= '<br/>' . request()->command . ' => ' . json_encode($data);
}
$message = sprintf('"%s"<br/>%s', $command, $exception->getMessage());
return redirect()->back()->withWarning($message);
}
}

View File

@ -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<p>";
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);

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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;