public function process()
 {
     $invoice = $this->invoice();
     $message = trans('texts.' . $invoice->getEntityType()) . ' ' . $invoice->invoice_number;
     $message = link_to('/download/' . $invoice->invitations[0]->invitation_key, $message);
     return SkypeResponse::message($message);
 }
 public function process()
 {
     $invoice = $this->stateInvoice();
     if (!Auth::user()->can('edit', $invoice)) {
         throw new Exception(trans('texts.not_allowed'));
     }
     $contactMailer = app('App\\Ninja\\Mailers\\ContactMailer');
     $contactMailer->sendInvoice($invoice);
     $message = trans('texts.bot_emailed_' . $invoice->getEntityType());
     if (Auth::user()->notify_viewed) {
         $message .= '<br/>' . trans('texts.bot_emailed_notify_viewed');
     } elseif (Auth::user()->notify_paid) {
         $message .= '<br/>' . trans('texts.bot_emailed_notify_paid');
     }
     return SkypeResponse::message($message);
 }
 public function handleMessage($platform)
 {
     $input = Input::all();
     $botUserId = $input['from']['id'];
     if (!($token = $this->authenticate($input))) {
         return SkypeResponse::message(trans('texts.not_authorized'));
     }
     try {
         if ($input['type'] === 'contactRelationUpdate') {
             // brand new user, ask for their email
             if ($input['action'] === 'add') {
                 $response = SkypeResponse::message(trans('texts.bot_get_email'));
                 $state = BOT_STATE_GET_EMAIL;
             } elseif ($input['action'] === 'remove') {
                 $this->removeBot($botUserId);
                 $this->saveState($token, false);
                 return RESULT_SUCCESS;
             }
         } else {
             $state = $this->loadState($token);
             $text = strip_tags($input['text']);
             // user gaves us their email
             if ($state === BOT_STATE_GET_EMAIL) {
                 if ($this->validateEmail($text, $botUserId)) {
                     $response = SkypeResponse::message(trans('texts.bot_get_code'));
                     $state = BOT_STATE_GET_CODE;
                 } else {
                     $response = SkypeResponse::message(trans('texts.email_not_found', ['email' => $text]));
                 }
                 // user sent the scurity code
             } elseif ($state === BOT_STATE_GET_CODE) {
                 if ($this->validateCode($text, $botUserId)) {
                     $response = SkypeResponse::message(trans('texts.bot_welcome') . trans('texts.bot_help_message'));
                     $state = BOT_STATE_READY;
                 } else {
                     $response = SkypeResponse::message(trans('texts.invalid_code'));
                 }
                 // regular chat message
             } else {
                 if ($text === 'help') {
                     $response = SkypeResponse::message(trans('texts.bot_help_message'));
                 } elseif ($text == 'status') {
                     $response = SkypeResponse::message(trans('texts.intent_not_supported'));
                 } else {
                     if (!($user = User::whereBotUserId($botUserId)->with('account')->first())) {
                         return SkypeResponse::message(trans('texts.not_authorized'));
                     }
                     Auth::onceUsingId($user->id);
                     $user->account->loadLocalizationSettings();
                     $data = $this->parseMessage($text);
                     $intent = BaseIntent::createIntent($state, $data);
                     $response = $intent->process();
                     $state = $intent->getState();
                 }
             }
         }
         $this->saveState($token, $state);
     } catch (Exception $exception) {
         $response = SkypeResponse::message($exception->getMessage());
     }
     $this->sendResponse($token, $botUserId, $response);
     return RESULT_SUCCESS;
 }
示例#4
0
 protected function createResponse($type, $content)
 {
     $response = new SkypeResponse($type);
     if (is_string($content)) {
         $response->setText($content);
     } else {
         if ($content instanceof \Illuminate\Database\Eloquent\Collection) {
             // do nothing
         } elseif (!is_array($content)) {
             $content = [$content];
         }
         foreach ($content as $item) {
             $response->addAttachment($item);
         }
     }
     return json_encode($response);
 }