Fixes for the bot

This commit is contained in:
Hillel Coren 2016-08-14 12:30:16 +03:00
parent 9e9da4e568
commit bfae5018e0
7 changed files with 17 additions and 11 deletions

View File

@ -66,9 +66,9 @@ class BotController extends Controller
} }
// regular chat message // regular chat message
} else { } else {
if ($message === 'help') { if ($text === 'help') {
$response = SkypeResponse::message(trans('texts.bot_help_message')); $response = SkypeResponse::message(trans('texts.bot_help_message'));
} elseif ($message == 'status') { } elseif ($text == 'status') {
$response = SkypeResponse::message(trans('texts.intent_not_supported')); $response = SkypeResponse::message(trans('texts.intent_not_supported'));
} else { } else {
if ( ! $user = User::whereBotUserId($botUserId)->with('account')->first()) { if ( ! $user = User::whereBotUserId($botUserId)->with('account')->first()) {
@ -98,8 +98,7 @@ class BotController extends Controller
private function authenticate($input) private function authenticate($input)
{ {
$headers = getallheaders(); $token = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : false;
$token = isset($headers['Authorization']) ? $headers['Authorization'] : false;
if (Utils::isNinjaDev()) { if (Utils::isNinjaDev()) {
// skip validation for testing // skip validation for testing
@ -261,6 +260,8 @@ class BotController extends Controller
return false; return false;
} }
$token = explode(' ', $token)[1];
// https://blogs.msdn.microsoft.com/tsmatsuz/2016/07/12/developing-skype-bot/ // https://blogs.msdn.microsoft.com/tsmatsuz/2016/07/12/developing-skype-bot/
// 0:Invalid, 1:Valid // 0:Invalid, 1:Valid
$token_valid = 0; $token_valid = 0;
@ -319,5 +320,4 @@ class BotController extends Controller
$res = base64_decode($res); $res = base64_decode($res);
return $res; return $res;
} }
} }

View File

@ -31,6 +31,7 @@ class VerifyCsrfToken extends BaseVerifier
'reseller_stats', 'reseller_stats',
'payment_hook/*', 'payment_hook/*',
'buy_now/*', 'buy_now/*',
'hook/bot/*',
]; ];
/** /**

View File

@ -67,7 +67,7 @@ class BaseIntent
public function process() public function process()
{ {
// do nothing by default throw new Exception(trans('texts.intent_not_supported'));
} }
public function setStateEntities($entityType, $entities) public function setStateEntities($entityType, $entities)

View File

@ -12,7 +12,7 @@ class ListProductsIntent extends ProductIntent
$account = Auth::user()->account; $account = Auth::user()->account;
$products = Product::scope() $products = Product::scope()
->orderBy('product_key') ->orderBy('product_key')
->limit(10) ->limit(5)
->get() ->get()
->transform(function($item, $key) use ($account) { ->transform(function($item, $key) use ($account) {
$card = $item->present()->skypeBot($account); $card = $item->present()->skypeBot($account);

View File

@ -144,11 +144,12 @@ class ClientRepository extends BaseRepository
$clients = Client::scope()->get(['id', 'name', 'public_id']); $clients = Client::scope()->get(['id', 'name', 'public_id']);
foreach ($clients as $client) { foreach ($clients as $client) {
$map[$client->id] = $client;
if ( ! $client->name) { if ( ! $client->name) {
continue; continue;
} }
$map[$client->id] = $client;
$similar = similar_text($clientNameMeta, metaphone($client->name), $percent); $similar = similar_text($clientNameMeta, metaphone($client->name), $percent);
if ($percent > $max) { if ($percent > $max) {

View File

@ -12,7 +12,11 @@
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L] RewriteRule ^ index.php [L]
# http://stackoverflow.com/a/20865084/497368
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# In case of running InvoiceNinja in a Subdomain like invoiceninja.example.com, # In case of running InvoiceNinja in a Subdomain like invoiceninja.example.com,
# you have to enable the following line: # you have to enable the following line:
# RewriteBase / # RewriteBase /

View File

@ -2054,7 +2054,7 @@ $LANG = array(
'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.', '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' => 'I wasn\'t able to find the client',
'not_allowed' => 'Sorry, you don\'t have the needed permissions', 'not_allowed' => 'Sorry, you don\'t have the needed permissions',
'bot_emailed_invoice' => 'Your invoice has been sent.', 'bot_emailed_invoice' => 'Your invoice has been sent.',
'bot_emailed_notify_viewed' => 'I\'ll email you when it\'s viewed.', 'bot_emailed_notify_viewed' => 'I\'ll email you when it\'s viewed.',
@ -2070,7 +2070,7 @@ $LANG = array(
'security_code_email_subject' => 'Security code for Invoice Ninja Bot', 'security_code_email_subject' => 'Security code for Invoice Ninja Bot',
'security_code_email_line1' => 'This is your Invoice Ninja Bot security code.', 'security_code_email_line1' => 'This is your Invoice Ninja Bot security code.',
'security_code_email_line2' => 'Note: it will expire in 10 minutes.', 'security_code_email_line2' => 'Note: it will expire in 10 minutes.',
'bot_help_message' => 'We currently support:<br/>• Create\update\email an invoice<br/>• List products<br/>For example:<br/><i>invoice bob for 2 tickets, set the due date to next thursday and the discount to 10 percent</i>', 'bot_help_message' => 'I currently support:<br/>• Create\update\email an invoice<br/>• List products<br/>For example:<br/><i>invoice bob for 2 tickets, set the due date to next thursday and the discount to 10 percent</i>',
'list_products' => 'List Products', 'list_products' => 'List Products',
); );