Skip to content

Commit

Permalink
added Exception to execute method
Browse files Browse the repository at this point in the history
  • Loading branch information
david p committed Feb 18, 2016
1 parent cadfba5 commit bd8d4c8
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions app/Http/Controllers/TelegramController.php
Expand Up @@ -43,23 +43,28 @@ public function receive(Request $request, $token)
}

private function execute($message, $tg) {
if(!array_key_exists('text', $message))
app()->abort(200, 'Missing command');

if(starts_with($message['text'], '/start'))
$this->start($message, $tg);
else if(starts_with($message['text'], '/cancel'))
$this->cancel($message, $tg);
else if(starts_with($message['text'], '/list'))
$this->listApps($message, $tg);
else if(starts_with($message['text'], '/revoke'))
$this->revoke($message, $tg);
else if(starts_with($message['text'], '/help'))
$this->help($message, $tg);
else
$this->commandReply($message);

return response()->json('', 200);
try {
if(!array_key_exists('text', $message))
app()->abort(200, 'Missing command');

if(starts_with($message['text'], '/start'))
$this->start($message, $tg);
else if(starts_with($message['text'], '/cancel'))
$this->cancel($message, $tg);
else if(starts_with($message['text'], '/list'))
$this->listApps($message, $tg);
else if(starts_with($message['text'], '/revoke'))
$this->revoke($message, $tg);
else if(starts_with($message['text'], '/help'))
$this->help($message, $tg);
else
$this->commandReply($message, $tg);

return response()->json('', 200);
} catch (\Exception $e) {
\Log::error($e);
app()->abort(200);
}
}

private function start($message, $tg) {
Expand Down Expand Up @@ -127,7 +132,6 @@ private function listApps($message, $tg)
$tg->save();

$apps = App::findByTelegramUser($tg);
\Log::debug($apps);
if(count($apps) > 0) {
$text = 'Here are your active apps:'.PHP_EOL;
$count = 1;
Expand Down

0 comments on commit bd8d4c8

Please sign in to comment.