mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on our bot
This commit is contained in:
parent
cb740a001c
commit
b8a124dc0f
@ -2,20 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Ninja\Repositories\InvoiceRepository;
|
use Exception;
|
||||||
use App\Ninja\Intents\BaseIntent;
|
use App\Ninja\Intents\BaseIntent;
|
||||||
|
|
||||||
class BotController extends Controller
|
class BotController extends Controller
|
||||||
{
|
{
|
||||||
protected $invoiceRepo;
|
|
||||||
|
|
||||||
public function __construct(InvoiceRepository $invoiceRepo)
|
|
||||||
{
|
|
||||||
//parent::__construct();
|
|
||||||
|
|
||||||
$this->invoiceRepo = $invoiceRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleMessage($platform)
|
public function handleMessage($platform)
|
||||||
{
|
{
|
||||||
$message = 'invoice acme client for 2 tickets';
|
$message = 'invoice acme client for 2 tickets';
|
||||||
@ -24,6 +15,35 @@ class BotController extends Controller
|
|||||||
//$message = view('bots.skype.message', ['message' => 'testing'])->render();
|
//$message = view('bots.skype.message', ['message' => 'testing'])->render();
|
||||||
//return $this->sendResponse($to, $message);
|
//return $this->sendResponse($to, $message);
|
||||||
|
|
||||||
|
$message = '{
|
||||||
|
"type": "message/image",
|
||||||
|
"text": "Test message",
|
||||||
|
"attachments": [
|
||||||
|
{
|
||||||
|
"contentType": "application/pdf",
|
||||||
|
"contentUrl": "http://www.orimi.com/pdf-test.pdf",
|
||||||
|
"thumbnailUrl": "http://www.orimi.com/pdf-test.pdf",
|
||||||
|
"filename": "test.pdf"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}';
|
||||||
|
return $this->sendResponse($to, $message);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$data = $this->parseMessage($message);
|
||||||
|
$intent = BaseIntent::createIntent($data);
|
||||||
|
$message = $intent->process();
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$message = view('bots.skype.message', [
|
||||||
|
'message' => $exception->getMessage()
|
||||||
|
])->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sendResponse($to, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseMessage($message)
|
||||||
|
{
|
||||||
$appId = env('MSBOT_LUIS_APP_ID');
|
$appId = env('MSBOT_LUIS_APP_ID');
|
||||||
$subKey = env('MSBOT_LUIS_SUBSCRIPTION_KEY');
|
$subKey = env('MSBOT_LUIS_SUBSCRIPTION_KEY');
|
||||||
$message = rawurlencode($message);
|
$message = rawurlencode($message);
|
||||||
@ -34,13 +54,7 @@ class BotController extends Controller
|
|||||||
|
|
||||||
var_dump($data->compositeEntities);
|
var_dump($data->compositeEntities);
|
||||||
|
|
||||||
if ($intent = BaseIntent::createIntent($data)) {
|
return $data;
|
||||||
$message = $intent->process();
|
|
||||||
} else {
|
|
||||||
$message = view('bots.skype.message', ['message' => trans('texts.intent_not_found')])->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sendResponse($to, $message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sendResponse($to, $message)
|
private function sendResponse($to, $message)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php namespace App\Ninja\Intents;
|
<?php namespace App\Ninja\Intents;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class BaseIntent
|
class BaseIntent
|
||||||
{
|
{
|
||||||
@ -13,14 +14,19 @@ class BaseIntent
|
|||||||
public static function createIntent($data)
|
public static function createIntent($data)
|
||||||
{
|
{
|
||||||
if ( ! count($data->intents)) {
|
if ( ! count($data->intents)) {
|
||||||
return false;
|
throw new Exception(trans('texts.intent_not_found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$intent = $data->intents[0];
|
$intent = $data->intents[0];
|
||||||
$intentType = $intent->intent;
|
$intentType = $intent->intent;
|
||||||
|
|
||||||
$className = "App\\Ninja\\Intents\\{$intentType}Intent";
|
$className = "App\\Ninja\\Intents\\{$intentType}Intent";
|
||||||
return new $className($data);
|
|
||||||
|
if ( ! class_exists($className)) {
|
||||||
|
throw new Exception(trans('texts.intent_not_supported'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new $className($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process()
|
public function process()
|
||||||
|
@ -2053,6 +2053,7 @@ $LANG = array(
|
|||||||
'payment_type_on_file' => ':type on file',
|
'payment_type_on_file' => ':type on file',
|
||||||
'invoice_for_client' => 'Invoice :invoice for :client',
|
'invoice_for_client' => 'Invoice :invoice for :client',
|
||||||
'intent_not_found' => 'Sorry, I\'m not sure what you\'re asking.',
|
'intent_not_found' => 'Sorry, I\'m not sure what you\'re asking.',
|
||||||
|
'intent_not_supported' => 'Sorry, I\'m not able to do that.',
|
||||||
'client_not_found' => 'We weren\'t able to find the client',
|
'client_not_found' => 'We weren\'t able to find the client',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
4
resources/views/bots/skype/message.blade.php
Normal file
4
resources/views/bots/skype/message.blade.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"type": "message/text",
|
||||||
|
"text": "{!! $message !!}"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user