From f8b5f179a880a2318bba1414b18d896093b5853a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 5 Apr 2017 18:04:44 +0300 Subject: [PATCH] Working on speech rec --- app/Constants.php | 2 +- app/Http/Controllers/BotController.php | 4 +++- app/Ninja/Intents/BaseIntent.php | 2 +- app/Ninja/Intents/WebApp/FindClientIntent.php | 17 +++++++++++++++++ app/Ninja/Intents/WebApp/FindInvoiceIntent.php | 17 +++++++++++++++++ app/Ninja/Intents/WebApp/FindQuoteIntent.php | 17 +++++++++++++++++ app/Ninja/Intents/WebApp/ListCreditIntent.php | 8 +++++++- app/Ninja/Intents/WebApp/ListInvoiceIntent.php | 8 +++++++- app/Ninja/Intents/WebApp/ListPaymentIntent.php | 8 +++++++- app/Ninja/Intents/WebApp/ListQuoteIntent.php | 8 +++++++- .../WebApp/ListRecurringInvoiceIntent.php | 8 +++++++- app/Ninja/Intents/WebApp/ListTaskIntent.php | 8 +++++++- .../views/partials/speech_recognition.blade.php | 5 ++--- 13 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 app/Ninja/Intents/WebApp/FindClientIntent.php create mode 100644 app/Ninja/Intents/WebApp/FindInvoiceIntent.php create mode 100644 app/Ninja/Intents/WebApp/FindQuoteIntent.php diff --git a/app/Constants.php b/app/Constants.php index c7d5ccd45a7b..07d1e750db4d 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -321,7 +321,7 @@ if (! defined('APP_NAME')) { define('FIREFOX_PDF_HELP_URL', 'https://support.mozilla.org/en-US/kb/view-pdf-files-firefox'); define('MSBOT_LOGIN_URL', 'https://login.microsoftonline.com/common/oauth2/v2.0/token'); - define('MSBOT_LUIS_URL', 'https://api.projectoxford.ai/luis/v1/application'); + define('MSBOT_LUIS_URL', 'https://westus.api.cognitive.microsoft.com/luis/v2.0/apps'); define('SKYPE_API_URL', 'https://apis.skype.com/v3'); define('MSBOT_STATE_URL', 'https://state.botframework.com/v3'); diff --git a/app/Http/Controllers/BotController.php b/app/Http/Controllers/BotController.php index 7596884192d4..1bd9be85bc55 100644 --- a/app/Http/Controllers/BotController.php +++ b/app/Http/Controllers/BotController.php @@ -100,6 +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(); } @@ -153,7 +154,8 @@ class BotController extends Controller $subKey = env('MSBOT_LUIS_SUBSCRIPTION_KEY'); $message = rawurlencode($message); - $url = sprintf('%s?id=%s&subscription-key=%s&q=%s', MSBOT_LUIS_URL, $appId, $subKey, $message); + $url = sprintf('%s/%s?subscription-key=%s&verbose=true&q=%s', MSBOT_LUIS_URL, $appId, $subKey, $message); + //$url = sprintf('%s?id=%s&subscription-key=%s&q=%s', MSBOT_LUIS_URL, $appId, $subKey, $message); $data = file_get_contents($url); $data = json_decode($data); diff --git a/app/Ninja/Intents/BaseIntent.php b/app/Ninja/Intents/BaseIntent.php index 7693627eb85f..4c170bba7311 100644 --- a/app/Ninja/Intents/BaseIntent.php +++ b/app/Ninja/Intents/BaseIntent.php @@ -51,7 +51,7 @@ class BaseIntent if ($state && ! $entityType) { $entityType = $state->current->entityType; } - + $entityType = $entityType ?: 'client'; $entityType = ucwords(strtolower($entityType)); if ($entityType == 'Recurring') { $entityType = 'RecurringInvoice'; diff --git a/app/Ninja/Intents/WebApp/FindClientIntent.php b/app/Ninja/Intents/WebApp/FindClientIntent.php new file mode 100644 index 000000000000..baa438193921 --- /dev/null +++ b/app/Ninja/Intents/WebApp/FindClientIntent.php @@ -0,0 +1,17 @@ +requestClient(); + + $url = $client ? $client->present()->url : '/clients'; + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/FindInvoiceIntent.php b/app/Ninja/Intents/WebApp/FindInvoiceIntent.php new file mode 100644 index 000000000000..158cdd023482 --- /dev/null +++ b/app/Ninja/Intents/WebApp/FindInvoiceIntent.php @@ -0,0 +1,17 @@ +requestInvoice(); + + $url = $invoice ? $invoice->present()->url : '/invoices'; + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/FindQuoteIntent.php b/app/Ninja/Intents/WebApp/FindQuoteIntent.php new file mode 100644 index 000000000000..0222c15dddc3 --- /dev/null +++ b/app/Ninja/Intents/WebApp/FindQuoteIntent.php @@ -0,0 +1,17 @@ +requestInvoice(); + + $url = $invoice ? $invoice->present()->url : '/quotes'; + + return redirect($url); + } +} diff --git a/app/Ninja/Intents/WebApp/ListCreditIntent.php b/app/Ninja/Intents/WebApp/ListCreditIntent.php index 0beb440e5540..b4f9412cf3c2 100644 --- a/app/Ninja/Intents/WebApp/ListCreditIntent.php +++ b/app/Ninja/Intents/WebApp/ListCreditIntent.php @@ -8,6 +8,12 @@ class ListCreditIntent extends BaseIntent { public function process() { - return redirect('/credits'); + if ($client = $this->requestClient()) { + $url = $client->present()->url . '#credits'; + } else { + $url = '/credits'; + } + + return redirect($url); } } diff --git a/app/Ninja/Intents/WebApp/ListInvoiceIntent.php b/app/Ninja/Intents/WebApp/ListInvoiceIntent.php index 7cf31d3b4cb0..477258f94f66 100644 --- a/app/Ninja/Intents/WebApp/ListInvoiceIntent.php +++ b/app/Ninja/Intents/WebApp/ListInvoiceIntent.php @@ -8,6 +8,12 @@ class ListInvoiceIntent extends InvoiceIntent { public function process() { - return redirect('/invoices'); + if ($client = $this->requestClient()) { + $url = $client->present()->url . '#invoices'; + } else { + $url = '/invoices'; + } + + return redirect($url); } } diff --git a/app/Ninja/Intents/WebApp/ListPaymentIntent.php b/app/Ninja/Intents/WebApp/ListPaymentIntent.php index 94456df19c43..40f2f3688e88 100644 --- a/app/Ninja/Intents/WebApp/ListPaymentIntent.php +++ b/app/Ninja/Intents/WebApp/ListPaymentIntent.php @@ -8,6 +8,12 @@ class ListPaymentIntent extends BaseIntent { public function process() { - return redirect('/payments'); + if ($client = $this->requestClient()) { + $url = $client->present()->url . '#payments'; + } else { + $url = '/payments'; + } + + return redirect($url); } } diff --git a/app/Ninja/Intents/WebApp/ListQuoteIntent.php b/app/Ninja/Intents/WebApp/ListQuoteIntent.php index 66887cf73b1c..76bae43d0575 100644 --- a/app/Ninja/Intents/WebApp/ListQuoteIntent.php +++ b/app/Ninja/Intents/WebApp/ListQuoteIntent.php @@ -8,6 +8,12 @@ class ListQuotesIntent extends BaseIntent { public function process() { - return redirect('/quotes'); + if ($client = $this->requestClient()) { + $url = $client->present()->url . '#quotes'; + } else { + $url = '/quotes'; + } + + return redirect($url); } } diff --git a/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php b/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php index cf98df5ee6e3..d0233c6db7fb 100644 --- a/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php +++ b/app/Ninja/Intents/WebApp/ListRecurringInvoiceIntent.php @@ -8,6 +8,12 @@ class ListRecurringInvoiceIntent extends BaseIntent { public function process() { - return redirect('/recurring_invoices'); + if ($client = $this->requestClient()) { + $url = $client->present()->url . '#recurring_invoices'; + } else { + $url = '/recurring_invoices'; + } + + return redirect($url); } } diff --git a/app/Ninja/Intents/WebApp/ListTaskIntent.php b/app/Ninja/Intents/WebApp/ListTaskIntent.php index 41e1a4fc6048..f8c68626cd58 100644 --- a/app/Ninja/Intents/WebApp/ListTaskIntent.php +++ b/app/Ninja/Intents/WebApp/ListTaskIntent.php @@ -8,6 +8,12 @@ class ListTaskIntent extends BaseIntent { public function process() { - return redirect('/tasks'); + if ($client = $this->requestClient()) { + $url = $client->present()->url . '#tasks'; + } else { + $url = '/tasks'; + } + + return redirect($url); } } diff --git a/resources/views/partials/speech_recognition.blade.php b/resources/views/partials/speech_recognition.blade.php index cfb63f7b3413..bc3ffeaca483 100644 --- a/resources/views/partials/speech_recognition.blade.php +++ b/resources/views/partials/speech_recognition.blade.php @@ -172,9 +172,8 @@ } function onMicrophoneClick() { - $('#search').val('new payment for invoice 1279'); - //$('#search').val('invoice for edgar'); - //$('#search').val('create a task for edgar'); + //$('#search').val("show me all of edgar's credits"); + $('#search').val("show me edgar's credits"); $('#search-form').submit(); return;