Example #1
0
 /**
  * save data on hooking
  * @param  [type] $_data [description]
  * @return [type]        [description]
  */
 private static function saveHook($_data)
 {
     // define user detail array
     $from_id = self::response('from');
     $from_key = ['message', 'callback_query', 'chosen_inline_result', 'inline_query'];
     $from = false;
     foreach ($from_key as $key => $value) {
         if (array_key_exists($value, $_data)) {
             $from = $_data[$value]['from'];
             break;
         }
     }
     // add user_id to save dest of files
     self::$saveDest .= $from_id . '-' . self::response('from', 'username') . '/';
     // if we do not have from id return false
     if (!$from || !$from_id) {
         return false;
     }
     // catch user telegram from database and if not exist insert as new user
     self::catchTelegramUser($from_id, $from);
     // save user detail like contact or location if sended
     if ($contact = self::response('contact', null)) {
         self::saveUserDetail('contact', $contact);
     } elseif ($location = self::response('location')) {
         self::saveUserDetail('location', $location);
     }
     // change language if needede
     if (\lib\define::get_language('iso') !== self::$language) {
         \lib\define::set_language(self::$language);
     }
     return true;
 }