Skip to content

Commit

Permalink
Fixes for the bot
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Aug 14, 2016
1 parent 9e9da4e commit bfae501
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/BotController.php
Expand Up @@ -66,9 +66,9 @@ public function handleMessage($platform)
}
// regular chat message
} else {
if ($message === 'help') {
if ($text === 'help') {
$response = SkypeResponse::message(trans('texts.bot_help_message'));
} elseif ($message == 'status') {
} elseif ($text == 'status') {
$response = SkypeResponse::message(trans('texts.intent_not_supported'));
} else {
if ( ! $user = User::whereBotUserId($botUserId)->with('account')->first()) {
Expand Down Expand Up @@ -98,8 +98,7 @@ public function handleMessage($platform)

private function authenticate($input)
{
$headers = getallheaders();
$token = isset($headers['Authorization']) ? $headers['Authorization'] : false;
$token = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : false;

if (Utils::isNinjaDev()) {
// skip validation for testing
Expand Down Expand Up @@ -261,6 +260,8 @@ private function validateToken($token)
return false;
}

$token = explode(' ', $token)[1];

// https://blogs.msdn.microsoft.com/tsmatsuz/2016/07/12/developing-skype-bot/
// 0:Invalid, 1:Valid
$token_valid = 0;
Expand Down Expand Up @@ -319,5 +320,4 @@ private function base64_url_decode($arg) {
$res = base64_decode($res);
return $res;
}

}
1 change: 1 addition & 0 deletions app/Http/Middleware/VerifyCsrfToken.php
Expand Up @@ -31,6 +31,7 @@ class VerifyCsrfToken extends BaseVerifier
'reseller_stats',
'payment_hook/*',
'buy_now/*',
'hook/bot/*',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Ninja/Intents/BaseIntent.php
Expand Up @@ -67,7 +67,7 @@ public static function createIntent($state, $data)

public function process()
{
// do nothing by default
throw new Exception(trans('texts.intent_not_supported'));
}

public function setStateEntities($entityType, $entities)
Expand Down
2 changes: 1 addition & 1 deletion app/Ninja/Intents/ListProductsIntent.php
Expand Up @@ -12,7 +12,7 @@ public function process()
$account = Auth::user()->account;
$products = Product::scope()
->orderBy('product_key')
->limit(10)
->limit(5)
->get()
->transform(function($item, $key) use ($account) {
$card = $item->present()->skypeBot($account);
Expand Down
3 changes: 2 additions & 1 deletion app/Ninja/Repositories/ClientRepository.php
Expand Up @@ -144,11 +144,12 @@ public function findPhonetically($clientName)
$clients = Client::scope()->get(['id', 'name', 'public_id']);

foreach ($clients as $client) {
$map[$client->id] = $client;

if ( ! $client->name) {
continue;
}

$map[$client->id] = $client;
$similar = similar_text($clientNameMeta, metaphone($client->name), $percent);

if ($percent > $max) {
Expand Down
6 changes: 5 additions & 1 deletion public/.htaccess
Expand Up @@ -12,7 +12,11 @@
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
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,
# you have to enable the following line:
# RewriteBase /
Expand Down
4 changes: 2 additions & 2 deletions resources/lang/en/texts.php
Expand Up @@ -2054,7 +2054,7 @@
'invoice_for_client' => 'Invoice :invoice for :client',
'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' => 'I wasn\'t able to find the client',
'not_allowed' => 'Sorry, you don\'t have the needed permissions',
'bot_emailed_invoice' => 'Your invoice has been sent.',
'bot_emailed_notify_viewed' => 'I\'ll email you when it\'s viewed.',
Expand All @@ -2070,7 +2070,7 @@
'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_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',

);
Expand Down

0 comments on commit bfae501

Please sign in to comment.