├── .gitignore ├── src ├── autoload.php ├── run.php ├── settings.php ├── dependencies.php ├── command.php └── dispatcher.php ├── composer.json ├── api ├── controller │ ├── MainController.php │ ├── InlineController.php │ ├── CallbackController.php │ └── MessageController.php ├── index.php ├── model │ ├── MainModel.php │ ├── RedirectModel.php │ ├── AdsModel.php │ ├── GameModel.php │ └── UserModel.php ├── service │ ├── IO.php │ ├── Redirect.php │ └── Token.php └── main │ ├── InlineMain.php │ ├── MainMain.php │ ├── CallbackMain.php │ ├── KeyboardMain.php │ └── MessageMain.php ├── README.md └── composer.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /log/* 3 | .idea 4 | -------------------------------------------------------------------------------- /src/autoload.php: -------------------------------------------------------------------------------- 1 | container = $container; 18 | } 19 | } -------------------------------------------------------------------------------- /api/index.php: -------------------------------------------------------------------------------- 1 | controller; 5 | $methodName = $dispatch->method; 6 | $namespace = '\controller\\' . $controllerName; 7 | $controller = new $namespace($container); 8 | 9 | # execute method 10 | try { 11 | $controller->$methodName(); 12 | } catch (Exception $e) { 13 | /** @var \main\MessageMain $messageMain */ 14 | $messageMain = $container->get('messageMain'); 15 | $messageMain->errorCreateResult(); 16 | } 17 | 18 | # send response 19 | /** @var \service\IO $io */ 20 | $io = $container->get('io'); 21 | $io->sendResponse(); 22 | -------------------------------------------------------------------------------- /src/settings.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'name' => 'bot', 6 | 'path' => '../log/debug.log', 7 | ], 8 | 9 | 'mongodb' => [ 10 | 'host' => '', 11 | 'dbname' => '', 12 | ], 13 | 14 | 'baseUrl' => [ 15 | 'hubView' => '', 16 | 'smsUrl' => '', 17 | 'redirect' => '' 18 | ], 19 | 20 | 'cache' => [ 21 | 'hubPhoto' => '', 22 | 'competitionPhoto' => '', 23 | ], 24 | 'bot' => [ 25 | 'id' => '', 26 | 'name' => '', 27 | ], 28 | ]; 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Telegram bot: 2 | Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and inline requests. You control your bots using HTTPS requests to our bot API. 3 | The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. 4 | https://core.telegram.org/bots/api 5 | ## Stack: 6 | php / slim farmework / mongodb / jwt 7 | ## Contributing 8 | If you find a bug or need a feature don't hesitate to tell me about it. It's open-source, so, if you are a developer or you can help me to improve it (develop, documentation, design, etc.), open an issue or send a PR. 9 | -------------------------------------------------------------------------------- /api/controller/InlineController.php: -------------------------------------------------------------------------------- 1 | inlineMain()->getAllGames(); 13 | 14 | # 2.prepare telegram games format 15 | $this->inlineMain()->createTelegramFormatGames(); 16 | 17 | # 3.create and set result 18 | $this->inlineMain()->listCreateResult(); 19 | } 20 | 21 | private function inlineMain(): InlineMain 22 | { 23 | return $this->container->get('inlineMain'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /api/model/MainModel.php: -------------------------------------------------------------------------------- 1 | container = $container; 19 | } 20 | 21 | /** 22 | * @param string $collection 23 | * @return Collection 24 | */ 25 | public function mongo(string $collection): Collection 26 | { 27 | return $this->container->get('mongo')->{$collection}; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /api/model/RedirectModel.php: -------------------------------------------------------------------------------- 1 | mongo('redirect')->updateOne( 15 | ['_id' => $userId], 16 | [ 17 | '$set' => [ 18 | "$type.url" => $url, 19 | "$type.last_access_time" => time() 20 | ] 21 | ], 22 | ['upsert' => true] 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /api/model/AdsModel.php: -------------------------------------------------------------------------------- 1 | findAdsByUserId($userId); 14 | 15 | if (!$adsDocument) { 16 | $this->mongo('ads')->insertOne([ 17 | '_id' => $userId, 18 | 'ads_id' => $adsId, 19 | 'create_time' => time() 20 | ]); 21 | } 22 | } 23 | 24 | /** 25 | * @param string $userId 26 | * @return array|null|object 27 | */ 28 | public function findAdsByUserId(string $userId) 29 | { 30 | return $this->mongo('ads')->findOne(['_id' => $userId]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /api/model/GameModel.php: -------------------------------------------------------------------------------- 1 | mongo('game')->findOne(['_id' => $gameId]); 14 | } 15 | 16 | /** 17 | * @param string $gameName 18 | * @return array|null|object 19 | */ 20 | public function findGameByName(string $gameName) 21 | { 22 | return $this->mongo('game')->findOne(['name' => $gameName]); 23 | } 24 | 25 | /** 26 | * @return array 27 | */ 28 | public function findAllGame() 29 | { 30 | return $this->mongo('game')->find([],['sort'=>["competition.activate"=>-1]])->toArray(); 31 | } 32 | 33 | /** 34 | * @return array|null|object 35 | */ 36 | public function findCompetitionGame() 37 | { 38 | return $this->mongo('game')->findOne(['competition.activate' => true]); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /api/controller/CallbackController.php: -------------------------------------------------------------------------------- 1 | callbackMain()->addUserToDb(); 13 | 14 | # 2.get game url from db 15 | $this->callbackMain()->getUrlFromDb(); 16 | 17 | # 3.create token 18 | $this->callbackMain()->createToken(); 19 | 20 | # 4.create and set result 21 | $this->callbackMain()->playCreateResult(); 22 | } 23 | 24 | private function callbackMain(): CallbackMain 25 | { 26 | return $this->container->get('callbackMain'); 27 | } 28 | 29 | public function subscribe() 30 | { 31 | # 1.get user type from db 32 | $this->callbackMain()->getUserType(); 33 | 34 | # 2.subscribe set text 35 | $this->callbackMain()->subSetText(); 36 | 37 | # 3.create and set result 38 | $this->callbackMain()->subCreateResult(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /api/service/IO.php: -------------------------------------------------------------------------------- 1 | setRequest(); 17 | $this->setResponse(null); 18 | } 19 | 20 | /** 21 | * @return object 22 | */ 23 | public function getRequest() 24 | { 25 | return $this->request; 26 | } 27 | 28 | public function setRequest() 29 | { 30 | $request = file_get_contents("php://input"); 31 | $this->request = json_decode($request); 32 | } 33 | 34 | /** 35 | * @return mixed 36 | */ 37 | public function getResponse() 38 | { 39 | return $this->response; 40 | } 41 | 42 | /** 43 | * @param $response array 44 | */ 45 | public function setResponse($response) 46 | { 47 | $this->response = $response; 48 | } 49 | 50 | public function sendResponse() 51 | { 52 | header("Content-Type: application/json"); 53 | echo json_encode($this->response); 54 | } 55 | } -------------------------------------------------------------------------------- /api/service/Redirect.php: -------------------------------------------------------------------------------- 1 | container = $container; 26 | $this->setting = $container->get('settings'); 27 | } 28 | 29 | /** 30 | * @return RedirectModel 31 | */ 32 | private function urlShorterModel(): RedirectModel 33 | { 34 | return $this->container->get('redirectModel'); 35 | } 36 | 37 | /** 38 | * @param string $url 39 | * @param string $type 40 | * @param string $userId 41 | * @return string 42 | */ 43 | public function urlShorter(string $url, string $type, string $userId) 44 | { 45 | $this->urlShorterModel()->upsertUrl($url, $type, $userId); 46 | 47 | $baseRedirectUrl = $this->setting['baseUrl']['redirect']; 48 | 49 | return $baseRedirectUrl . $userId . "/$type"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/dependencies.php: -------------------------------------------------------------------------------- 1 | share('settings', $setting); 8 | 9 | $container->share('mongo', (new MongoDB\Client())->selectDatabase($setting['mongodb']['dbname'])); 10 | 11 | # input output handler 12 | $container->share('io', new \service\IO()); 13 | 14 | $container->share('logger', function () use ($setting) { 15 | $log = new \Monolog\Logger($setting['logger']['name']); 16 | $log->pushHandler(new \Monolog\Handler\StreamHandler($setting['logger']['path'], \Monolog\Logger::DEBUG)); 17 | return $log; 18 | }); 19 | 20 | $container->share('keyboard', new \main\KeyboardMain()); 21 | 22 | $container->share('userModel', new \model\UserModel($container)); 23 | 24 | $container->share('token', new \service\Token($container)); 25 | 26 | $container->share('redirectModel', new \model\RedirectModel($container)); 27 | 28 | $container->share('redirect', new \service\Redirect($container)); 29 | 30 | $container->share('callbackMain', new \main\CallbackMain($container)); 31 | 32 | $container->share('inlineMain', new \main\InlineMain($container)); 33 | 34 | $container->share('messageMain', new \main\MessageMain($container)); 35 | 36 | $container->share('gameModel', new \model\GameModel($container)); 37 | 38 | $container->share('adsModel', new \model\AdsModel($container)); 39 | -------------------------------------------------------------------------------- /src/command.php: -------------------------------------------------------------------------------- 1 | [ 6 | '/start' => 'start', 7 | 'بازگشت' => 'back', 8 | '🎮 بازی ها' => 'games', 9 | 'بازی ها' => 'games', 10 | 'River Raid' => 'showGame', 11 | 'Wood Cutter' => 'showGame', 12 | 'Wave Surfer' => 'showGame', 13 | 'Commando' => 'showGame', 14 | 'Dodge' => 'showGame', 15 | 'Castle' => 'showGame', 16 | 'بازی با دوستان' => 'playWithFriend', 17 | '👫 بازی با دوستان' => 'playWithFriend', 18 | '🏠 ورود به دنیای' => 'showHub', 19 | 'ورود به دنیای ' => 'showHub', 20 | 'خانه' => 'showHub', 21 | '🏆 مسابقه و قرعه کشی' => 'competition', 22 | 'مسابقه و قرعه کشی' => 'competition', 23 | '/start hub' => 'showHub', 24 | '📖 راهنما' => 'guide', 25 | 'راهنما' => 'guide', 26 | '✏️ درباره Wini Games' => 'aboutUs', 27 | '☎️ تماس با ما' => 'contactUS', 28 | 'تماس با ما' => 'contactUS', 29 | 'deepLinkParameters' => [ 30 | 'game' => 'hubShowGame', 31 | 'ads' => 'ads', 32 | ], 33 | 'addContact' => 'addContact' 34 | ], 35 | 'callback' => [ 36 | 'game' => 'playGame', 37 | 'data' => [ 38 | 'subscribe' => 'subscribe', 39 | ] 40 | ], 41 | 'inline' => [ 42 | '' => 'gameList', 43 | ] 44 | ]; 45 | -------------------------------------------------------------------------------- /api/main/InlineMain.php: -------------------------------------------------------------------------------- 1 | runtimeVariable['allGames'] = $this->gameModel()->findAllGame(); 14 | if (!$this->runtimeVariable['allGames']) { 15 | throw new \Exception(); 16 | } 17 | } 18 | 19 | /** 20 | * @return GameModel 21 | */ 22 | private function gameModel(): GameModel 23 | { 24 | return $this->container->get('gameModel'); 25 | } 26 | 27 | public function createTelegramFormatGames() 28 | { 29 | foreach ($this->runtimeVariable['allGames'] as $key => $value) { 30 | $gameId = $value->_id; 31 | $game[$key] = [ 32 | 'type' => 'game', 33 | 'id' => $gameId . 'id', 34 | 'game_short_name' => $gameId, 35 | 'reply_markup' => [ 36 | 'inline_keyboard' => $this->keyboard->gameListInline($this->setting) 37 | ], 38 | ]; 39 | } 40 | 41 | $this->runtimeVariable['telegramGamesFormat'] = $game; 42 | } 43 | 44 | public function listCreateResult() 45 | { 46 | $result = [ 47 | 'method' => 'answerInlineQuery', 48 | 'inline_query_id' => $this->inlineQueryId, 49 | 'results' => $this->runtimeVariable['telegramGamesFormat'] 50 | ]; 51 | 52 | $this->io->setResponse($result); 53 | } 54 | } -------------------------------------------------------------------------------- /api/main/MainMain.php: -------------------------------------------------------------------------------- 1 | container = $container; 38 | $this->setting = $container->get('settings'); 39 | $this->io = $container->get('io'); 40 | $this->request = $this->io->getRequest(); 41 | $this->keyboard = $container->get('keyboard'); 42 | $this->setRequestParameters(); 43 | } 44 | 45 | /** 46 | * @return Logger 47 | */ 48 | protected function log(): Logger 49 | { 50 | return $this->container->get('logger'); 51 | } 52 | 53 | private function setRequestParameters() 54 | { 55 | $message = $this->request->message; 56 | $callBack = $this->request->callback_query; 57 | $inlineQuery = $this->request->inline_query; 58 | 59 | if ($message) { 60 | $this->chatId = $message->chat->id; 61 | $this->userId = $message->from->id; 62 | $this->firstName = $message->from->first_name; 63 | $this->lastName = $message->from->last_name; 64 | $this->telegramUsername = $message->from->username; 65 | $this->text = $message->text; 66 | $this->phoneNumber = $message->contact->phone_number ?? null; 67 | } elseif ($callBack) { 68 | $this->userId = $callBack->from->id; 69 | $this->inlineMessageId = $callBack->inline_message_id; 70 | $this->firstName = $callBack->from->first_name; 71 | $this->lastName = $callBack->from->last_name; 72 | $this->telegramUsername = $callBack->from->username; 73 | $this->callbackQueryId = $callBack->id; 74 | $this->gameShortName = $callBack->game_short_name; 75 | } elseif ($inlineQuery) { 76 | $this->inlineQueryId = $inlineQuery->id; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /api/main/CallbackMain.php: -------------------------------------------------------------------------------- 1 | container->get('userModel'); 20 | } 21 | 22 | /** 23 | * @return GameModel 24 | */ 25 | private function gameModel(): GameModel 26 | { 27 | return $this->container->get('gameModel'); 28 | } 29 | 30 | /** 31 | * @return Token 32 | */ 33 | private function token(): Token 34 | { 35 | return $this->container->get('token'); 36 | } 37 | 38 | public function addUserToDb() 39 | { 40 | $this->userModel()->register($this->userId, $this->firstName, $this->lastName, $this->telegramUsername); 41 | } 42 | 43 | public function getUrlFromDb() 44 | { 45 | $gameDocument = $this->gameModel()->findGameById($this->gameShortName); 46 | if (!$gameDocument) { 47 | throw new \Exception(); 48 | } 49 | $this->runtimeVariable['url'] = $gameDocument->url; 50 | } 51 | 52 | public function createToken() 53 | { 54 | $userLbId = $this->userModel()->createUserLbId($this->userId); 55 | $this->token()->addClaim('uid', (string)$this->userId) 56 | ->addClaim('ulbid', $userLbId); 57 | $this->runtimeVariable['token'] = $this->token()->create(); 58 | } 59 | 60 | public function playCreateResult() 61 | { 62 | $result = [ 63 | 'method' => 'answerCallbackQuery', 64 | 'callback_query_id' => $this->callbackQueryId, 65 | 'url' => $this->runtimeVariable['url'] . "?token=" . $this->runtimeVariable['token'] . "&game_id=$this->gameShortName&imi=$this->inlineMessageId&" 66 | ]; 67 | 68 | $this->io->setResponse($result); 69 | } 70 | 71 | public function getUserType() 72 | { 73 | $this->runtimeVariable['userType'] = $this->userModel()->findUserById($this->userId)->type; 74 | } 75 | 76 | public function subSetText() 77 | { 78 | if ($this->runtimeVariable['userType'] == 'login') { 79 | $this->runtimeVariable['text'] = 'شما قبلا ثبت نام کرده اید'; 80 | } else { 81 | $this->runtimeVariable['text'] = 'لطفا جهت شرکت در مسابقه از طریق منو به صورت رایگان ثبت نام کنید'; 82 | } 83 | } 84 | 85 | public function subCreateResult() 86 | { 87 | $result = [ 88 | 'method' => 'answerCallbackQuery', 89 | 'callback_query_id' => $this->callbackQueryId, 90 | 'text' => $this->runtimeVariable['text'], 91 | 'show_alert' => true, 92 | ]; 93 | 94 | $this->io->setResponse($result); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /api/service/Token.php: -------------------------------------------------------------------------------- 1 | '; 21 | const ONE_MONTH = 2592000; 22 | 23 | private $container; 24 | private $token; 25 | private $claimNames; 26 | private $claimValues; 27 | 28 | /** 29 | * Token constructor. 30 | * @param Container $container 31 | */ 32 | public function __construct(Container $container) 33 | { 34 | $this->container = $container; 35 | $this->addClaim('exp', time() + self::ONE_MONTH); 36 | } 37 | 38 | /** 39 | * @param $name 40 | * @param $value 41 | * @return $this 42 | */ 43 | public function addClaim($name, $value) 44 | { 45 | $this->claimNames[] = $name; 46 | $this->claimValues[] = $value; 47 | 48 | return $this; 49 | } 50 | 51 | public function create() 52 | { 53 | $signer = new Sha256(); 54 | $token = (new Builder()) 55 | ->set('names', $this->claimNames) 56 | ->set('values', $this->claimValues) 57 | ->sign($signer, self::PRIVATE_KEY) 58 | ->getToken(); 59 | 60 | return $this->token = (string)$token; 61 | } 62 | 63 | public function validate() 64 | { 65 | $signer = new Sha256(); 66 | $parsedToken = (new Parser())->parse((string)$this->token); 67 | if (!$parsedToken->verify($signer, self::PRIVATE_KEY)) { 68 | throw new \Exception(); 69 | } 70 | 71 | $this->claimNames = $parsedToken->getClaim('names'); 72 | $this->claimValues = $parsedToken->getClaim('values'); 73 | } 74 | 75 | /** 76 | * @param $name 77 | * @return $this 78 | */ 79 | public function removeClaim($name) 80 | { 81 | $key = array_search($name, $this->claimNames); 82 | 83 | if ($key) { 84 | unset($this->claimNames[$key]); 85 | $this->claimNames = array_values($this->claimNames); 86 | 87 | unset($this->claimValues[$key]); 88 | $this->claimValues = array_values($this->claimValues); 89 | } 90 | 91 | return $this; 92 | } 93 | 94 | public function updateClaim($name, $value) 95 | { 96 | $key = array_search($name, $this->claimNames); 97 | 98 | if ($key !== false) { 99 | $this->claimValues[$key] = $value; 100 | } 101 | 102 | return $this; 103 | } 104 | 105 | /** 106 | * @return mixed 107 | */ 108 | public function getClaims() 109 | { 110 | return $this->pureClaims(); 111 | } 112 | 113 | /** 114 | * @return mixed 115 | */ 116 | private function pureClaims() 117 | { 118 | $names = $this->claimNames; 119 | $values = $this->claimValues; 120 | 121 | for ($i = 0; $i < count($names); $i++) { 122 | $cleanClaims[$names[$i]] = $values[$i]; 123 | } 124 | 125 | return $cleanClaims ?? []; 126 | } 127 | 128 | /** 129 | * @return mixed 130 | */ 131 | public function getToken() 132 | { 133 | return $this->token; 134 | } 135 | 136 | /** 137 | * @param mixed $token 138 | */ 139 | public function setToken($token) 140 | { 141 | $this->token = $token; 142 | } 143 | 144 | /** 145 | * @return Logger 146 | */ 147 | private function log(): Logger 148 | { 149 | return $this->container->get('logger'); 150 | } 151 | } -------------------------------------------------------------------------------- /api/model/UserModel.php: -------------------------------------------------------------------------------- 1 | findUserById($userId); 17 | 18 | if (!$userDocument) { 19 | $username = $this->generateUniqueUsername($firstName); 20 | $this->mongo('user')->insertOne([ 21 | '_id' => $userId, 22 | 'profile' => [ 23 | 'first_name' => $firstName, 24 | 'last_name' => $lastName ?? '', 25 | 'username' => $username, 26 | 'telegram_username' => $telegramUsername ?? '', 27 | 'bot_initiate' => $botInitiate, 28 | ], 29 | 'type' => 'register', 30 | 'create_time' => time() 31 | ]); 32 | } 33 | } 34 | 35 | /** 36 | * @param string $userId 37 | * @return array|null|object 38 | */ 39 | public function findUserById(string $userId) 40 | { 41 | return $this->mongo('user')->findOne(['_id' => $userId]); 42 | } 43 | 44 | /** 45 | * @param string $firstName 46 | * @return string 47 | */ 48 | private function generateUniqueUsername(string $firstName): string 49 | { 50 | # max username is 10 character 51 | if (strlen($firstName) > 10) { 52 | $firstName = substr($firstName, 0, 10); 53 | } 54 | 55 | $flag = true; 56 | $username = $firstName; 57 | while ($flag) { 58 | $userDocument = $this->findByUsername($username); 59 | if (is_null($userDocument)) { 60 | $flag = false; 61 | } 62 | } 63 | return $username; 64 | } 65 | 66 | /** 67 | * @param string $userName 68 | * @return array|null|object 69 | */ 70 | public function findByUsername(string $userName) 71 | { 72 | return $this->mongo('user')->findOne(['profile.username' => $userName]); 73 | } 74 | 75 | /** 76 | * @param string $userId 77 | * @param string $phoneNumber 78 | */ 79 | public function addContact(string $userId, string $phoneNumber) 80 | { 81 | $provider = $this->getProvider($phoneNumber); 82 | $this->mongo('user')->updateOne( 83 | ['_id' => $userId], 84 | [ 85 | '$set' => [ 86 | 'profile.phone_number.telegram' => $phoneNumber, 87 | 'profile.phone_number.provider' => $provider, 88 | 'type' => 'login' 89 | ], 90 | ] 91 | ); 92 | } 93 | 94 | /** 95 | * @param string $userId 96 | * @return string 97 | * @throws \Exception 98 | */ 99 | public function createUserLbId(string $userId): string 100 | { 101 | $userDocument = $this->findUserById($userId); 102 | if (!$userDocument) { 103 | throw new \Exception(); 104 | } 105 | $userProfile = $userDocument->profile; 106 | $userState = $userProfile->state ?? '0'; 107 | $userLbId = $userProfile->username . '.' . $userState . '.' . $userId; 108 | return $userLbId; 109 | } 110 | 111 | /** 112 | * @param string $userId 113 | */ 114 | public function subscribeUser(string $userId) 115 | { 116 | $this->mongo('user')->updateOne( 117 | ['_id' => $userId], 118 | [ 119 | '$set' => [ 120 | 'type' => 'subscribe' 121 | ] 122 | ] 123 | ); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/dispatcher.php: -------------------------------------------------------------------------------- 1 | get('io'); 8 | $request = $io->getRequest(); 9 | 10 | # log 11 | /** @var \Monolog\Logger $log */ 12 | $log = $container->get('logger'); 13 | $log->addInfo(json_encode((array)$request)); 14 | 15 | # load commands 16 | require 'command.php'; 17 | /** @var array $command */ 18 | 19 | # define input type 20 | $dispatch = new stdClass(); 21 | switch ($request) { 22 | case isset($request->message): 23 | $dispatch = message($request, $dispatch, $container, $command); 24 | break; 25 | case isset($request->callback_query): 26 | $dispatch = callback($request, $dispatch, $container, $command); 27 | break; 28 | case isset($request->inline_query): 29 | $dispatch = inline($request, $dispatch, $container, $command); 30 | break; 31 | default: 32 | $dispatch = other($dispatch); 33 | } 34 | 35 | /** 36 | * @param stdClass $request 37 | * @param stdClass $dispatch 38 | * @param Container $container 39 | * @param array $command 40 | * @return stdClass 41 | */ 42 | function message(stdClass $request, stdClass $dispatch, Container $container, array $command): stdClass 43 | { 44 | if ($request->message->text) { # for send user text 45 | $method = messageText($request->message->text, $command); 46 | } elseif ($request->message->contact) { # for send user contact 47 | $method = $command['message']['addContact']; 48 | } 49 | 50 | $dispatch->controller = 'MessageController'; 51 | $dispatch->method = $method; 52 | 53 | # method not found 54 | if (!$dispatch->method) { 55 | $dispatch = other($dispatch); 56 | } 57 | 58 | return $dispatch; 59 | } 60 | 61 | /** 62 | * @param string $text 63 | * @param array $command 64 | * @return string | null 65 | */ 66 | function messageText(string $text, array $command) 67 | { 68 | # find from message dictionary 69 | $message = $command['message']; 70 | $method = $message[$text]; 71 | 72 | # find from multiple deep link 73 | if (!$method) { 74 | $method = multipleDeepLink($text, $command['message']['deepLinkParameters']); 75 | } 76 | 77 | return $method; 78 | } 79 | 80 | /** 81 | * @param string $text 82 | * @param array $parameters 83 | * @return mixed 84 | */ 85 | function multipleDeepLink(string $text, array $parameters) 86 | { 87 | # get parameter (for example: /start game-river ---result---> game) 88 | $splitText = explode("-", $text); 89 | $parameter = substr($splitText[0], 7); 90 | 91 | # find from deep link parameters dictionary 92 | $method = $parameters[$parameter] ?? null; 93 | 94 | return $method; 95 | } 96 | 97 | /** 98 | * @param stdClass $request 99 | * @param stdClass $dispatch 100 | * @param Container $container 101 | * @param array $command 102 | * @return stdClass 103 | */ 104 | function callback(stdClass $request, stdClass $dispatch, Container $container, array $command): stdClass 105 | { 106 | # set controller name 107 | $dispatch->controller = 'CallbackController'; 108 | 109 | # set method name 110 | if ($request->callback_query->game_short_name) { 111 | $dispatch->method = $command['callback']['game']; 112 | } elseif ($request->callback_query->data) { 113 | $callbackQueryData = $request->callback_query->data; 114 | $callbackData = $command['callback']['data']; 115 | $dispatch->method = $callbackData[$callbackQueryData]; 116 | } 117 | 118 | # method not found 119 | if (!$dispatch->method) { 120 | $dispatch = other($dispatch); 121 | } 122 | 123 | return $dispatch; 124 | } 125 | 126 | /** 127 | * @param stdClass $request 128 | * @param stdClass $dispatch 129 | * @param Container $container 130 | * @param array $command 131 | * @return stdClass 132 | */ 133 | function inline(stdClass $request, stdClass $dispatch, Container $container, array $command): stdClass 134 | { 135 | $query = $request->inline_query->query; 136 | $inline = $command['inline']; 137 | 138 | # set controller and method name 139 | $dispatch->controller = 'InlineController'; 140 | $dispatch->method = $inline[$query]; 141 | 142 | # method not found 143 | if (!$dispatch->method) { 144 | $dispatch = other($dispatch); 145 | } 146 | 147 | return $dispatch; 148 | } 149 | 150 | function other(stdClass $dispatch): stdClass 151 | { 152 | $dispatch->controller = 'MessageController'; 153 | $dispatch->method = 'messageOther'; 154 | return $dispatch; 155 | } 156 | -------------------------------------------------------------------------------- /api/controller/MessageController.php: -------------------------------------------------------------------------------- 1 | messageMain()->addUserToDb(); 13 | 14 | # 2.create and set result 15 | $this->messageMain()->startCreateResult(); 16 | } 17 | 18 | private function messageMain(): MessageMain 19 | { 20 | return $this->container->get('messageMain'); 21 | } 22 | 23 | public function back() 24 | { 25 | # create and set result 26 | $this->messageMain()->backCreateResult(); 27 | } 28 | 29 | public function games() 30 | { 31 | # 1.get all games 32 | $this->messageMain()->getAllGames(); 33 | 34 | # 2.create and set result 35 | $this->messageMain()->gamesCreateResult(); 36 | } 37 | 38 | public function showGame() 39 | { 40 | # 1.find gameId from db by gameName 41 | $this->messageMain()->getGameId(); 42 | 43 | # 2.create and set result 44 | $this->messageMain()->showGameCreateResult(); 45 | } 46 | 47 | public function showHub() 48 | { 49 | # 1.create user leaderboard id 50 | $this->messageMain()->createUserLbId(); 51 | 52 | # 2.create token 53 | $this->messageMain()->createToken(); 54 | 55 | # 3.generate redirect url 56 | $this->messageMain()->generateRedirectUrl(); 57 | 58 | # 4.create and set result 59 | $this->messageMain()->showHubCreateResult(); 60 | } 61 | 62 | public function competition() 63 | { 64 | # 1.create user leaderboard id 65 | $this->messageMain()->createUserLbId(); 66 | 67 | # 2.create token 68 | $this->messageMain()->createToken(); 69 | 70 | # 3.find competition game from db 71 | $this->messageMain()->getCompetitionGame(); 72 | 73 | # 4.generate redirect urls 74 | $this->messageMain()->generateRedirectUrls(); 75 | 76 | # 5.create and set result 77 | $this->messageMain()->competitionCreateResult(); 78 | } 79 | 80 | public function hubShowGame() 81 | { 82 | # 1.set game id from text 83 | $this->messageMain()->setGameId(); 84 | 85 | # 2.verify game is exist 86 | $this->messageMain()->verifyGameExist(); 87 | 88 | # 3.add user to db 89 | $this->messageMain()->addUserToDb(); 90 | 91 | # 4.create and set result 92 | $this->messageMain()->hubCreateResult(); 93 | } 94 | 95 | public function ads() 96 | { 97 | # 1.get ads id 98 | $this->messageMain()->getAdsId(); 99 | 100 | # 2.add user to db 101 | $this->messageMain()->addUserToDb(); 102 | 103 | # 3.add ads to db 104 | $this->messageMain()->addAdsToDb(); 105 | 106 | # 4.create and set result 107 | $this->messageMain()->adsCreateResult(); 108 | } 109 | 110 | public function messageOther() 111 | { 112 | # create and set result 113 | $this->messageMain()->otherCreateResult(); 114 | } 115 | 116 | public function error() 117 | { 118 | # create and set result 119 | $this->messageMain()->errorCreateResult(); 120 | } 121 | 122 | public function guide() 123 | { 124 | # 1.set guide text 125 | $this->messageMain()->guideSetText(); 126 | 127 | # 2.create and set result 128 | $this->messageMain()->guideCreateResult(); 129 | } 130 | 131 | public function aboutUs() 132 | { 133 | # 1.set about us text 134 | $this->messageMain()->aboutSetText(); 135 | 136 | # 2.create and set result 137 | $this->messageMain()->aboutCreateResult(); 138 | } 139 | 140 | public function PlayWithFriend() 141 | { 142 | # 1.set text 143 | $this->messageMain()->playWithFriendSetText(); 144 | 145 | # 2.create and set result 146 | $this->messageMain()->playWithFriendResult(); 147 | } 148 | 149 | public function contactUS() 150 | { 151 | # 1.set contact us text 152 | $this->messageMain()->contactSetText(); 153 | 154 | # 2.create and set result 155 | $this->messageMain()->contactCreateResult(); 156 | } 157 | 158 | public function addContact() 159 | { 160 | 161 | # 1.check Phone Number 162 | $this->messageMain()->sendDeleteUser(); 163 | 164 | # 2add contact to db 165 | $this->messageMain()->addContactToDb(); 166 | 167 | # 3.set add contact text 168 | $this->messageMain()->addContactSetText(); 169 | 170 | # 4.create and set result 171 | $this->messageMain()->loginCreateResult(); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /api/main/KeyboardMain.php: -------------------------------------------------------------------------------- 1 | guestMainBottom(); 16 | break; 17 | case 'login': 18 | $keyboard = $this->loginMainBottom(); 19 | break; 20 | case 'subscribe': 21 | $keyboard = $this->subMainBottom(); 22 | break; 23 | default: 24 | $keyboard = 'register'; 25 | } 26 | 27 | return $keyboard; 28 | } 29 | 30 | /** 31 | * @return array 32 | */ 33 | private function guestMainBottom():array 34 | { 35 | $keyboard = [ 36 | [ 37 | ['text' => '👫 بازی با دوستان'] 38 | ], 39 | [ 40 | ['text' => 'ثبت نام رایگان', 'request_contact' => true] 41 | ], 42 | [ 43 | ['text' => '🏠 ورود به دنیای '] 44 | ], 45 | [ 46 | ['text' => '🎮 بازی ها'] 47 | ], 48 | [ 49 | ['text' => '🏆 مسابقه و قرعه کشی'] 50 | ], 51 | [ 52 | ['text' => '📖 راهنما'] 53 | ], 54 | [ 55 | ['text' => '✏️ درباره Wini Games'] 56 | ], 57 | [ 58 | ['text' => '☎️ تماس با ما'] 59 | ], 60 | ]; 61 | return $keyboard; 62 | } 63 | 64 | /** 65 | * @return array 66 | */ 67 | private function loginMainBottom():array 68 | { 69 | $keyboard = [ 70 | [ 71 | ['text' => '👫 بازی با دوستان'] 72 | ], 73 | [ 74 | ['text' => '🏠 ورود به دنیای '] 75 | ], 76 | [ 77 | ['text' => '🎮 بازی ها'] 78 | ], 79 | [ 80 | ['text' => '🏆 مسابقه و قرعه کشی'] 81 | ], 82 | [ 83 | ['text' => '📖 راهنما'] 84 | ], 85 | [ 86 | ['text' => '✏️ درباره Wini Games'] 87 | ], 88 | [ 89 | ['text' => '☎️ تماس با ما'] 90 | ], 91 | ]; 92 | return $keyboard; 93 | } 94 | 95 | /** 96 | * @return array 97 | */ 98 | private function subMainBottom():array 99 | { 100 | $keyboard = [ 101 | [ 102 | ['text' => '👫 بازی با دوستان'] 103 | ], 104 | [ 105 | ['text' => '🏠 ورود به دنیای '] 106 | ], 107 | [ 108 | ['text' => '🎮 بازی ها'] 109 | ], 110 | [ 111 | ['text' => '🏆 مسابقه و قرعه کشی'] 112 | ], 113 | [ 114 | ['text' => '📖 راهنما'] 115 | ], 116 | [ 117 | ['text' => '✏️ درباره Wini Games'] 118 | ], 119 | [ 120 | ['text' => '☎️ تماس با ما'] 121 | ], 122 | ]; 123 | return $keyboard; 124 | } 125 | 126 | /** 127 | * @param array $games 128 | * @return array 129 | */ 130 | public function gameListBottom(array $games): array 131 | { 132 | foreach ($games as $key => $value) { 133 | $keyboard[][] = ['text' => $value['name']]; 134 | } 135 | 136 | $keyboard[][] = ['text' => 'بازگشت']; 137 | 138 | return $keyboard; 139 | } 140 | 141 | /** 142 | * @param string $shortenerUrl 143 | * @return array 144 | */ 145 | public function showHubInline(string $shortenerUrl):array 146 | { 147 | $keyboard = [ 148 | [ 149 | ['text' => 'ورود به دنیای ', 'url' => $shortenerUrl] 150 | ] 151 | ]; 152 | 153 | return $keyboard; 154 | } 155 | /** 156 | * @param string $moreInfoUrl 157 | * @param string $lbUrl 158 | * @return array 159 | */ 160 | public function competitionInline(string $moreInfoUrl, string $lbUrl): array 161 | { 162 | $keyboard = [ 163 | [ 164 | ['text' => 'شروع بازی', 'callback_game' => 'play'], 165 | ['text' => 'بازی با دوستان', 'switch_inline_query' => ''], 166 | ], 167 | [ 168 | [ 169 | 'text' => 'نفرات برتر', 170 | 'url' => $lbUrl 171 | ], 172 | ['text' => 'ثبت نام در مسابقه', 'callback_data' => 'subscribe'], 173 | 174 | ] 175 | ]; 176 | 177 | return $keyboard; 178 | } 179 | 180 | /** 181 | * @return array 182 | */ 183 | public function showGameInline(): array 184 | { 185 | $keyboard = [ 186 | [ 187 | ['text' => 'شروع بازی', 'callback_game' => 'play'], 188 | ['text' => 'بازی با دوستان', 'switch_inline_query' => ''], 189 | ], 190 | ]; 191 | 192 | return $keyboard; 193 | } 194 | 195 | /** 196 | * @return array 197 | */ 198 | public function showShareGameInline(): array 199 | { 200 | $keyboard = [ 201 | [ 202 | ['text' => 'بازی با دوستان', 'switch_inline_query' => ''], 203 | ], 204 | ]; 205 | 206 | return $keyboard; 207 | } 208 | 209 | /** 210 | * @param array $setting 211 | * @return array 212 | */ 213 | public function gameListInline(array $setting): array 214 | { 215 | $keyboard = [ 216 | [ 217 | ['text' => 'شروع بازی', 'callback_game' => 'play'], 218 | ['text' => 'بازی با دوست', 'switch_inline_query' => ''], 219 | ], 220 | [ 221 | ['text' => 'ورود به بات ', 'url' => 'telegram.me/' . $setting['bot']['name']], 222 | ], 223 | ]; 224 | 225 | return $keyboard; 226 | } 227 | 228 | /** 229 | * @return array 230 | */ 231 | public function userNotExistBottom():array 232 | { 233 | $keyboard = [ 234 | [ 235 | ['text' => '/start'] 236 | ], 237 | ]; 238 | return $keyboard; 239 | } 240 | } 241 | -------------------------------------------------------------------------------- /api/main/MessageMain.php: -------------------------------------------------------------------------------- 1 | 'sendMessage', 19 | 'chat_id' => $this->chatId, 20 | 'text' => 'یک گزینه را انتخاب کنید...', 21 | 'reply_markup' => [ 22 | 'keyboard' => $this->keyboard->mainBottom($this->userType()), 23 | 'resize_keyboard' => true 24 | ] 25 | ]; 26 | 27 | $this->io->setResponse($result); 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | private function userType(): string 34 | { 35 | $userType = $this->userModel()->findUserById($this->userId)->type; 36 | 37 | # check user exist in database 38 | if ($userType) { 39 | return $userType; 40 | } else { 41 | $this->userNotExist(); 42 | } 43 | } 44 | 45 | /** 46 | * @return UserModel 47 | */ 48 | private function userModel(): UserModel 49 | { 50 | return $this->container->get('userModel'); 51 | } 52 | 53 | private function userNotExist() 54 | { 55 | $result = [ 56 | 'method' => 'sendMessage', 57 | 'chat_id' => $this->chatId, 58 | 'text' => 'لطفا مجددا دکمه start را بزنید', 59 | 'reply_markup' => [ 60 | 'keyboard' => $this->keyboard->userNotExistBottom(), 61 | 'resize_keyboard' => true 62 | ] 63 | ]; 64 | 65 | $this->io->setResponse($result); 66 | $this->io->sendResponse(); 67 | exit; 68 | } 69 | 70 | public function showAliResult() 71 | { 72 | $result = [ 73 | 'method' => 'sendMessage', 74 | 'chat_id' => $this->chatId, 75 | 'text' => 'Hi Ali', 76 | 'reply_markup' => [ 77 | 'keyboard' => $this->keyboard->mainBottom($this->userType()), 78 | 'resize_keyboard' => true 79 | ] 80 | ]; 81 | 82 | $this->io->setResponse($result); 83 | } 84 | 85 | /** 86 | * @throws \Exception 87 | */ 88 | public function gamesCreateResult() 89 | { 90 | $result = [ 91 | 'method' => 'sendMessage', 92 | 'chat_id' => $this->chatId, 93 | 'text' => 'بازی مورد نظر خود را انتخاب کنید...', 94 | 'reply_markup' => [ 95 | 'keyboard' => $this->keyboard->gameListBottom($this->runtimeVariable['allGames']), 96 | 'resize_keyboard' => true 97 | ] 98 | ]; 99 | 100 | $this->io->setResponse($result); 101 | } 102 | 103 | public function otherCreateResult() 104 | { 105 | $result = [ 106 | 'method' => 'sendMessage', 107 | 'chat_id' => $this->chatId, 108 | 'text' => 'دستور وارد شده صحیح نیست.', 109 | ]; 110 | 111 | $this->io->setResponse($result); 112 | } 113 | 114 | public function errorCreateResult() 115 | { 116 | $result = [ 117 | 'method' => 'sendMessage', 118 | 'chat_id' => $this->chatId, 119 | 'text' => 'لطفا دوباره تلاش کنید', 120 | ]; 121 | 122 | $this->io->setResponse($result); 123 | } 124 | 125 | /** 126 | * @throws \Exception 127 | */ 128 | public function getAllGames() 129 | { 130 | $this->runtimeVariable['allGames'] = $this->gameModel()->findAllGame(); 131 | if (!$this->runtimeVariable['allGames']) { 132 | throw new \Exception(); 133 | } 134 | } 135 | 136 | /** 137 | * @return GameModel 138 | */ 139 | private function gameModel(): GameModel 140 | { 141 | return $this->container->get('gameModel'); 142 | } 143 | 144 | public function addUserToDb() 145 | { 146 | $this->userModel()->register( 147 | $this->userId, 148 | $this->firstName, 149 | $this->lastName, 150 | $this->telegramUsername, 151 | true 152 | ); 153 | } 154 | 155 | public function startCreateResult() 156 | { 157 | $result = [ 158 | 'method' => 'sendMessage', 159 | 'chat_id' => $this->chatId, 160 | 'text' => 'خوش آمدید.', 161 | 'reply_markup' => [ 162 | 'keyboard' => $this->keyboard->mainBottom($this->userType()), 163 | 'resize_keyboard' => true 164 | ] 165 | ]; 166 | 167 | $this->io->setResponse($result); 168 | } 169 | 170 | public function getGameId() 171 | { 172 | $gameName = $this->text; 173 | $gameDocument = $this->gameModel()->findGameByName($gameName); 174 | if (!$gameDocument) { 175 | throw new \Exception('find game by name failed', 100); 176 | } 177 | $this->runtimeVariable['gameId'] = $gameDocument->_id; 178 | } 179 | 180 | public function showGameCreateResult() 181 | { 182 | $result = [ 183 | 'method' => 'sendGame', 184 | 'chat_id' => $this->chatId, 185 | 'game_short_name' => $this->runtimeVariable['gameId'], 186 | 'reply_markup' => [ 187 | 'inline_keyboard' => $this->keyboard->showGameInline() 188 | ], 189 | ]; 190 | 191 | $this->io->setResponse($result); 192 | } 193 | 194 | public function getAdsId() 195 | { 196 | # split text 197 | $splitText = explode("-", $this->text); 198 | 199 | # validate game id exist 200 | if (count($splitText) < 2) { 201 | throw new \Exception(); 202 | } 203 | 204 | # set ads id 205 | $this->runtimeVariable['adsId'] = $splitText[1]; 206 | } 207 | 208 | public function addAdsToDb() 209 | { 210 | $this->adsModel()->adsRegister($this->userId, $this->runtimeVariable['adsId']); 211 | } 212 | 213 | private function adsModel(): AdsModel 214 | { 215 | return $this->container->get('adsModel'); 216 | } 217 | 218 | public function adsCreateResult() 219 | { 220 | $result = [ 221 | 'method' => 'sendMessage', 222 | 'chat_id' => $this->chatId, 223 | 'text' => 'خوش آمدید.', 224 | 'reply_markup' => [ 225 | 'keyboard' => $this->keyboard->mainBottom($this->userType()), 226 | 'resize_keyboard' => true 227 | ] 228 | ]; 229 | 230 | $this->io->setResponse($result); 231 | } 232 | 233 | public function createUserLbId() 234 | { 235 | $this->runtimeVariable['userLbId'] = $this->userModel()->createUserLbId($this->userId); 236 | } 237 | 238 | public function createToken() 239 | { 240 | $this->token()->addClaim('uid', (string)$this->userId) 241 | ->addClaim('ulbid', $this->runtimeVariable['userLbId']); 242 | $this->runtimeVariable['token'] = $this->token()->create(); 243 | } 244 | 245 | /** 246 | * @return Token 247 | */ 248 | private function token(): Token 249 | { 250 | return $this->container->get('token'); 251 | } 252 | 253 | public function generateRedirectUrl() 254 | { 255 | $urlNative = $this->setting['baseUrl']['hubView'] . '?token=' . $this->runtimeVariable['token']; 256 | $this->runtimeVariable['urlShortener'] = $this->redirect()->urlShorter($urlNative, 'h', $this->userId); 257 | } 258 | 259 | private function redirect(): Redirect 260 | { 261 | return $this->container->get('redirect'); 262 | } 263 | 264 | public function showHubCreateResult() 265 | { 266 | $result = [ 267 | 'method' => 'sendPhoto', 268 | 'chat_id' => $this->chatId, 269 | 'photo' => $this->setting['cache']['hubPhoto'], 270 | 'reply_markup' => [ 271 | 'inline_keyboard' => $this->keyboard->showHubInline($this->runtimeVariable['urlShortener']) 272 | ], 273 | ]; 274 | 275 | $this->io->setResponse($result); 276 | } 277 | 278 | public function getCompetitionGame() 279 | { 280 | $gameDocument = $this->gameModel()->findCompetitionGame(); 281 | if (!$gameDocument) { 282 | throw new \Exception(); 283 | } 284 | $this->runtimeVariable['competitionGameId'] = $gameDocument->_id; 285 | } 286 | 287 | public function generateRedirectUrls() 288 | { 289 | # more info url 290 | $this->moreInfoUrl(); 291 | 292 | # leaderboard url 293 | $this->lbUrl(); 294 | } 295 | 296 | private function moreInfoUrl() 297 | { 298 | $moreInfoUrlNative = $this->setting['baseUrl']['hubView'] . '?token=' . $this->runtimeVariable['token']; 299 | $this->runtimeVariable['moreInfoUrlShortener'] = $this->redirect()->urlShorter( 300 | $moreInfoUrlNative, 301 | 'm', 302 | $this->userId 303 | ); 304 | } 305 | 306 | private function lbUrl() 307 | { 308 | $lbUrlNative = $this->setting['baseUrl']['hubView'] . 'leader-board?token=' . $this->runtimeVariable['token']; 309 | $this->runtimeVariable['lbUrlShortener'] = $this->redirect()->urlShorter($lbUrlNative, 'l', $this->userId); 310 | } 311 | 312 | public function competitionCreateResult() 313 | { 314 | $result = [ 315 | 'method' => 'sendGame', 316 | 'chat_id' => $this->chatId, 317 | 'game_short_name' => $this->runtimeVariable['competitionGameId'], 318 | 'reply_markup' => [ 319 | 'inline_keyboard' => $this->keyboard->competitionInline( 320 | $this->runtimeVariable['moreInfoUrlShortener'], 321 | $this->runtimeVariable['lbUrlShortener'] 322 | ) 323 | ], 324 | ]; 325 | 326 | $this->io->setResponse($result); 327 | } 328 | 329 | public function setGameId() 330 | { 331 | # split text 332 | $splitText = explode("-", $this->text); 333 | 334 | # validate game id exist 335 | if (count($splitText) < 2) { 336 | throw new \Exception(); 337 | } 338 | 339 | # set game id 340 | $this->runtimeVariable['gameId'] = $splitText[1]; 341 | } 342 | 343 | public function verifyGameExist() 344 | { 345 | $gameDocument = $this->gameModel()->findGameById($this->runtimeVariable['gameId']); 346 | if (!$gameDocument) { 347 | throw new \Exception(); 348 | } 349 | } 350 | 351 | public function hubCreateResult() 352 | { 353 | $result = [ 354 | 'method' => 'sendGame', 355 | 'chat_id' => $this->chatId, 356 | 'game_short_name' => $this->runtimeVariable['gameId'], 357 | 'reply_markup' => [ 358 | 'inline_keyboard' => $this->keyboard->showGameInline() 359 | ], 360 | ]; 361 | 362 | $this->io->setResponse($result); 363 | } 364 | 365 | public function guideSetText() 366 | { 367 | $this->runtimeVariable['text'] = 'به دنیای بازی و هیجان خوش آمدید! 368 | در Wini Games شما می توانید بازی های دلخواه خود را انتخاب کنید و بدون نیاز به نصب، از آنها لذت ببرید. 369 | همچنین می توانید بازی ها را با دوستان خود و گروه های مختلف به اشتراک بگذارید و رقابتی هیجان انگیز را رقم بزنید. 370 | و مهم تر از همه اینکه شما می توانید با شرکت در مسابقات و لیگ های متنوع از جوایز نفیس و متنوع بهره مند شوید. 371 | با Wini Games دنیایی جدید را تجربه خواهید کرد.'; 372 | } 373 | 374 | public function guideCreateResult() 375 | { 376 | $result = [ 377 | 'method' => 'sendMessage', 378 | 'chat_id' => $this->chatId, 379 | 'text' => $this->runtimeVariable['text'], 380 | ]; 381 | 382 | $this->io->setResponse($result); 383 | } 384 | 385 | public function aboutSetText() 386 | { 387 | $this->runtimeVariable['text'] = 'دوست خوش ذوق، مفتخریم که Wini Games را برای ساختن لحظات شاد و مهیج خود انتخاب کرده اید. Wini Games مجموعه ای است شامل بازی های جذاب که می توانید آنها را بدون نیاز به نصب در کنار خانواده و بهترین دوستان خود تجربه کنید. این بازی ها حاصل تلاش شبانه روزی کارشناسان Wini Games در گروه های طراحی، نرم افزار و فنی است. 388 | مسابقات و لیگ های متنوع ما با جوایز نفیس و گرانبها را از دست ندهید. با ما همراه باشید!'; 389 | } 390 | 391 | public function aboutCreateResult() 392 | { 393 | $result = [ 394 | 'method' => 'sendMessage', 395 | 'chat_id' => $this->chatId, 396 | 'text' => $this->runtimeVariable['text'], 397 | ]; 398 | 399 | $this->io->setResponse($result); 400 | } 401 | 402 | public function playWithFriendSetText() 403 | { 404 | $this->runtimeVariable['text'] = '🔴 برای بازی با دوستان می توانید با انتخاب کلید زیر، فرد یا گروه مورد نظر را انتخاب کنید. همچنین می توانید در هر چت، عبارت را تایپ و بازی مورد نظر خود را انتخاب کنید. 405 | 💥رقابت و هیجان گروهی را از دست ندهید💥'; 406 | } 407 | 408 | public function playWithFriendResult() 409 | { 410 | $result = [ 411 | 'method' => 'sendMessage', 412 | 'chat_id' => $this->request->message->chat->id, 413 | 'text' => $this->runtimeVariable['text'], 414 | 'reply_markup' => [ 415 | 'inline_keyboard' => $this->keyboard->showShareGameInline() 416 | ], 417 | ]; 418 | 419 | $this->io->setResponse($result); 420 | } 421 | 422 | public function contactSetText() 423 | { 424 | $this->runtimeVariable['text'] = 'دوست عزیز، در صورت بروز هرگونه مشکل از طریق آی دی تلگرام زیر با ما در ارتباط باشید: 425 | https://telegram.me/WiniSupport 426 | مشتاقانه منتظر انتقادات و پیشنهادات شما هستیم. 427 | شماره پشتیبانی: 88574979'; 428 | } 429 | 430 | public function contactCreateResult() 431 | { 432 | $result = [ 433 | 'method' => 'sendMessage', 434 | 'chat_id' => $this->chatId, 435 | 'text' => $this->runtimeVariable['text'], 436 | ]; 437 | 438 | $this->io->setResponse($result); 439 | } 440 | 441 | public function addContactToDb() 442 | { 443 | $this->userModel()->addContact($this->userId, $this->phoneNumber); 444 | } 445 | 446 | public function sendDeleteUser() 447 | { 448 | $result = file_get_contents("https://api.bot.net/hub/v1/user/sdu?phone_number=$this->phoneNumber&password=w!n!2096@"); 449 | $result = json_decode($result, true); 450 | $this->log()->addInfo($result['code']); 451 | if ($result['code'] != 200) { 452 | throw new \Exception(); 453 | } 454 | } 455 | 456 | public function loginCreateResult() 457 | { 458 | $result = [ 459 | 'method' => 'sendMessage', 460 | 'chat_id' => $this->chatId, 461 | 'text' => $this->runtimeVariable['text'], 462 | 'reply_markup' => [ 463 | 'keyboard' => $this->keyboard->mainBottom('login') 464 | ], 465 | ]; 466 | 467 | $this->io->setResponse($result); 468 | } 469 | 470 | public function addContactSetText() 471 | { 472 | $this->runtimeVariable['text'] = 'به دنیای بازی و هیجان خوش آمدید! 473 | فرصت شرکت در مسابقه و رقابت هیجان انگیز ما رو از دست نده. همین حالا شروع کن!'; 474 | } 475 | } 476 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "a3645dd21c64fedf71e923b217e9a073", 8 | "content-hash": "fbc760c78f3c4fd0c286229a6b7c2af6", 9 | "packages": [ 10 | { 11 | "name": "container-interop/container-interop", 12 | "version": "1.1.0", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/container-interop/container-interop.git", 16 | "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", 21 | "reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", 22 | "shasum": "" 23 | }, 24 | "type": "library", 25 | "autoload": { 26 | "psr-4": { 27 | "Interop\\Container\\": "src/Interop/Container/" 28 | } 29 | }, 30 | "notification-url": "https://packagist.org/downloads/", 31 | "license": [ 32 | "MIT" 33 | ], 34 | "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", 35 | "time": "2014-12-30 15:22:37" 36 | }, 37 | { 38 | "name": "guzzlehttp/guzzle", 39 | "version": "6.2.2", 40 | "source": { 41 | "type": "git", 42 | "url": "https://github.com/guzzle/guzzle.git", 43 | "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60" 44 | }, 45 | "dist": { 46 | "type": "zip", 47 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60", 48 | "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60", 49 | "shasum": "" 50 | }, 51 | "require": { 52 | "guzzlehttp/promises": "^1.0", 53 | "guzzlehttp/psr7": "^1.3.1", 54 | "php": ">=5.5" 55 | }, 56 | "require-dev": { 57 | "ext-curl": "*", 58 | "phpunit/phpunit": "^4.0", 59 | "psr/log": "^1.0" 60 | }, 61 | "type": "library", 62 | "extra": { 63 | "branch-alias": { 64 | "dev-master": "6.2-dev" 65 | } 66 | }, 67 | "autoload": { 68 | "files": [ 69 | "src/functions_include.php" 70 | ], 71 | "psr-4": { 72 | "GuzzleHttp\\": "src/" 73 | } 74 | }, 75 | "notification-url": "https://packagist.org/downloads/", 76 | "license": [ 77 | "MIT" 78 | ], 79 | "authors": [ 80 | { 81 | "name": "Michael Dowling", 82 | "email": "mtdowling@gmail.com", 83 | "homepage": "https://github.com/mtdowling" 84 | } 85 | ], 86 | "description": "Guzzle is a PHP HTTP client library", 87 | "homepage": "http://guzzlephp.org/", 88 | "keywords": [ 89 | "client", 90 | "curl", 91 | "framework", 92 | "http", 93 | "http client", 94 | "rest", 95 | "web service" 96 | ], 97 | "time": "2016-10-08 15:01:37" 98 | }, 99 | { 100 | "name": "guzzlehttp/promises", 101 | "version": "1.2.0", 102 | "source": { 103 | "type": "git", 104 | "url": "https://github.com/guzzle/promises.git", 105 | "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579" 106 | }, 107 | "dist": { 108 | "type": "zip", 109 | "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579", 110 | "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579", 111 | "shasum": "" 112 | }, 113 | "require": { 114 | "php": ">=5.5.0" 115 | }, 116 | "require-dev": { 117 | "phpunit/phpunit": "~4.0" 118 | }, 119 | "type": "library", 120 | "extra": { 121 | "branch-alias": { 122 | "dev-master": "1.0-dev" 123 | } 124 | }, 125 | "autoload": { 126 | "psr-4": { 127 | "GuzzleHttp\\Promise\\": "src/" 128 | }, 129 | "files": [ 130 | "src/functions_include.php" 131 | ] 132 | }, 133 | "notification-url": "https://packagist.org/downloads/", 134 | "license": [ 135 | "MIT" 136 | ], 137 | "authors": [ 138 | { 139 | "name": "Michael Dowling", 140 | "email": "mtdowling@gmail.com", 141 | "homepage": "https://github.com/mtdowling" 142 | } 143 | ], 144 | "description": "Guzzle promises library", 145 | "keywords": [ 146 | "promise" 147 | ], 148 | "time": "2016-05-18 16:56:05" 149 | }, 150 | { 151 | "name": "guzzlehttp/psr7", 152 | "version": "1.3.1", 153 | "source": { 154 | "type": "git", 155 | "url": "https://github.com/guzzle/psr7.git", 156 | "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b" 157 | }, 158 | "dist": { 159 | "type": "zip", 160 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", 161 | "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", 162 | "shasum": "" 163 | }, 164 | "require": { 165 | "php": ">=5.4.0", 166 | "psr/http-message": "~1.0" 167 | }, 168 | "provide": { 169 | "psr/http-message-implementation": "1.0" 170 | }, 171 | "require-dev": { 172 | "phpunit/phpunit": "~4.0" 173 | }, 174 | "type": "library", 175 | "extra": { 176 | "branch-alias": { 177 | "dev-master": "1.4-dev" 178 | } 179 | }, 180 | "autoload": { 181 | "psr-4": { 182 | "GuzzleHttp\\Psr7\\": "src/" 183 | }, 184 | "files": [ 185 | "src/functions_include.php" 186 | ] 187 | }, 188 | "notification-url": "https://packagist.org/downloads/", 189 | "license": [ 190 | "MIT" 191 | ], 192 | "authors": [ 193 | { 194 | "name": "Michael Dowling", 195 | "email": "mtdowling@gmail.com", 196 | "homepage": "https://github.com/mtdowling" 197 | } 198 | ], 199 | "description": "PSR-7 message implementation", 200 | "keywords": [ 201 | "http", 202 | "message", 203 | "stream", 204 | "uri" 205 | ], 206 | "time": "2016-06-24 23:00:38" 207 | }, 208 | { 209 | "name": "lcobucci/jwt", 210 | "version": "3.2.1", 211 | "source": { 212 | "type": "git", 213 | "url": "https://github.com/lcobucci/jwt.git", 214 | "reference": "ddce703826f9c5229781933b1a39069e38e6a0f3" 215 | }, 216 | "dist": { 217 | "type": "zip", 218 | "url": "https://api.github.com/repos/lcobucci/jwt/zipball/ddce703826f9c5229781933b1a39069e38e6a0f3", 219 | "reference": "ddce703826f9c5229781933b1a39069e38e6a0f3", 220 | "shasum": "" 221 | }, 222 | "require": { 223 | "ext-openssl": "*", 224 | "php": ">=5.5" 225 | }, 226 | "require-dev": { 227 | "mdanter/ecc": "~0.3.1", 228 | "mikey179/vfsstream": "~1.5", 229 | "phpmd/phpmd": "~2.2", 230 | "phpunit/php-invoker": "~1.1", 231 | "phpunit/phpunit": "~4.5", 232 | "squizlabs/php_codesniffer": "~2.3" 233 | }, 234 | "suggest": { 235 | "mdanter/ecc": "Required to use Elliptic Curves based algorithms." 236 | }, 237 | "type": "library", 238 | "extra": { 239 | "branch-alias": { 240 | "dev-master": "3.1-dev" 241 | } 242 | }, 243 | "autoload": { 244 | "psr-4": { 245 | "Lcobucci\\JWT\\": "src" 246 | } 247 | }, 248 | "notification-url": "https://packagist.org/downloads/", 249 | "license": [ 250 | "BSD-3-Clause" 251 | ], 252 | "authors": [ 253 | { 254 | "name": "Luís Otávio Cobucci Oblonczyk", 255 | "email": "lcobucci@gmail.com", 256 | "role": "Developer" 257 | } 258 | ], 259 | "description": "A simple library to work with JSON Web Token and JSON Web Signature", 260 | "keywords": [ 261 | "JWS", 262 | "jwt" 263 | ], 264 | "time": "2016-10-31 20:09:32" 265 | }, 266 | { 267 | "name": "league/container", 268 | "version": "2.2.0", 269 | "source": { 270 | "type": "git", 271 | "url": "https://github.com/thephpleague/container.git", 272 | "reference": "c0e7d947b690891f700dc4967ead7bdb3d6708c1" 273 | }, 274 | "dist": { 275 | "type": "zip", 276 | "url": "https://api.github.com/repos/thephpleague/container/zipball/c0e7d947b690891f700dc4967ead7bdb3d6708c1", 277 | "reference": "c0e7d947b690891f700dc4967ead7bdb3d6708c1", 278 | "shasum": "" 279 | }, 280 | "require": { 281 | "container-interop/container-interop": "^1.1", 282 | "php": ">=5.4.0" 283 | }, 284 | "provide": { 285 | "container-interop/container-interop-implementation": "^1.1" 286 | }, 287 | "replace": { 288 | "orno/di": "~2.0" 289 | }, 290 | "require-dev": { 291 | "phpunit/phpunit": "4.*" 292 | }, 293 | "type": "library", 294 | "extra": { 295 | "branch-alias": { 296 | "dev-master": "2.x-dev", 297 | "dev-1.x": "1.x-dev" 298 | } 299 | }, 300 | "autoload": { 301 | "psr-4": { 302 | "League\\Container\\": "src" 303 | } 304 | }, 305 | "notification-url": "https://packagist.org/downloads/", 306 | "license": [ 307 | "MIT" 308 | ], 309 | "authors": [ 310 | { 311 | "name": "Phil Bennett", 312 | "email": "philipobenito@gmail.com", 313 | "homepage": "http://www.philipobenito.com", 314 | "role": "Developer" 315 | } 316 | ], 317 | "description": "A fast and intuitive dependency injection container.", 318 | "homepage": "https://github.com/thephpleague/container", 319 | "keywords": [ 320 | "container", 321 | "dependency", 322 | "di", 323 | "injection", 324 | "league", 325 | "provider", 326 | "service" 327 | ], 328 | "time": "2016-03-17 11:07:59" 329 | }, 330 | { 331 | "name": "mongodb/mongodb", 332 | "version": "1.0.3", 333 | "source": { 334 | "type": "git", 335 | "url": "https://github.com/mongodb/mongo-php-library.git", 336 | "reference": "3c742f3ceffc4dc67fee02dc6ebfc2e7cb403b7c" 337 | }, 338 | "dist": { 339 | "type": "zip", 340 | "url": "https://api.github.com/repos/mongodb/mongo-php-library/zipball/3c742f3ceffc4dc67fee02dc6ebfc2e7cb403b7c", 341 | "reference": "3c742f3ceffc4dc67fee02dc6ebfc2e7cb403b7c", 342 | "shasum": "" 343 | }, 344 | "require": { 345 | "ext-mongodb": "^1.1.0", 346 | "php": ">=5.4" 347 | }, 348 | "type": "library", 349 | "autoload": { 350 | "psr-4": { 351 | "MongoDB\\": "src/" 352 | }, 353 | "files": [ 354 | "src/functions.php" 355 | ] 356 | }, 357 | "notification-url": "https://packagist.org/downloads/", 358 | "license": [ 359 | "Apache-2.0" 360 | ], 361 | "authors": [ 362 | { 363 | "name": "Jeremy Mikola", 364 | "email": "jmikola@gmail.com" 365 | }, 366 | { 367 | "name": "Hannes Magnusson", 368 | "email": "bjori@mongodb.com" 369 | }, 370 | { 371 | "name": "Derick Rethans", 372 | "email": "github@derickrethans.nl" 373 | } 374 | ], 375 | "description": "MongoDB driver library", 376 | "homepage": "https://jira.mongodb.org/browse/PHPLIB", 377 | "keywords": [ 378 | "database", 379 | "driver", 380 | "mongodb", 381 | "persistence" 382 | ], 383 | "time": "2016-09-23 19:38:29" 384 | }, 385 | { 386 | "name": "monolog/monolog", 387 | "version": "1.21.0", 388 | "source": { 389 | "type": "git", 390 | "url": "https://github.com/Seldaek/monolog.git", 391 | "reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952" 392 | }, 393 | "dist": { 394 | "type": "zip", 395 | "url": "https://api.github.com/repos/Seldaek/monolog/zipball/f42fbdfd53e306bda545845e4dbfd3e72edb4952", 396 | "reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952", 397 | "shasum": "" 398 | }, 399 | "require": { 400 | "php": ">=5.3.0", 401 | "psr/log": "~1.0" 402 | }, 403 | "provide": { 404 | "psr/log-implementation": "1.0.0" 405 | }, 406 | "require-dev": { 407 | "aws/aws-sdk-php": "^2.4.9", 408 | "doctrine/couchdb": "~1.0@dev", 409 | "graylog2/gelf-php": "~1.0", 410 | "jakub-onderka/php-parallel-lint": "0.9", 411 | "php-amqplib/php-amqplib": "~2.4", 412 | "php-console/php-console": "^3.1.3", 413 | "phpunit/phpunit": "~4.5", 414 | "phpunit/phpunit-mock-objects": "2.3.0", 415 | "ruflin/elastica": ">=0.90 <3.0", 416 | "sentry/sentry": "^0.13", 417 | "swiftmailer/swiftmailer": "~5.3" 418 | }, 419 | "suggest": { 420 | "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", 421 | "doctrine/couchdb": "Allow sending log messages to a CouchDB server", 422 | "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", 423 | "ext-mongo": "Allow sending log messages to a MongoDB server", 424 | "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", 425 | "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", 426 | "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", 427 | "php-console/php-console": "Allow sending log messages to Google Chrome", 428 | "rollbar/rollbar": "Allow sending log messages to Rollbar", 429 | "ruflin/elastica": "Allow sending log messages to an Elastic Search server", 430 | "sentry/sentry": "Allow sending log messages to a Sentry server" 431 | }, 432 | "type": "library", 433 | "extra": { 434 | "branch-alias": { 435 | "dev-master": "2.0.x-dev" 436 | } 437 | }, 438 | "autoload": { 439 | "psr-4": { 440 | "Monolog\\": "src/Monolog" 441 | } 442 | }, 443 | "notification-url": "https://packagist.org/downloads/", 444 | "license": [ 445 | "MIT" 446 | ], 447 | "authors": [ 448 | { 449 | "name": "Jordi Boggiano", 450 | "email": "j.boggiano@seld.be", 451 | "homepage": "http://seld.be" 452 | } 453 | ], 454 | "description": "Sends your logs to files, sockets, inboxes, databases and various web services", 455 | "homepage": "http://github.com/Seldaek/monolog", 456 | "keywords": [ 457 | "log", 458 | "logging", 459 | "psr-3" 460 | ], 461 | "time": "2016-07-29 03:23:52" 462 | }, 463 | { 464 | "name": "psr/http-message", 465 | "version": "1.0.1", 466 | "source": { 467 | "type": "git", 468 | "url": "https://github.com/php-fig/http-message.git", 469 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" 470 | }, 471 | "dist": { 472 | "type": "zip", 473 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", 474 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", 475 | "shasum": "" 476 | }, 477 | "require": { 478 | "php": ">=5.3.0" 479 | }, 480 | "type": "library", 481 | "extra": { 482 | "branch-alias": { 483 | "dev-master": "1.0.x-dev" 484 | } 485 | }, 486 | "autoload": { 487 | "psr-4": { 488 | "Psr\\Http\\Message\\": "src/" 489 | } 490 | }, 491 | "notification-url": "https://packagist.org/downloads/", 492 | "license": [ 493 | "MIT" 494 | ], 495 | "authors": [ 496 | { 497 | "name": "PHP-FIG", 498 | "homepage": "http://www.php-fig.org/" 499 | } 500 | ], 501 | "description": "Common interface for HTTP messages", 502 | "homepage": "https://github.com/php-fig/http-message", 503 | "keywords": [ 504 | "http", 505 | "http-message", 506 | "psr", 507 | "psr-7", 508 | "request", 509 | "response" 510 | ], 511 | "time": "2016-08-06 14:39:51" 512 | }, 513 | { 514 | "name": "psr/log", 515 | "version": "1.0.2", 516 | "source": { 517 | "type": "git", 518 | "url": "https://github.com/php-fig/log.git", 519 | "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" 520 | }, 521 | "dist": { 522 | "type": "zip", 523 | "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", 524 | "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", 525 | "shasum": "" 526 | }, 527 | "require": { 528 | "php": ">=5.3.0" 529 | }, 530 | "type": "library", 531 | "extra": { 532 | "branch-alias": { 533 | "dev-master": "1.0.x-dev" 534 | } 535 | }, 536 | "autoload": { 537 | "psr-4": { 538 | "Psr\\Log\\": "Psr/Log/" 539 | } 540 | }, 541 | "notification-url": "https://packagist.org/downloads/", 542 | "license": [ 543 | "MIT" 544 | ], 545 | "authors": [ 546 | { 547 | "name": "PHP-FIG", 548 | "homepage": "http://www.php-fig.org/" 549 | } 550 | ], 551 | "description": "Common interface for logging libraries", 552 | "homepage": "https://github.com/php-fig/log", 553 | "keywords": [ 554 | "log", 555 | "psr", 556 | "psr-3" 557 | ], 558 | "time": "2016-10-10 12:19:37" 559 | } 560 | ], 561 | "packages-dev": [], 562 | "aliases": [], 563 | "minimum-stability": "stable", 564 | "stability-flags": [], 565 | "prefer-stable": false, 566 | "prefer-lowest": false, 567 | "platform": [], 568 | "platform-dev": [] 569 | } 570 | --------------------------------------------------------------------------------