src/Controller/Telegram/AgentPublicBot/NeoWebHookController.php line 587

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Telegram\AgentPublicBot;
  3. use App\DependencyInjection\JDF;
  4. use App\Entity\Country;
  5. use App\Entity\Generic\User;
  6. use App\Entity\SubTransactions\ArzDigital;
  7. use App\Entity\Telegram\AgentPublicBot\Bot;
  8. use App\Entity\Telegram\AgentPublicBot\BotCampaign;
  9. use App\Entity\Telegram\AgentPublicBot\BotPlan;
  10. use App\Entity\Telegram\AgentPublicBot\BotTransaction;
  11. use App\Entity\Telegram\AgentPublicBot\BotUser;
  12. use App\Entity\Transaction;
  13. use App\Entity\VPN\Service\Plan;
  14. use App\Entity\VPN\Service\Service;
  15. use App\Entity\VPN\V2ray\Server;
  16. use App\Form\VPN\Service\Service\LimitedOcServType;
  17. use App\Form\VPN\Service\Service\LimitedOpenType;
  18. use App\Form\VPN\Service\Service\LimitedV2rayType;
  19. use App\Form\VPN\Service\Service\LimitedVipType;
  20. use App\Form\VPN\Service\Service\UnlimitedOcServType;
  21. use App\Form\VPN\Service\Service\UnlimitedOpenType;
  22. use App\Form\VPN\Service\Service\UnlimitedV2rayType;
  23. use App\Repository\Telegram\AgentPublicBot\BotPlanRepository;
  24. use App\Repository\Telegram\AgentPublicBot\BotRepository;
  25. use App\Repository\Telegram\AgentPublicBot\BotUserRepository;
  26. use App\Repository\VPN\Service\ServiceRepository;
  27. use App\Repository\VPN\V2ray\ServerRepository;
  28. use App\Service\SettingService;
  29. use App\Service\Telegram\AgentPublicBot\BotUserService;
  30. use App\Service\TransactionService;
  31. use App\Service\Util\ByteConvert;
  32. use App\Service\Util\DynamicPriceCalculation;
  33. use App\Service\Util\NotificationService;
  34. use App\Service\Util\TelegramBot;
  35. use App\Service\Util\TelegramNotifier;
  36. use App\Service\Util\V2rayConnectionMaker;
  37. use App\Service\VPN\Service\ServiceService;
  38. use DateTime;
  39. use DateTimeImmutable;
  40. use Doctrine\ORM\EntityManagerInterface;
  41. use Exception;
  42. use App\Service\Util\MarzbanNewAPI;
  43. use Psr\Log\LoggerInterface;
  44. use Ramsey\Collection\Set;
  45. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  46. use Symfony\Component\HttpFoundation\JsonResponse;
  47. use Symfony\Component\HttpFoundation\Request;
  48. use Symfony\Component\HttpFoundation\RequestStack;
  49. use Symfony\Component\HttpFoundation\Response;
  50. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  51. use Symfony\Component\Routing\Annotation\Route;
  52. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  53. class NeoWebHookController extends AbstractController
  54. {
  55.     public TransactionService $transaction;
  56.     public DynamicPriceCalculation $dynamicPriceCalculation;
  57.     public EntityManagerInterface $entityManager;
  58.     public TransactionService $panelTrasnactionService;
  59.     public ServiceService $service;
  60.     public TransactionService $transactionService;
  61. //    public null| $botUser = null;
  62.     public array $messages = [
  63.         'welcome' => PHP_EOL '------
  64. موجودی شما : --WALLET--
  65. شناسه کاربری شما : --USERID--
  66. ',
  67.         'chooseServiceType' => 'لطفا ابتدا نوع سرویس مدنظر را انتخاب فرمایید' PHP_EOL .
  68.             'سرویس انتخاب شده : ' PHP_EOL .
  69.             'نوع سرویس : --SERVICETYPE--' PHP_EOL .
  70.             'لوکیشن : --SERVERTYPE--' PHP_EOL .
  71.             ' تعداد کاربر : --USERCOUNT--' PHP_EOL .
  72.             ' زمان سرویس : --SERVICETIME--' PHP_EOL,
  73.         'chooseServiceServerType' => 'لطفا نوع سرور سرویس خود را انتخاب فرمایید' PHP_EOL .
  74.             'سرویس انتخاب شده : ' PHP_EOL .
  75.             'نوع سرویس : --SERVICETYPE--' PHP_EOL .
  76.             'لوکیشن : --SERVERTYPE--' PHP_EOL .
  77.             ' تعداد کاربر : --USERCOUNT--' PHP_EOL .
  78.             ' زمان سرویس : --SERVICETIME--' PHP_EOL,
  79.         'chooseServiceLocation' => 'لطفا کشور مد نظر را انتخاب فرمایید' PHP_EOL .
  80.             'سرویس انتخاب شده : ' PHP_EOL .
  81.             'نوع سرویس : --SERVICETYPE--' PHP_EOL .
  82.             'لوکیشن : --SERVERTYPE--' PHP_EOL .
  83.             ' تعداد کاربر : --USERCOUNT--' PHP_EOL .
  84.             ' زمان سرویس : --SERVICETIME--' PHP_EOL,
  85.         'chooseServiceUsers' => 'تعداد کاربر مورد نیاز خود برای اتصال را انتخاب فرمایید' PHP_EOL .
  86.             'سرویس انتخاب شده : ' PHP_EOL .
  87.             'نوع سرویس : --SERVICETYPE--' PHP_EOL .
  88.             'لوکیشن : --SERVERTYPE--' PHP_EOL .
  89.             ' تعداد کاربر : --USERCOUNT--' PHP_EOL .
  90.             ' زمان سرویس : --SERVICETIME--' PHP_EOL,
  91.         'chooseServicePlan' => 'سرویس مورد نظر را انتخاب فرمایید' PHP_EOL .
  92.             'سرویس انتخاب شده : ' PHP_EOL .
  93.             'نوع سرویس : --SERVICETYPE--' PHP_EOL .
  94.             'لوکیشن : --SERVERTYPE--' PHP_EOL .
  95.             ' تعداد کاربر : --USERCOUNT--' PHP_EOL .
  96.             ' زمان سرویس : --SERVICETIME--' PHP_EOL,
  97.         'chooseServiceTime' => 'زمان سرویس مورد نظر را انتخاب فرمایید' PHP_EOL .
  98.             'سرویس انتخاب شده : ' PHP_EOL .
  99.             'نوع سرویس : --SERVICETYPE--' PHP_EOL .
  100.             'لوکیشن : --SERVERTYPE--' PHP_EOL .
  101.             ' تعداد کاربر : --USERCOUNT--' PHP_EOL .
  102.             ' زمان سرویس : --SERVICETIME--' PHP_EOL,
  103.     ];
  104.     public array $startMessageButtons;
  105.     public array $serviceTypesButtons;
  106.     public array $testServiceTypesButtons = [
  107. //        [
  108. //            [
  109. //                'text' => 'سرویس V2ray نامحدود',
  110. //                'callback_data' => 'tes-v2rayServiceUnLimited'
  111. //            ],
  112. //            [
  113. //                'text' => 'سرویس V2ray حجمی',
  114. //                'callback_data' => 'tes-v2rayService'
  115. //            ]
  116. //        ],
  117. //        [
  118. //            [
  119. //                'text' => 'سرویس Cisco نامحدود',
  120. //                'callback_data' => 'tes-ciscoServiceUnLimited'
  121. //            ],
  122. //            [
  123. //                'text' => 'سرویس Cisco حجمی',
  124. //                'callback_data' => 'tes-ciscoService'
  125. //            ]
  126. //        ],
  127. //
  128. //        [
  129. //            [
  130. //                'text' => 'سرویس OpenVpn نامحدود',
  131. //                'callback_data' => 'tes-openServiceUnLimited'
  132. //            ],
  133. //            [
  134. //                'text' => 'سرویس OpenVpn حجمی',
  135. //                'callback_data' => 'tes-openService'
  136. //            ]
  137. //        ],
  138. //        [
  139. //            [
  140. //                'text' => 'سرویس مولتی پروتکل',
  141. //                'callback_data' => 'tes-vipService'
  142. //            ]
  143. //        ],
  144.         [
  145.             [
  146.                 'text' => 'دریافت تست یک روزه',
  147.                 'callback_data' => 'tes-vipService'
  148.             ]
  149.         ],
  150.         [
  151.             [
  152.                 'text' => '⬆️ بازگشت به صفحه اصلی',
  153.                 'callback_data' => '/start'
  154.             ]
  155.         ]
  156.     ];
  157.     public array $serviceUsersButtons = [
  158.         [
  159.             [
  160.                 'text' => 'یک کاربر همزمان',
  161.                 'callback_data' => '1User'
  162.             ]
  163.         ],
  164.         [
  165.             [
  166.                 'text' => 'دو کاربر همزمان',
  167.                 'callback_data' => '2User'
  168.             ]
  169.         ],
  170.         [
  171.             [
  172.                 'text' => 'سه کاربر همزمان',
  173.                 'callback_data' => '3User'
  174.             ]
  175.         ],
  176.         [
  177.             [
  178.                 'text' => 'چهار کاربر همزمان',
  179.                 'callback_data' => '4User'
  180.             ]
  181.         ],
  182.         [
  183.             [
  184.                 'text' => 'پنج کاربر همزمان',
  185.                 'callback_data' => '5User'
  186.             ]
  187.         ],
  188.         [
  189.             [
  190.                 'text' => '⬆️ بازگشت به صفحه اصلی',
  191.                 'callback_data' => '/start'
  192.             ]
  193.         ]
  194.     ];
  195.     public array $serviceTimeButtons = [
  196.         [
  197.             [
  198.                 'text' => 'یک ماه',
  199.                 'callback_data' => '30Days'
  200.             ]
  201.         ],
  202.         [
  203.             [
  204.                 'text' => 'دو ماه',
  205.                 'callback_data' => '60Days'
  206.             ]
  207.         ],
  208.         [
  209.             [
  210.                 'text' => 'سه ماه',
  211.                 'callback_data' => '90Days'
  212.             ]
  213.         ],
  214.         [
  215.             [
  216.                 'text' => 'شش ماه',
  217.                 'callback_data' => '180Days'
  218.             ]
  219.         ],
  220.         [
  221.             [
  222.                 'text' => 'یک سال',
  223.                 'callback_data' => '365Days'
  224.             ]
  225.         ],
  226.         [
  227.             [
  228.                 'text' => '⬆️ بازگشت به صفحه اصلی',
  229.                 'callback_data' => '/start'
  230.             ]
  231.         ]
  232.     ];
  233.     public array $paymentButtons;
  234.     public Bot|null $bot;
  235.     public BotUser|null $botUser;
  236.     public string $channelUsername;
  237.     public string $token;
  238.     public TelegramNotifier $telegramBot;
  239.     public $learn_channel "@khanvpnofficial";
  240.     public $adminId '6471235924';
  241.     private string $brandDomain;
  242.     private BotUserService $botUserService;
  243.     public NotificationService $notificationService;
  244.     public function getStartButtons($userId null)
  245.     {
  246.         if ($this->bot->isIsBotForWebsite()) {
  247.             $this->startMessageButtons = [
  248.                 [
  249.                     [
  250.                         "text" => "🎁 دریافت اکانت تست (رایگان)",
  251.                         "callback_data" => "testService"
  252.                     ]
  253.                 ],
  254.                 [
  255.                     [
  256.                         "text" => "📞 پشتیبانی آنلاین",
  257.                         "url" => "https://t.me/" $this->bot->getSupportUsername()
  258.                     ]
  259.                 ],
  260.                 [
  261.                     [
  262.                         "text" => "🔋 اعطای نمایندگی",
  263.                         "url" => "https://t.me/" $this->bot->getSupportUsername()
  264.                     ],
  265.                 ],
  266.             ];
  267.         } else {
  268.             if ($userId) {
  269.                 if (str_contains($this->brandDomain 'tehransub.website')){
  270.                     $myServicesLink "https://tehrannet.org/telegram/agent-public-bot/webhook-neo/{$this->bot->getId()}/user-services/{$this->botUser->getUserId()}";
  271.                 }else{
  272.                     $myServicesLink "{$this->brandDomain}/telegram/agent-public-bot/webhook-neo/{$this->bot->getId()}/user-services/{$this->botUser->getUserId()}";
  273.                 }
  274.                 $this->startMessageButtons = [
  275.                     [
  276.                         [
  277.                             "text" => "📦 کانفیگ های من",
  278.                             "url" => $myServicesLink
  279.                         ],
  280.                         [
  281.                             "text" => "🛒 خرید کانفیگ جدید",
  282.                             "callback_data" => "buyService"
  283.                         ],
  284.                     ],
  285.                     [
  286.                         [
  287.                             "text" => "🔋 تمدید کانفیگ",
  288.                             "url" => $myServicesLink
  289.                         ],
  290.                     ],
  291.                     [
  292.                         [
  293.                             "text" => "🎁 دریافت اکانت تست (رایگان)",
  294.                             "callback_data" => "testService"
  295.                         ]
  296.                     ],
  297.                     [
  298.                         [
  299.                             "text" => "💸 حسابداری",
  300.                             "callback_data" => "accounting"
  301.                         ],
  302.                         [
  303.                             "text" => "💰 شارژ کیف پول",
  304.                             "callback_data" => "charge"
  305.                         ],
  306.                     ],
  307. //            [
  308. //                [
  309. //                    "text" => "🧩|آموزش اتصال",
  310. //                    "url" => "https://t.me/khanvpn_support"
  311. //                ]
  312. //            ],
  313.                     [
  314.                         [
  315.                             "text" => "📞 پشتیبانی آنلاین",
  316.                             "url" => "https://t.me/" $this->bot->getSupportUsername()
  317.                         ]
  318.                     ],
  319.                     [
  320.                         [
  321.                             "text" => "🔋 اعطای نمایندگی",
  322.                             "url" => "https://t.me/" $this->bot->getSupportUsername()
  323.                         ],
  324. //            [
  325. //                "text" => "😇|دعوت از دوستان",
  326. //                "url" => "https://t.me/khanvpn_support"
  327. //            ]
  328.                     ],
  329.                 ];
  330.             } else {
  331.                 $this->startMessageButtons = [
  332.                     [
  333. //                    [
  334. //                        "text" => "📦 کانفیگ های من",
  335. //                        "url" => $myServicesLink
  336. //                    ],
  337.                         [
  338.                             "text" => "🛒 خرید کانفیگ جدید",
  339.                             "callback_data" => "buyService"
  340.                         ],
  341.                     ],
  342.                     [
  343.                         [
  344.                             "text" => "🎁 دریافت اکانت تست (رایگان)",
  345.                             "callback_data" => "testService"
  346.                         ]
  347.                     ],
  348.                     [
  349.                         [
  350.                             "text" => "💸 حسابداری",
  351.                             "callback_data" => "accounting"
  352.                         ],
  353.                         [
  354.                             "text" => "💰 شارژ کیف پول",
  355.                             "callback_data" => "charge"
  356.                         ],
  357.                     ],
  358. //            [
  359. //                [
  360. //                    "text" => "🧩|آموزش اتصال",
  361. //                    "url" => "https://t.me/khanvpn_support"
  362. //                ]
  363. //            ],
  364.                     [
  365.                         [
  366.                             "text" => "📞 پشتیبانی آنلاین",
  367.                             "url" => "https://t.me/" $this->bot->getSupportUsername()
  368.                         ]
  369.                     ],
  370.                     [
  371.                         [
  372.                             "text" => "🔋 اعطای نمایندگی",
  373.                             "url" => "https://t.me/" $this->bot->getSupportUsername()
  374.                         ],
  375. //            [
  376. //                "text" => "😇|دعوت از دوستان",
  377. //                "url" => "https://t.me/khanvpn_support"
  378. //            ]
  379.                     ],
  380.                 ];
  381.             }
  382.         }
  383.         return $this->startMessageButtons;
  384.     }
  385.     public function __construct(NotificationService $notificationService TransactionService $transactionTransactionService $panelTransactionServiceBotPlanRepository $botPlanRepositoryServiceService $serviceEntityManagerInterface $entityManagerTransactionService $transactionServiceTelegramNotifier $telegramBotRequestStack $requestStackBotUserService $botUserServiceDynamicPriceCalculation $dynamicPriceCalculation)
  386.     {
  387.         $this->notificationService $notificationService;
  388.         $this->transaction $transaction;
  389.         $this->dynamicPriceCalculation $dynamicPriceCalculation;
  390.         $this->panelTrasnactionService $panelTransactionService;
  391.         $setting = new SettingService($entityManager);
  392.         $this->brandDomain 'https://' $setting->getSetting('SUBSCRIPTIONLINK''#');
  393.         $this->transactionService $transactionService;
  394.         $botID $requestStack->getCurrentRequest()->attributes->get('id');
  395.         $this->entityManager $entityManager;
  396.         $bot $entityManager->getRepository(Bot::class)->find($botID);
  397.         $this->bot $bot;
  398.         if ($bot->isIsBotForWebsite()) {
  399.             $this->messages['welcome'] = $this->bot->getWelcomeMessage();
  400.         } else {
  401.             $this->messages['welcome'] = $this->bot->getWelcomeMessage() . $this->messages['welcome'];
  402.         }
  403.         $this->token $bot->getToken();
  404.         $this->channelUsername "@" $this->bot->getChannelUserNAme();
  405.         $this->telegramBot $telegramBot;
  406.         if ($bot->getDomain()) {
  407.             $this->brandDomain 'https://' $bot->getDomain()->getAddress();
  408.         }
  409.         $this->botUserService $botUserService;
  410.         $this->service $service;
  411.         $this->paymentButtons = [];
  412.         if ($this->bot->getCardNumber() && ($this->bot->getCardNumber() !== '')) {
  413.             $this->paymentButtons[] = [
  414.                 [
  415.                     'text' => 'کارت به کارت',
  416.                     'callback_data' => 'chargeCardToCard'
  417.                 ]
  418.             ];
  419.         }
  420.         if ($this->bot->getWalletAddress() && ($this->bot->getWalletAddress() !== '')) {
  421.             $this->paymentButtons[] = [
  422.                 [
  423.                     'text' => 'پرداخت آنلاین',
  424.                     'callback_data' => 'chargeOnline'
  425.                 ]
  426.             ];
  427.         }
  428. // دکمه بازگشت همیشه هست
  429.         $this->paymentButtons[] = [
  430.             [
  431.                 'text' => '⬆️ بازگشت به صفحه اصلی',
  432.                 'callback_data' => '/start'
  433.             ]
  434.         ];
  435. //        $this->serviceTypesButtons =[
  436. //            [
  437. //                [
  438. //                    'text' => 'V2ray نامحدود',
  439. //                    'callback_data' => 'v2rayServiceUnLimited'
  440. //                ],
  441. //                [
  442. //                    'text' => 'V2ray حجمی',
  443. //                    'callback_data' => 'v2rayService'
  444. //                ]
  445. //            ],
  446. //            [
  447. //                [
  448. //                    'text' => 'Cisco نامحدود',
  449. //                    'callback_data' => 'ciscoServiceUnLimited'
  450. //                ],
  451. //                [
  452. //                    'text' => 'Cisco حجمی',
  453. //                    'callback_data' => 'ciscoService'
  454. //                ]
  455. //            ],
  456. //            [
  457. //                [
  458. //                    'text' => 'OpenVPN نامحدود',
  459. //                    'callback_data' => 'openServiceUnLimited'
  460. //                ],
  461. //                [
  462. //                    'text' => 'OpenVPN حجمی',
  463. //                    'callback_data' => 'openService'
  464. //                ]
  465. //            ],
  466. //            [
  467. //                [
  468. //                    'text' => 'مولتی پروتکل',
  469. //                    'callback_data' => 'vipService'
  470. //                ]
  471. //            ],
  472. //            [
  473. //                [
  474. //                    'text' => '⬆️ بازگشت به صفحه اصلی',
  475. //                    'callback_data' => '/start'
  476. //                ]
  477. //            ]
  478. //
  479. //
  480. //        ];
  481.         $this->serviceTypesButtons = [];
  482.         if ($botPlanRepository->hasPlanType($this->bot'unlimited''v2ray') || $botPlanRepository->hasPlanType($this->bot'sized''v2ray')) {
  483.             $row = [];
  484.             if ($botPlanRepository->hasPlanType($this->bot'unlimited''v2ray')) {
  485.                 $row[] = [
  486.                     'text' => 'V2ray نامحدود',
  487.                     'callback_data' => 'v2rayServiceUnLimited'
  488.                 ];
  489.             }
  490.             if ($botPlanRepository->hasPlanType($this->bot'sized''v2ray')) {
  491.                 $row[] = [
  492.                     'text' => 'V2ray حجمی',
  493.                     'callback_data' => 'v2rayService'
  494.                 ];
  495.             }
  496.             if (!empty($row)) {
  497.                 $this->serviceTypesButtons[] = $row;
  498.             }
  499.         }
  500. // مشابه همین واسه Cisco
  501.         $row = [];
  502.         if ($botPlanRepository->hasPlanType($this->bot'unlimited''ocserv')) {
  503.             $row[] = [
  504.                 'text' => 'Cisco نامحدود',
  505.                 'callback_data' => 'ciscoServiceUnLimited'
  506.             ];
  507.         }
  508.         if ($botPlanRepository->hasPlanType($this->bot'sized''ocserv')) {
  509.             $row[] = [
  510.                 'text' => 'Cisco حجمی',
  511.                 'callback_data' => 'ciscoService'
  512.             ];
  513.         }
  514.         if (!empty($row)) {
  515.             $this->serviceTypesButtons[] = $row;
  516.         }
  517. // مشابه واسه OpenVPN
  518.         $row = [];
  519.         if ($botPlanRepository->hasPlanType($this->bot'unlimited''open')) {
  520.             $row[] = [
  521.                 'text' => 'OpenVPN نامحدود',
  522.                 'callback_data' => 'openServiceUnLimited'
  523.             ];
  524.         }
  525.         if ($botPlanRepository->hasPlanType($this->bot'sized''open')) {
  526.             $row[] = [
  527.                 'text' => 'OpenVPN حجمی',
  528.                 'callback_data' => 'openService'
  529.             ];
  530.         }
  531.         if (!empty($row)) {
  532.             $this->serviceTypesButtons[] = $row;
  533.         }
  534.         if ($botPlanRepository->hasPlanType($this->bot'sized''vip')) {
  535.             $this->serviceTypesButtons[] = [
  536.                 [
  537.                     'text' => 'مولتی پروتکل',
  538.                     'callback_data' => 'vipService'
  539.                 ]
  540.             ];
  541.         }
  542. // دکمه بازگشت همیشه هست
  543.         $this->serviceTypesButtons[] = [
  544.             [
  545.                 'text' => '⬆️ بازگشت به صفحه اصلی',
  546.                 'callback_data' => '/start'
  547.             ]
  548.         ];
  549.     }
  550.     #[Route('/telegram/agent-public-bot/webhook-neo/{id}'name'app_telegram_agent_public_bot_web_hook_neon')]
  551.     public function handleWebhook(Request $requestLoggerInterface $logger): Response
  552.     {
  553. //        if (isset($content['channel_post'])) {
  554. //            $this->handleChannelPost($content['channel_post'], $logger);
  555. //        }
  556.         $content json_decode($request->getContent(), true);
  557.         if (isset($content['message'])) {
  558.             $this->handleMessage($content['message'], $logger);
  559.         }
  560.         if (isset($content['callback_query'])) {
  561.             $this->handleCallbackQuery($content['callback_query'], $logger);
  562.         }
  563.         if (isset($content['edited_message'])) {
  564.             $this->handleEditedMessage($content['edited_message'], $logger);
  565.         }
  566.         if (isset($content['inline_query'])) {
  567.             $this->handleInlineQuery($content['inline_query'], $logger);
  568.         }
  569.         if (isset($content['channel_post'])) {
  570.             $this->handleChannelPost($content['channel_post'], $logger);
  571.         }
  572.         if (isset($content['edited_channel_post'])) {
  573.             $this->handleEditedChannelPost($content['edited_channel_post'], $logger);
  574.         }
  575.         if (isset($content['poll'])) {
  576.             $this->handlePoll($content['poll'], $logger);
  577.         }
  578.         if (isset($content['poll_answer'])) {
  579.             $this->handlePollAnswer($content['poll_answer'], $logger);
  580.         }
  581.         if (isset($content['my_chat_member'])) {
  582.             $this->handleMyChatMember($content['my_chat_member'], $logger);
  583.         }
  584.         if (isset($content['chat_member'])) {
  585.             $this->handleChatMember($content['chat_member'], $logger);
  586.         }
  587.         // Respond with 200 OK
  588.         return new Response('NoDirectAccess'Response::HTTP_OK);
  589.     }
  590.     public function beautifyText($text)
  591.     {
  592.         if ($this->botUser) {
  593.             $text str_replace('--USERID--'$this->botUser->getUserId(), $text);
  594.             $text str_replace('--WALLET--'number_format($this->botUser->getWallet()) . ' تومان'$text);
  595.             $text str_replace('--CARDNUMBER--''`' $this->bot->getCardNumber() . '`'$text);
  596.             if (isset($this->botUser->getNewServiceDetail()['users'])) {
  597.                 $text str_replace('--USERCOUNT--'$this->botUser->getNewServiceDetail()['users'] . ' کاربر'$text);
  598.             } else {
  599.                 $text str_replace('--USERCOUNT--''انتخاب نشده'$text);
  600.             }
  601.             if (isset($this->botUser->getNewServiceDetail()['serviceType'])) {
  602.                 switch ($this->botUser->getNewServiceDetail()['serviceType']) {
  603.                     case 'v2rayService':
  604.                         $text str_replace('--SERVICETYPE--''سرویس V2ray حجمی'$text);
  605.                         break;
  606.                     case 'ciscoService':
  607.                         $text str_replace('--SERVICETYPE--''سرویس Cisco حجمی'$text);
  608.                         break;
  609.                     case 'openService':
  610.                         $text str_replace('--SERVICETYPE--''سرویس OpenVPN حجمی'$text);
  611.                         break;
  612.                     case 'v2rayServiceUnLimited':
  613.                         $text str_replace('--SERVICETYPE--''سرویس V2ray نامحدود'$text);
  614.                         break;
  615.                     case 'ciscoServiceUnLimited':
  616.                         $text str_replace('--SERVICETYPE--''سرویس Cisco نامحدود'$text);
  617.                         break;
  618.                     case 'openServiceUnLimited':
  619.                         $text str_replace('--SERVICETYPE--''سرویس OpenVPN نامحدود'$text);
  620.                         break;
  621.                     case 'vipService':
  622.                         $text str_replace('--SERVICETYPE--''سرویس VIP مولتی پروتکل'$text);
  623.                         break;
  624.                 }
  625.             } else {
  626.                 $text str_replace('--SERVICETYPE--''انتخاب نشده'$text);
  627.             }
  628.             if (isset($this->botUser->getNewServiceDetail()['serviceTime'])) {
  629.                 switch ($this->botUser->getNewServiceDetail()['serviceTime']) {
  630.                     case '30':
  631.                         $text str_replace('--SERVICETIME--''یک ماه'$text);
  632.                         break;
  633.                     case '60':
  634.                         $text str_replace('--SERVICETIME--''دو ماه'$text);
  635.                         break;
  636.                     case '90':
  637.                         $text str_replace('--SERVICETIME--''سه ماه'$text);
  638.                         break;
  639.                     case '180':
  640.                         $text str_replace('--SERVICETIME--''شش ماه'$text);
  641.                         break;
  642.                     case '365':
  643.                         $text str_replace('--SERVICETIME--''یک سال'$text);
  644.                         break;
  645.                 }
  646.             } else {
  647.                 $text str_replace('--SERVICETIME--''انتخاب نشده'$text);
  648.             }
  649.             if (isset($this->botUser->getNewServiceDetail()['serviceType'])
  650.                 &&
  651.                 str_contains($this->botUser->getNewServiceDetail()['serviceType'], 'UnLimited')
  652.             ) {
  653.                 if (isset($this->botUser->getNewServiceDetail()['country'])) {
  654.                     $countryRepo $this->getDoctrine()->getRepository(Country::class);
  655.                     $selectedCountry $countryRepo->findOneBy(['code' => $this->botUser->getNewServiceDetail()['country']]);
  656.                     $text str_replace('--SERVERTYPE--',
  657.                         $this->countryCodeToFlag($selectedCountry->getCode()) .
  658.                         $selectedCountry->getTitle(), $text);
  659.                 } else {
  660.                     $text str_replace('--SERVERTYPE--''انتخاب نشده'$text);
  661.                 }
  662.             } else {
  663.                 $text str_replace('--SERVERTYPE--''تمام لوکیشن های موجود'$text);
  664.             }
  665.         }
  666.         return $text;
  667.     }
  668. //    #[Route('/set-webhook', name: 'set_webhook')]
  669. //    public function setWebhook()
  670. //    {
  671. //        $webhookUrl = "https://tehrannet.org/khan/bot/main/webhook";
  672. //        $apiUrl = "https://api.telegram.org/bot{$this->token}/setWebhook";
  673. //        $parameters = [
  674. //            'url' => $webhookUrl,
  675. //            'drop_pending_updates' => 'True',
  676. //            'max_connections' => '100'
  677. //        ];
  678. //        $ch = curl_init();
  679. //        curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot{$this->token}/deleteWebhook");
  680. //        curl_setopt($ch, CURLOPT_POST, true);
  681. //        curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
  682. //        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  683. //        $response = curl_exec($ch);
  684. //        curl_close($ch);
  685. //        $ch = curl_init();
  686. //        curl_setopt($ch, CURLOPT_URL, $apiUrl);
  687. //        curl_setopt($ch, CURLOPT_POST, true);
  688. //        curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
  689. //        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  690. //        $response = curl_exec($ch);
  691. //        curl_close($ch);
  692. //        return $this->json(['res' => $response]);
  693. //    }
  694.     private function handleMessage(array $messageLoggerInterface $logger): void
  695.     {
  696.         $repo $this->getDoctrine()->getRepository(BotUser::class);
  697.         $chatId $message['chat']['id'];
  698.         $firstName $message['chat']['first_name'] ?? null;
  699.         $lastName $message['chat']['last_name'] ?? null;
  700.         $username $message['chat']['username'] ?? null;
  701.         $khanUser $repo->findOneBy(['userId' => $chatId'bot' => $this->bot]);
  702.         if (!$khanUser) {
  703.             $khanUser = new BotUser();
  704.             $khanUser->setNewServiceDetail([]);
  705.             $khanUser->setUserId($chatId);
  706.             $khanUser->setBot($this->bot);
  707.         }
  708.         $khanUser->setName($firstName ?: '');
  709.         $khanUser->setUsername($username ?: '');
  710.         $this->entityManager->persist($khanUser);
  711.         $this->entityManager->flush();
  712.         $this->botUser $khanUser;
  713.         if (!$this->bot->isActive() || !$this->bot->getOwner()->isActive()) {
  714.             $this->sendMessage($this->botUser->getUserId(),
  715.                 'ربات فعال نمیباشد با پشتیبانی در ارتباط باشید....'
  716.             );
  717.             die;
  718.         }
  719.         $chatId $message['chat']['id'];
  720.         $text $message['text'] ?? '';
  721.         $messageId $message['message_id'] ?? null// Get message ID
  722.         if ((bool)$this->bot->isForceJoinChannel() && $this->bot->getChannelUserNAme()) {
  723.             if (!$this->checkIfUserIsInChannel($chatId$this->channelUsername)) {
  724.                 $this->sendInlineKeyboard($chatId'❌ برای استفاده از ربات حتما باید در کانال زیر عضو شوید:
  725.     
  726. ✅ بعد از اینکه عضو شدید روی دکمه عضو شدم بزنید'
  727.                     PHP_EOL .
  728.                     $this->channelUsername, [
  729.                         [
  730.                             [
  731.                                 'text' => '✅عضو شدم✅',
  732.                                 'callback_data' => '/start'
  733.                             ]
  734.                         ]
  735.                     ]
  736.                 );
  737.                 return;
  738.             }
  739.         }
  740. //        try {
  741. //            $serviceTypesButtons = [];
  742. //            $botPlanRepository = $this->getDoctrine()->getRepository(BotPlan::class);
  743. //            if ($botPlanRepository->hasPlanType($this->bot , 'unlimited' , 'v2ray') || $botPlanRepository->hasPlanType($this->bot , 'sized' , 'v2ray')) {
  744. //                $row = [];
  745. //                if ($botPlanRepository->hasPlanType($this->bot , 'unlimited' , 'v2ray')) {
  746. //                    $row[] = [
  747. //                        'text' => 'V2ray نامحدود',
  748. //                        'callback_data' => 'v2rayServiceUnLimited'
  749. //                    ];
  750. //                }
  751. //                if ($botPlanRepository->hasPlanType($this->bot , 'sized' , 'v2ray')) {
  752. //                    $row[] = [
  753. //                        'text' => 'V2ray حجمی',
  754. //                        'callback_data' => 'v2rayService'
  755. //                    ];
  756. //                }
  757. //                if (!empty($row)) {
  758. //                    $serviceTypesButtons = $row;
  759. //                }
  760. //            }
  761. //
  762. //// مشابه همین واسه Cisco
  763. //            $row = [];
  764. //            if ($botPlanRepository->hasPlanType($this->bot , 'unlimited' , 'ocserv')) {
  765. //                $row[] = [
  766. //                    'text' => 'Cisco نامحدود',
  767. //                    'callback_data' => 'ciscoServiceUnLimited'
  768. //                ];
  769. //            }
  770. //            if ($botPlanRepository->hasPlanType($this->bot , 'sized' , 'ocserv')) {
  771. //                $row[] = [
  772. //                    'text' => 'Cisco حجمی',
  773. //                    'callback_data' => 'ciscoService'
  774. //                ];
  775. //            }
  776. //            if (!empty($row)) {
  777. //                $serviceTypesButtons[] = $row;
  778. //            }
  779. //
  780. //// مشابه واسه OpenVPN
  781. //            $row = [];
  782. //            if ($botPlanRepository->hasPlanType($this->bot , 'unlimited' , 'openvpn')) {
  783. //                $row[] = [
  784. //                    'text' => 'OpenVPN نامحدود',
  785. //                    'callback_data' => 'openServiceUnLimited'
  786. //                ];
  787. //            }
  788. //            if ($botPlanRepository->hasPlanType($this->bot , 'sized' , 'openvpn')) {
  789. //                $row[] = [
  790. //                    'text' => 'OpenVPN حجمی',
  791. //                    'callback_data' => 'openService'
  792. //                ];
  793. //            }
  794. //            if (!empty($row)) {
  795. //                $serviceTypesButtons[] = $row;
  796. //            }
  797. //
  798. //// دکمه VIP همیشه هست
  799. //            $serviceTypesButtons[] = [
  800. //                [
  801. //                    'text' => 'مولتی پروتکل',
  802. //                    'callback_data' => 'vipService'
  803. //                ]
  804. //            ];
  805. //
  806. //// دکمه بازگشت همیشه هست
  807. //            $serviceTypesButtons[] = [
  808. //                [
  809. //                    'text' => '⬆️ بازگشت به صفحه اصلی',
  810. //                    'callback_data' => '/start'
  811. //                ]
  812. //            ];
  813. //
  814. //            $this->sendMessageRaw($this->adminId , json_encode($serviceTypesButtons));
  815. //        }catch (\Exception $exception){
  816. //            $this->sendMessageRaw($this->adminId  , $exception->getMessage());
  817. //        }
  818.         if (preg_match('/^\/start(?:\s+\w+=(\w+))?/'$text$matches)) {
  819.             if (str_contains($text'usr')) {
  820.                 $this->handleConnectMessage(str_replace('/start usr='''$text), $chatId$logger);  // For user ID
  821.             }
  822.             if (str_contains($text'utm')) {
  823.                 $this->handleCampaign(str_replace('/start utm='''$text), $chatId$logger);  // For UTM value
  824.                 $this->sendInlineKeyboard($chatId$this->messages['welcome'], $this->getStartButtons($chatId));
  825.             }
  826.             if ($text == '/start') {
  827.                 $this->botUser->setNewServiceDetail([]);
  828.                 $this->entityManager->flush();
  829.                 $this->sendInlineKeyboard($chatId$this->messages['welcome'], $this->getStartButtons($chatId));
  830.             } else {
  831.                 if ($this->botUser->getStep()) {
  832.                     if ($this->botUser->getStep() == 'waitForPrice') {
  833.                         $startNumber intval($text);
  834.                         if ($startNumber < ($this->bot->getMinimumCardToCard() ?: 1000)) {
  835.                             $this->sendMessage($this->botUser->getUserId(), 'مبلغ وارد شده اشتباه می باشد مجدد مبلغ را ارسال فرمایید');
  836.                             die;
  837.                         } else {
  838.                             $minimumCardToCard $this->bot->getMinimumCardToCard() ?: 10000;
  839.                             $minimumCardToCardString number_format($minimumCardToCard);
  840.                             if ((int)$text >= (int)$minimumCardToCard) {
  841.                                 $targetPrice = (int)$text;
  842.                                 $this->botUser->setStep("waitForPanelFactor({$targetPrice})");
  843.                                 $this->getDoctrine()->getManager()->flush();
  844.                                 $this->sendMessage($this->botUser->getUserId(),
  845.                                     'درصورت ارسال رسید جعلی حساب شما بدون عودت وجه مسدود خواهد شد
  846.         لطفا مبلغ وارد شده با به شماره کارت
  847.         --CARDNUMBER--
  848.         واریز کنید و رسید آن را ارسال فرماید''markdown');
  849.                             } else {
  850.                                 $this->sendMessage($this->botUser->getUserId(), "عدد به درستی وارد نشده یا عدد ثبت شده کمتر از {$minimumCardToCardString} تومان می باشد لطفا مجدد به تومان با استفاده از کیبورد لاتین ارسال فرمایید");
  851.                             }
  852.                         }
  853.                     } elseif (preg_match('/waitForPanelFactor\((\d+)\)/'$this->botUser->getStep(), $match)) {
  854.                         if (isset($message['message']['photo']) || isset($message['photo'])) {
  855.                             $photo $message['message']['photo'] ?? $message['photo'];
  856.                             $this->botUser->setStep('');
  857.                             $chargetPrice number_format((int)$match[1]);
  858.                             try {
  859.                                 $this->sendPhoto($this->bot->getOwner()->getConnectedTelegramUserId()['userId'], $photo[0]['file_id'],
  860.                                     PHP_EOL .
  861.                                     "نام مشتری :‌ {$this->botUser->getName()}"
  862.                                     PHP_EOL .
  863.                                     "نام کاربری مشتری :‌ {$this->botUser->getUsername()}"
  864.                                     PHP_EOL .
  865.                                     "مبلغ ثبت شده : {$chargetPrice} تومان "
  866.                                     PHP_EOL .
  867.                                     "در صورتی که مبلغ وارد شده با مبلغ داخل رسید یکیست آنرا تایید کنید تا مشتری شارژ شود و در غیر اینصورت آنرا رد کنید تا رد شود",
  868.                                     [
  869.                                         [
  870.                                             [
  871.                                                 "text" => "تایید رسید",
  872.                                                 "callback_data" => "/acPCh(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  873.                                             ],
  874.                                         ],
  875.                                         [
  876.                                             [
  877.                                                 "text" => "رد رسید",
  878.                                                 "callback_data" => "/dcPCh(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  879.                                             ],
  880.                                         ],
  881.                                         [
  882.                                             [
  883.                                                 "text" => "رد رسید - رسید جعلی",
  884.                                                 "callback_data" => "/dcPChJa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  885.                                             ],
  886.                                         ],
  887.                                         [
  888.                                             [
  889.                                                 "text" => "رد رسید - عدم تطابق عدد واریز  و عدد ثبتی در پنل",
  890.                                                 "callback_data" => "/dcPChPa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  891.                                             ],
  892.                                         ],
  893.                                         [
  894.                                             [
  895.                                                 "text" => "رد رسید - عدم عدم وضوح متون تصویر",
  896.                                                 "callback_data" => "/dcPChKa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  897.                                             ],
  898.                                         ],
  899.                                         [
  900.                                             [
  901.                                                 "text" => "رد رسید - عدم دریافت مبلغ (پایا - شبا - پل)",
  902.                                                 "callback_data" => "/dcPChMa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  903.                                             ],
  904.                                         ]
  905.                                     ]
  906.                                 );
  907.                                 $this->sendMessage($this->botUser->getUserId(), 'رسید برای ادمین ارسال شد منتظر تایید آن باشید');
  908.                             } catch (Exception $exception) {
  909.                                 $this->notificationService->exception($exception);
  910. //                                $this->te
  911. //                                    $this->telegram->exception($exception);
  912. //                            $this->bot('sendMessage', [
  913. //                                'chat_id' => $this->chatId,
  914. //                                'text' => 'تصویر به درستی ارسال نشد مجدد اقدام فرمایید',
  915. //                                'reply_markup' => $this->backMenu
  916. //                            ], $bot->getToken());
  917. //                            $objectUser->setStep('');
  918.                             }
  919.                             $this->getDoctrine()->getManager()->flush();
  920.                         } else {
  921.                             $this->sendMessage($this->botUser->getUserId(), 'تصویر ارسال کن');
  922.                         }
  923.                     }
  924.                 } else {
  925.                     $this->sendInlineKeyboard($chatId$this->messages['welcome'], $this->getStartButtons($chatId));
  926.                 }
  927.             }
  928.         } else {
  929.             if ($this->botUser->getStep()) {
  930.                 if ($this->botUser->getStep() == 'waitForPrice') {
  931.                     $startNumber intval($text);
  932.                     if ($startNumber < ($this->bot->getMinimumCardToCard() ?: 1000)) {
  933.                         $this->sendMessage($this->botUser->getUserId(), 'مبلغ وارد شده اشتباه می باشد مجدد مبلغ را ارسال فرمایید');
  934.                         die;
  935.                     } else {
  936.                         $minimumCardToCard $this->bot->getMinimumCardToCard() ?: 10000;
  937.                         $minimumCardToCardString number_format($minimumCardToCard);
  938.                         if ((int)$text >= (int)$minimumCardToCard) {
  939.                             $targetPrice = (int)$text;
  940.                             $this->botUser->setStep("waitForPanelFactor({$targetPrice})");
  941.                             $this->getDoctrine()->getManager()->flush();
  942.                             $this->sendMessage($this->botUser->getUserId(),
  943.                                 'درصورت ارسال رسید جعلی حساب شما بدون عودت وجه مسدود خواهد شد
  944.         لطفا مبلغ وارد شده با به شماره کارت
  945.         --CARDNUMBER--
  946.         واریز کنید و رسید آن را ارسال فرماید''markdown');
  947.                         } else {
  948.                             $this->sendMessage($this->botUser->getUserId(), "عدد به درستی وارد نشده یا عدد ثبت شده کمتر از {$minimumCardToCardString} تومان می باشد لطفا مجدد به تومان با استفاده از کیبورد لاتین ارسال فرمایید");
  949.                         }
  950.                     }
  951.                 } elseif (preg_match('/waitForPanelFactor\((\d+)\)/'$this->botUser->getStep(), $match)) {
  952.                     if (isset($message['message']['photo']) || isset($message['photo'])) {
  953.                         $photo $message['message']['photo'] ?? $message['photo'];
  954.                         $this->botUser->setStep('');
  955.                         $chargetPrice number_format((int)$match[1]);
  956.                         try {
  957.                             $this->sendPhoto($this->bot->getOwner()
  958.                                 ->getConnectedTelegramUserId()['userId'], $photo[0]['file_id'],
  959.                                 PHP_EOL .
  960.                                 "نام مشتری :‌ {$this->botUser->getName()}"
  961.                                 PHP_EOL .
  962.                                 "نام کاربری مشتری :‌ {$this->botUser->getUsername()}"
  963.                                 PHP_EOL .
  964.                                 "مبلغ ثبت شده : {$chargetPrice} تومان "
  965.                                 PHP_EOL .
  966.                                 "در صورتی که مبلغ وارد شده با مبلغ داخل رسید یکیست آنرا تایید کنید تا مشتری شارژ شود و در غیر اینصورت آنرا رد کنید تا رد شود",
  967.                                 [
  968.                                     [
  969.                                         [
  970.                                             "text" => "تایید رسید",
  971.                                             "callback_data" => "/acPCh(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  972.                                         ],
  973.                                     ],
  974.                                     [
  975.                                         [
  976.                                             "text" => "رد رسید",
  977.                                             "callback_data" => "/dcPCh(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  978.                                         ],
  979.                                     ],
  980.                                     [
  981.                                         [
  982.                                             "text" => "رد رسید - رسید جعلی",
  983.                                             "callback_data" => "/dcPChJa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  984.                                         ],
  985.                                     ],
  986.                                     [
  987.                                         [
  988.                                             "text" => "رد رسید - عدم تطابق عدد واریز  و عدد ثبتی در پنل",
  989.                                             "callback_data" => "/dcPChPa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  990.                                         ],
  991.                                     ],
  992.                                     [
  993.                                         [
  994.                                             "text" => "رد رسید - عدم عدم وضوح متون تصویر",
  995.                                             "callback_data" => "/dcPChKa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  996.                                         ],
  997.                                     ],
  998.                                     [
  999.                                         [
  1000.                                             "text" => "رد رسید - عدم دریافت مبلغ (پایا - شبا - پل)",
  1001.                                             "callback_data" => "/dcPChMa(p-{$match[1]})|(e-{$this->botUser->getUrlSlug()})|(u-{$this->botUser->getUserId()})"
  1002.                                         ],
  1003.                                     ]
  1004.                                 ]
  1005.                             );
  1006.                             $this->sendMessage($this->botUser->getUserId(), 'رسید برای ادمین ارسال شد منتظر تایید آن باشید');
  1007.                         } catch (Exception $exception) {
  1008.                             $this->notificationService->exception($exception);
  1009. //                                    $this->telegram->exception($exception);
  1010. //                            $this->bot('sendMessage', [
  1011. //                                'chat_id' => $this->chatId,
  1012. //                                'text' => 'تصویر به درستی ارسال نشد مجدد اقدام فرمایید',
  1013. //                                'reply_markup' => $this->backMenu
  1014. //                            ], $bot->getToken());
  1015. //                            $objectUser->setStep('');
  1016.                         }
  1017.                         $this->getDoctrine()->getManager()->flush();
  1018.                     } else {
  1019.                         $this->sendMessage($this->botUser->getUserId(), 'تصویر ارسال کن');
  1020.                     }
  1021.                 }
  1022.             } else {
  1023.                 $this->sendInlineKeyboard($chatId$this->messages['welcome'], $this->getStartButtons($chatId));
  1024.             }
  1025.         }
  1026.     }
  1027.     private function handleCallbackQuery(array $callbackQueryLoggerInterface $logger)
  1028.     {
  1029.         try {
  1030.             $repo $this->getDoctrine()->getRepository(BotUser::class);
  1031.             $chatId $callbackQuery['message']['chat']['id'];
  1032.             $firstName $callbackQuery['message']['chat']['first_name'] ?? null;
  1033.             $lastName $callbackQuery['message']['chat']['last_name'] ?? null;
  1034.             $username $callbackQuery['message']['chat']['username'] ?? null;
  1035.             $khanUser $repo->findOneBy(['userId' => $chatId'bot' => $this->bot]);
  1036.             if (!$khanUser) {
  1037.                 $khanUser = new BotUser();
  1038.                 $khanUser->setBot($this->bot);
  1039.                 $khanUser->setNewServiceDetail([]);
  1040.                 $khanUser->setUserId($chatId);
  1041.             }
  1042.             $khanUser->setName($firstName ?: '');
  1043.             $khanUser->setUsername($username ?: '');
  1044.             $this->entityManager->persist($khanUser);
  1045.             $this->entityManager->flush();
  1046.             $this->botUser $khanUser;
  1047.             if ((bool)$this->bot->isForceJoinChannel() && $this->bot->getChannelUserNAme()) {
  1048.                 if (!$this->checkIfUserIsInChannel($chatId$this->channelUsername)) {
  1049.                     $this->sendInlineKeyboard($chatId'❌ برای استفاده از ربات حتما باید در کانال زیر عضو شوید:
  1050.     
  1051. ✅ بعد از اینکه عضو شدید روی دکمه عضو شدم بزنید'
  1052.                         PHP_EOL .
  1053.                         $this->channelUsername, [
  1054.                             [
  1055.                                 [
  1056.                                     'text' => '✅عضو شدم✅',
  1057.                                     'callback_data' => '/start'
  1058.                                 ]
  1059.                             ]
  1060.                         ]
  1061.                     );
  1062.                     die;
  1063.                 }
  1064.             }
  1065.             if (!$this->bot->isActive() || !$this->bot->getOwner()->isActive()) {
  1066.                 $this->sendMessage($this->botUser->getUserId(),
  1067.                     'ربات فعال نمیباشد با پشتیبانی در ارتباط باشید....'
  1068.                 );
  1069.                 die;
  1070.             }
  1071.         } catch (Exception $exception) {
  1072.             $this->notificationService->exception($exception);
  1073.             $this->telegramBot->exception($exception);
  1074.         }
  1075.         try {
  1076.             $callbackQueryId $callbackQuery['id'];
  1077.             $data $callbackQuery['data'] ?? '';
  1078.             $chatId $callbackQuery['message']['chat']['id'];
  1079.             $messageId $callbackQuery['message']['message_id'];
  1080. //            $logger->info('Handling callback query', ['data' => $data]);
  1081.             $messageId $callbackQuery['message']['message_id'] ?? null// Get message ID
  1082.             if ($data == '/start') {
  1083.                 if ($this->botUser) {
  1084.                     $this->botUser->setNewServiceDetail([]);
  1085.                     $this->botUser->setStep(null);
  1086.                     $this->entityManager->flush();
  1087.                 }
  1088.                 if ($messageId) {
  1089.                     $this->editAsInlineMessage($chatId$messageId$this->messages['welcome'], $this->getStartButtons($this->botUser->getUserId()));
  1090.                 } else {
  1091.                     $this->sendInlineKeyboard($chatId$this->messages['welcome'], $this->getStartButtons($this->botUser->getUserId()));
  1092.                 }
  1093.             } elseif (str_contains($data'arz-')) {
  1094.                 $price str_replace('arz-'''$data);
  1095.                 $setting = new SettingService($this->entityManager);
  1096.                 $arzplusObject = new ArzDigital();
  1097.                 $arzRef uniqid('ref-'false);
  1098.                 $arzplusObject->setRefId($arzRef);
  1099.                 $arzPrice number_format(($price / ($setting->getSetting('tron_sell'))), 1);
  1100.                 $arzplusObject->setPrice(($price));
  1101.                 $arzplusObject->setBot($this->bot);
  1102.                 $arzplusObject->setBotUserOwner($this->botUser);
  1103.                 $arzplusObject->setIsPaid(0);
  1104.                 $this->entityManager->persist($arzplusObject);
  1105.                 $this->entityManager->flush();
  1106.                 $arzWallet $this->bot->getWalletAddress();
  1107.                 $arzUrl "https://arzplus24.com/fastpay?network=trx&symbol=TRX&amount=$arzPrice&address=$arzWallet&callback=https://tehransub.website/callback/arz-plus/{$this->bot->getTitle()}/{$this->botUser->getUserId()}?refId={$arzplusObject->getRefId()}";
  1108.                 if ($messageId) {
  1109.                     $this->editAsInlineMessage($chatId$messageId'فاکتور ایجاد شد لطفا با زدن دکمه پرداخت و پرداخت در صرافی کیف پول خود را شارژ فرمایید',
  1110.                         [
  1111.                             [
  1112.                                 [
  1113.                                     'text' => 'پرداخت',
  1114.                                     "url" => $arzUrl
  1115.                                 ],
  1116.                             ],
  1117.                             [
  1118.                                 [
  1119.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1120.                                     'callback_data' => '/start'
  1121.                                 ]
  1122.                             ],
  1123.                         ]
  1124.                     );
  1125.                 } else {
  1126.                     $this->sendInlineKeyboard($chatId'فاکتور ایجاد شد لطفا با زدن دکمه پرداخت و پرداخت در صرافی کیف پول خود را شارژ فرمایید'
  1127.                         ,
  1128.                         [
  1129.                             [
  1130.                                 [
  1131.                                     'text' => 'پرداخت',
  1132.                                     "url" => $arzUrl
  1133.                                 ],
  1134.                             ],
  1135.                             [
  1136.                                 [
  1137.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1138.                                     'callback_data' => '/start'
  1139.                                 ]
  1140.                             ],
  1141.                         ]
  1142.                     );
  1143.                 }
  1144.             } elseif ($data == '/startd') {
  1145.                 $this->sendInlineKeyboard($chatId$this->messages['welcome'], $this->getStartButtons($this->botUser->getUserId()));
  1146.             } elseif ($data == 'buyService') {
  1147.                 if ($messageId) {
  1148.                     $this->editAsInlineMessage($chatId$messageId$this->messages['chooseServiceType'], $this->serviceTypesButtons);
  1149.                 } else {
  1150.                     $this->sendInlineKeyboard($chatId$this->messages['chooseServiceType'], $this->serviceTypesButtons);
  1151.                 }
  1152.             } elseif (in_array($data, [
  1153.                 'v2rayServiceUnLimited',
  1154.                 'ciscoServiceUnLimited',
  1155.                 'openServiceUnLimited',
  1156.                 'v2rayService',
  1157.                 'ciscoService',
  1158.                 'openService',
  1159.                 'vipService',
  1160.             ], true)) {
  1161.                 $serviceArray $this->botUser->getNewServiceDetail() ?: [];
  1162.                 $serviceArray['serviceType'] = $data;
  1163.                 $this->botUser->setNewServiceDetail($serviceArray);
  1164.                 $this->entityManager->flush();
  1165.                 $this->handleNextQuestion($messageId);
  1166.             } elseif ($data == '1User' || $data == '2User' || $data == '3User' || $data == '4User' || $data == '5User') {
  1167.                 $serviceArray $this->botUser->getNewServiceDetail() ?: [];
  1168.                 $serviceArray['users'] = str_replace('User'''$data);
  1169.                 $this->botUser->setNewServiceDetail($serviceArray);
  1170.                 $this->entityManager->flush();
  1171.                 $this->handleNextQuestion($messageId);
  1172.             } elseif (str_contains($data'country-')) {
  1173.                 $serviceArray $this->botUser->getNewServiceDetail() ?: [];
  1174.                 $serviceArray['country'] = str_replace('country-'''$data);
  1175.                 $this->botUser->setNewServiceDetail($serviceArray);
  1176.                 $this->entityManager->flush();
  1177.                 $this->handleNextQuestion($messageId);
  1178.             } elseif ($data == '30Days' || $data == '60Days' || $data == '90Days' || $data == '180Days' || $data == '365Days') {
  1179.                 $serviceArray $this->botUser->getNewServiceDetail() ?: [];
  1180.                 $serviceArray['serviceTime'] = str_replace('Days'''$data);
  1181.                 $this->botUser->setNewServiceDetail($serviceArray);
  1182.                 $this->entityManager->flush();
  1183.                 $this->handleNextQuestion($messageId);
  1184.             } elseif (preg_match('/^pslug-[a-f0-9]+$/'$data$matches)) {
  1185.                 $plan $this->getDoctrine()->getRepository(BotPlan::class)->findOneBy(['urlSlug' => str_replace('pslug-''slug-'$data)]);
  1186.                 switch ($this->botUser->getNewServiceDetail()['serviceType']) {
  1187.                     case 'openServiceUnLimited':
  1188.                     case 'ciscoServiceUnLimited':
  1189.                     case 'v2rayServiceUnLimited':
  1190.                         $thisText 'شما در حال خرید سرویس زیر می باشید : '
  1191.                             PHP_EOL .
  1192.                             "\u{200F}" .
  1193.                             $plan->getPlan()->__toString()
  1194.                             . PHP_EOL .
  1195.                             "\u{200F}" .
  1196.                             number_format($plan->getPrice(), 0) . ' تومان ';
  1197.                         break;
  1198.                     case 'vipService':
  1199.                     case 'ciscoService':
  1200.                     case 'openService':
  1201.                     case 'v2rayService':
  1202.                         $thisText 'شما در حال خرید سرویس زیر می باشید : '
  1203.                             PHP_EOL .
  1204.                             "\u{200F}" .
  1205.                             $this->formatSizeUnits($plan->getPlan()->getSize()) .
  1206.                             ' - ' .
  1207.                             number_format($plan->getPrice(), 0) . ' تومان ';
  1208.                         break;
  1209.                 }
  1210.                 if ($messageId) {
  1211.                     $this->editAsInlineMessage($chatId$messageId$thisText,
  1212.                         [
  1213.                             [
  1214.                                 [
  1215.                                     'text' => 'تایید میکنم',
  1216.                                     'callback_data' => 'y' $plan->getUrlSlug()
  1217.                                 ]
  1218.                             ],
  1219.                             [
  1220.                                 [
  1221.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1222.                                     'callback_data' => '/start'
  1223.                                 ]
  1224.                             ],
  1225.                         ]
  1226.                     );
  1227.                 } else {
  1228.                     $this->sendInlineKeyboard($chatId$thisText,
  1229.                         [
  1230.                             [
  1231.                                 [
  1232.                                     'text' => 'تایید میکنم',
  1233.                                     'callback_data' => 'y' $plan->getUrlSlug()
  1234.                                 ]
  1235.                             ],
  1236.                             [
  1237.                                 [
  1238.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1239.                                     'callback_data' => '/start'
  1240.                                 ]
  1241.                             ],
  1242.                         ]
  1243.                     );
  1244.                 }
  1245.             } elseif (preg_match('/^yslug-[a-f0-9]+$/'$data$matches)) {
  1246.                 $plan $this->getDoctrine()->getRepository(BotPlan::class)->findOneBy(['urlSlug' => str_replace('yslug-''slug-'$data), 'active' => 1]);
  1247.                 if (!$plan) {
  1248.                     if ($messageId) {
  1249.                         $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته انتخابی برای فروش فعال نیست', [
  1250.                             [
  1251.                                 [
  1252.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1253.                                     'callback_data' => '/start'
  1254.                                 ]
  1255.                             ],
  1256.                         ]);
  1257.                     } else {
  1258.                         $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته انتخابی برای فروش فعال نیست', [
  1259.                             [
  1260.                                 [
  1261.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1262.                                     'callback_data' => '/start'
  1263.                                 ]
  1264.                             ],
  1265.                         ]);
  1266.                     }
  1267.                 }
  1268.                 $price $plan->getPrice();
  1269.                 if ($this->botUser->getWallet() >= $price || $this->botUser->getUserId() == $this->bot->getOwnerUserId()) {
  1270.                     $this->createService($this->botUser$this->bot$plan$messageId);
  1271.                     if ($this->bot->getOwner()->getWallet() < 100000) {
  1272.                         $this->sendMessage($this->bot->getOwnerUserId(), "مدیریت محترم موجودی کیف پول شما در سایت کمتر از صد هزار تومان می باشد برای جلوگیری از توقف فروش در ربات لطفا فورا کیف پول خود را در سایت شارژ فرمایید");
  1273.                     }
  1274.                 } else {
  1275.                     if ($messageId) {
  1276.                         $this->editAsInlineMessage($chatId$messageId'موجودی کیف پول شما برای خرید کافی نیست لطفا ابتدا کیف پول خود را شارژ فرمایید'
  1277.                             PHP_EOL .
  1278.                             'موجودی فعلی شما : ' .
  1279.                             number_format($this->botUser->getWallet()) .
  1280.                             ' تومان' .
  1281.                             PHP_EOL .
  1282.                             'موجودی مورد نیاز : ' .
  1283.                             number_format($price) .
  1284.                             ' تومان', [
  1285.                             [
  1286.                                 [
  1287.                                     "text" => "💰 شارژ کیف پول",
  1288.                                     "callback_data" => "charge"
  1289.                                 ],
  1290.                             ],
  1291.                             [
  1292.                                 [
  1293.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1294.                                     'callback_data' => '/start'
  1295.                                 ]
  1296.                             ],
  1297.                         ]);
  1298.                     } else {
  1299.                         $this->sendInlineKeyboard($chatId'موجودی کیف پول شما برای خرید کافی نیست لطفا ابتدا کیف پول خود را شارژ فرمایید'
  1300.                             PHP_EOL .
  1301.                             'موجودی فعلی شما : ' .
  1302.                             number_format($this->botUser->getWallet()) .
  1303.                             ' تومان' .
  1304.                             PHP_EOL .
  1305.                             'موجودی مورد نیاز : ' .
  1306.                             number_format($price) .
  1307.                             ' تومان'
  1308.                             , [
  1309.                                 [
  1310.                                     [
  1311.                                         "text" => "💰 شارژ کیف پول",
  1312.                                         "callback_data" => "charge"
  1313.                                     ],
  1314.                                 ],
  1315.                                 [
  1316.                                     [
  1317.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1318.                                         'callback_data' => '/start'
  1319.                                     ]
  1320.                                 ],
  1321.                             ]);
  1322.                     }
  1323.                 }
  1324.             } elseif ($data == 'myServices') {
  1325. //                TODO MYSERVICES
  1326.                 die;
  1327. //                $userServiceRepo = $this->getDoctrine()->getRepository(UserService::class);
  1328.                 $myServicesKeyboard = [];
  1329.                 $myServicesKeyboard[] = [
  1330.                     [
  1331.                         'text' => 'دریافت کانفیگ',
  1332.                         'callback_data' => '#'
  1333.                     ],
  1334.                     [
  1335.                         'text' => 'وضعیت',
  1336.                         'callback_data' => '#'
  1337.                     ],
  1338.                     [
  1339.                         'text' => 'حجم مانده : ',
  1340.                         'callback_data' => '#'
  1341.                     ],
  1342.                     [
  1343.                         'text' => 'روز مانده : ',
  1344.                         'callback_data' => '#'
  1345.                     ],
  1346.                     [
  1347.                         'text' => 'سرویس : ',
  1348.                         'callback_data' => '#'
  1349.                     ],
  1350.                     [
  1351.                         'text' => 'شناسه سرویس : ',
  1352.                         'callback_data' => '#'
  1353.                     ]
  1354.                 ];
  1355.                 $myServicesKeyboard[] = [
  1356.                     [
  1357.                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1358.                         'callback_data' => '/start'
  1359.                     ]
  1360.                 ];
  1361.                 $myServicesKeyboard[] = [
  1362.                     [
  1363.                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1364.                         'callback_data' => '/start'
  1365.                     ]
  1366.                 ];
  1367.                 if ($messageId) {
  1368.                     $this->editAsInlineMessage($chatId$messageId'لیست سرویس های دریافتی شما : ',
  1369.                         $myServicesKeyboard);
  1370.                 } else {
  1371.                     $this->sendInlineKeyboard($chatId'لیست سرویس های دریافتی شما : ',
  1372.                         $myServicesKeyboard);
  1373.                 }
  1374.             } elseif ($data == 'accounting') {
  1375.                 $transactions $this->getDoctrine()->getRepository(BotTransaction::class)->findBy(['botUser' => $this->botUser'bot' => $this->bot]);
  1376.                 if (count($transactions) > 0) {
  1377.                     $text 'آخرین تراکنش های شما :‌' PHP_EOL;
  1378.                     foreach ($transactions as $transaction) {
  1379.                         $text $text .
  1380.                             $transaction->getDescription()
  1381.                             . PHP_EOL;
  1382.                     }
  1383.                     if ($messageId) {
  1384.                         $this->editAsInlineMessage($chatId$messageId$text, [
  1385.                             [
  1386.                                 [
  1387.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1388.                                     'callback_data' => '/start'
  1389.                                 ]
  1390.                             ],
  1391.                         ]);
  1392.                     } else {
  1393.                         $this->sendInlineKeyboard($chatId$text, [
  1394.                             [
  1395.                                 [
  1396.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1397.                                     'callback_data' => '/start'
  1398.                                 ]
  1399.                             ],
  1400.                         ]);
  1401.                     }
  1402.                 } else {
  1403.                     if ($messageId) {
  1404.                         $this->editAsInlineMessage($chatId$messageId'تراکنشی برای کیف پول شما هنوز بوجود نیامده است', [
  1405.                             [
  1406.                                 [
  1407.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1408.                                     'callback_data' => '/start'
  1409.                                 ]
  1410.                             ],
  1411.                         ]);
  1412.                     } else {
  1413.                         $this->sendInlineKeyboard($chatId'تراکنشی برای کیف پول شما هنوز بوجود نیامده است', [
  1414.                             [
  1415.                                 [
  1416.                                     'text' => '⬆️ بازگشت به صفحه اصلی',
  1417.                                     'callback_data' => '/start'
  1418.                                 ]
  1419.                             ],
  1420.                         ]);
  1421.                     }
  1422.                 }
  1423.             } elseif ($data == 'charge') {
  1424.                 if ($messageId) {
  1425.                     $this->editAsInlineMessage($chatId$messageId'روش شارژ را انتخاب فرمایید'
  1426.                         ,
  1427.                         $this->paymentButtons
  1428.                     );
  1429.                 } else {
  1430.                     $this->sendInlineKeyboard($chatId'روش شارژ را انتخاب فرمایید',
  1431.                         $this->paymentButtons
  1432.                     );
  1433.                 }
  1434.             } elseif ($data == 'chargeCardToCard') {
  1435.                 $this->botUser->setStep('waitForPrice');
  1436.                 $this->getDoctrine()->getManager()->flush();
  1437.                 $this->sendMessage($this->botUser->getUserId(), 'لطفا مبلغ مورد نیاز را وارد فرمایید - حداقل ' number_format($this->bot->getMinimumCardToCard(), 0));
  1438.             } elseif ($data == 'chargeOnline') {
  1439.                 if ($this->bot->getWalletAddress()) {
  1440.                     if ($messageId) {
  1441.                         $this->editAsInlineMessage($chatId$messageId'مبلغ مدنظر برای شارژ را انتخاب فرمایید'
  1442.                             PHP_EOL .
  1443.                             'پس از پرداخت حساب شما تا ۳ دقیقه بعد شارژ خواهد شد لطفا پس از پرداخت صبور باشید....'
  1444.                             ,
  1445.                             [
  1446.                                 [
  1447.                                     [
  1448.                                         'text' => number_format(300000) . ' تومان',
  1449.                                         'callback_data' => 'arz-300000'
  1450.                                     ],
  1451.                                     [
  1452.                                         'text' => number_format(200000) . ' تومان',
  1453.                                         'callback_data' => 'arz-200000'
  1454.                                     ],
  1455.                                     [
  1456.                                         'text' => number_format(100000) . ' تومان',
  1457.                                         'callback_data' => 'arz-100000'
  1458.                                     ],
  1459.                                 ],
  1460.                                 [
  1461.                                     [
  1462.                                         'text' => number_format(600000) . ' تومان',
  1463.                                         'callback_data' => 'arz-600000'
  1464.                                     ],
  1465.                                     [
  1466.                                         'text' => number_format(500000) . ' تومان',
  1467.                                         'callback_data' => 'arz-500000'
  1468.                                     ],
  1469.                                     [
  1470.                                         'text' => number_format(400000) . ' تومان',
  1471.                                         'callback_data' => 'arz-400000'
  1472.                                     ],
  1473.                                 ],
  1474.                                 [
  1475.                                     [
  1476.                                         'text' => number_format(900000) . ' تومان',
  1477.                                         'callback_data' => 'arz-900000'
  1478.                                     ],
  1479.                                     [
  1480.                                         'text' => number_format(800000) . ' تومان',
  1481.                                         'callback_data' => 'arz-800000'
  1482.                                     ],
  1483.                                     [
  1484.                                         'text' => number_format(700000) . ' تومان',
  1485.                                         'callback_data' => 'arz-700000'
  1486.                                     ],
  1487.                                 ],
  1488.                                 [
  1489.                                     [
  1490.                                         'text' => 'یک میلیون تومان',
  1491.                                         'callback_data' => 'arz-1000000'
  1492.                                     ],
  1493.                                 ],
  1494.                                 [
  1495.                                     [
  1496.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1497.                                         'callback_data' => '/start'
  1498.                                     ]
  1499.                                 ],
  1500.                             ]
  1501.                         );
  1502.                     } else {
  1503.                         $this->sendInlineKeyboard($chatId'مبلغ مدنظر برای شارژ را انتخاب فرمایید'
  1504.                             PHP_EOL .
  1505.                             'پس از پرداخت حساب شما تا ۳ دقیقه بعد شارژ خواهد شد لطفا پس از پرداخت صبور باشید....'
  1506.                             ,
  1507.                             [
  1508.                                 [
  1509.                                     [
  1510.                                         'text' => number_format(300000) . ' تومان',
  1511.                                         'callback_data' => 'arz-300000'
  1512.                                     ],
  1513.                                     [
  1514.                                         'text' => number_format(200000) . ' تومان',
  1515.                                         'callback_data' => 'arz-200000'
  1516.                                     ],
  1517.                                     [
  1518.                                         'text' => number_format(100000) . ' تومان',
  1519.                                         'callback_data' => 'arz-100000'
  1520.                                     ],
  1521.                                 ],
  1522.                                 [
  1523.                                     [
  1524.                                         'text' => number_format(600000) . ' تومان',
  1525.                                         'callback_data' => 'arz-600000'
  1526.                                     ],
  1527.                                     [
  1528.                                         'text' => number_format(500000) . ' تومان',
  1529.                                         'callback_data' => 'arz-500000'
  1530.                                     ],
  1531.                                     [
  1532.                                         'text' => number_format(400000) . ' تومان',
  1533.                                         'callback_data' => 'arz-400000'
  1534.                                     ],
  1535.                                 ],
  1536.                                 [
  1537.                                     [
  1538.                                         'text' => number_format(900000) . ' تومان',
  1539.                                         'callback_data' => 'arz-900000'
  1540.                                     ],
  1541.                                     [
  1542.                                         'text' => number_format(800000) . ' تومان',
  1543.                                         'callback_data' => 'arz-800000'
  1544.                                     ],
  1545.                                     [
  1546.                                         'text' => number_format(700000) . ' تومان',
  1547.                                         'callback_data' => 'arz-700000'
  1548.                                     ],
  1549.                                 ],
  1550.                                 [
  1551.                                     [
  1552.                                         'text' => 'یک میلیون تومان',
  1553.                                         'callback_data' => 'arz-1000000'
  1554.                                     ],
  1555.                                 ],
  1556.                                 [
  1557.                                     [
  1558.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1559.                                         'callback_data' => '/start'
  1560.                                     ]
  1561.                                 ],
  1562.                             ]
  1563.                         );
  1564.                     }
  1565.                 } else {
  1566.                     if ($messageId) {
  1567.                         $this->editAsInlineMessage($chatId$messageId'درگاه پرداخت آنلاین غیر فعال میباشد برای فعالسازی با پشتیبانی در ارتباط باشید'
  1568.                             ,
  1569.                             [
  1570.                                 [
  1571.                                     [
  1572.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1573.                                         'callback_data' => '/start'
  1574.                                     ]
  1575.                                 ],
  1576.                             ]
  1577.                         );
  1578.                     } else {
  1579.                         $this->sendInlineKeyboard($chatId'درگاه پرداخت آنلاین غیر فعال میباشد برای فعالسازی با پشتیبانی در ارتباط باشید',
  1580.                             [
  1581.                                 [
  1582.                                     [
  1583.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1584.                                         'callback_data' => '/start'
  1585.                                     ]
  1586.                                 ],
  1587.                             ]
  1588.                         );
  1589.                     }
  1590.                 }
  1591.             } elseif ($data == 'testService') {
  1592.                 if ($messageId) {
  1593.                     $this->editAsInlineMessage($chatId$messageId'نیاز به تست کدام پروتکل دارید؟',
  1594.                         $this->testServiceTypesButtons
  1595.                     );
  1596.                 } else {
  1597.                     $this->sendInlineKeyboard($chatId'نیاز به تست کدام پروتکل دارید؟',
  1598.                         $this->testServiceTypesButtons
  1599.                     );
  1600.                 }
  1601.             } elseif (
  1602.                 $data == 'tes-v2rayService' ||
  1603.                 $data == 'tes-v2rayServiceUnLimited' ||
  1604.                 $data == 'tes-ciscoService' ||
  1605.                 $data == 'tes-ciscoServiceUnLimited' ||
  1606.                 $data == 'tes-openService' ||
  1607.                 $data == 'tes-openServiceUnLimited' ||
  1608.                 $data == 'tes-vipService'
  1609.             ) {
  1610.                 $this->botUser->setGotTest(1);
  1611.                 $this->entityManager->flush();
  1612.                 $this->createTestService($messageId$data);
  1613.             } elseif (preg_match('/^d-\d+$/'$data$matches)) {
  1614.                 $khanServiceId str_replace('d-'''$data);
  1615.             } elseif (preg_match('/\/acPCh\(p-(\d+)\)\|\(e-([^|]+)\)\|\(u-(\d+)\)/'$data$matches)) {
  1616.                 $this->getDoctrine()->getManager()->flush();
  1617.                 $price $matches[1];
  1618.                 $slug $matches[2];
  1619.                 $userId $matches[3];
  1620.                 $customerBotUserObject $this->getDoctrine()->getRepository(BotUser::class)->findOneBy(['userId' => $userId'bot' => $this->bot]);
  1621.                 $this->sendInlineKeyboard($this->botUser->getUserId(), 'شارژ کیف پول تایید شد', [
  1622.                     [
  1623.                         [
  1624.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  1625.                             'callback_data' => '/start'
  1626.                         ]
  1627.                     ],
  1628.                 ]);
  1629.                 $this->sendInlineKeyboard($customerBotUserObject->getUserId(), 'شارژ کیف پول تایید شد',
  1630.                     [
  1631.                         [
  1632.                             [
  1633.                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1634.                                 'callback_data' => '/start'
  1635.                             ]
  1636.                         ],
  1637.                     ]
  1638.                 );
  1639.                 $increaseTransaction = new BotTransaction();
  1640.                 $increaseTransaction->setBot($this->bot);
  1641.                 $increaseTransaction->setBotUser($customerBotUserObject);
  1642.                 $increaseTransaction->setPrice($price);
  1643.                 $increaseTransaction->setDescription('شارژ کیف پول');
  1644.                 $increaseTransaction->setBeforeWallet($customerBotUserObject->getWallet());
  1645.                 $increaseTransaction->setAfterWallet((int)$customerBotUserObject->getWallet() + (int)$price);
  1646.                 $increaseTransaction->setType(1);
  1647.                 $this->entityManager->persist($increaseTransaction);
  1648.                 $this->entityManager->flush();
  1649.                 $customerBotUserObject->setWallet((int)$customerBotUserObject->getWallet() + (int)$price);
  1650.                 if ($messageId) {
  1651.                     $this->deleteMessage($this->bot->getOwnerUserId(), $messageId);
  1652.                 }
  1653.                 $customerBotUserObject->setStep('');
  1654.                 $this->getDoctrine()->getManager()->flush();
  1655.             } elseif (preg_match('/\/dcPCh\(p-(\d+)\)\|\(e-([^|]+)\)\|\(u-(\d+)\)/'$data$matches)) {
  1656.                 $this->getDoctrine()->getManager()->flush();
  1657.                 $price $matches[1];
  1658.                 $slug $matches[2];
  1659.                 $userId $matches[3];
  1660.                 $customerBotUserObject $this->getDoctrine()->getRepository(BotUser::class)->findOneBy(['userId' => $userId'bot' => $this->bot]);
  1661.                 $this->sendInlineKeyboard($this->botUser->getUserId(), 'شارژ کیف پول تایید نشد', [
  1662.                     [
  1663.                         [
  1664.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  1665.                             'callback_data' => '/start'
  1666.                         ]
  1667.                     ],
  1668.                 ]);
  1669.                 $this->sendInlineKeyboard($customerBotUserObject->getUserId(), 'شارژ کیف پول تایید نشد',
  1670.                     [
  1671.                         [
  1672.                             [
  1673.                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1674.                                 'callback_data' => '/start'
  1675.                             ]
  1676.                         ],
  1677.                     ]
  1678.                 );
  1679.                 if ($messageId) {
  1680.                     $this->deleteMessage($this->bot->getOwnerUserId(), $messageId);
  1681.                 }
  1682.                 $customerBotUserObject->setStep('');
  1683.                 $this->getDoctrine()->getManager()->flush();
  1684.             } else {
  1685.                 $this->sendMessage($chatId'No Action Called');
  1686.             }
  1687.             return $this->json(['res' => true]);
  1688.         } catch
  1689.         (Exception $exception) {
  1690.             $this->notificationService->exception($exception);
  1691.             $this->telegramBot->exception($exception);
  1692.         }
  1693.     }
  1694.     public function handleNextQuestion($messageId null)
  1695.     {
  1696. //        $this->sendMessage($this->adminId  , $this->botUser->getNewServiceDetail()['serviceType']);die;
  1697.         switch ($this->botUser->getNewServiceDetail()) {
  1698.             case (!isset($this->botUser->getNewServiceDetail()['serviceType']) || ($this->botUser->getNewServiceDetail()['serviceType']) == ''):
  1699.                 if ($messageId) {
  1700.                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServiceType'], $this->serviceTypesButtons);
  1701.                 } else {
  1702.                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServiceType'], $this->serviceTypesButtons);
  1703.                 }
  1704.                 break;
  1705.             case (
  1706.                 (str_contains($this->botUser->getNewServiceDetail()['serviceType'], 'UnLimited'))
  1707.                 &&
  1708.                 (!isset($this->botUser->getNewServiceDetail()['country']) || ($this->botUser->getNewServiceDetail()['country']) == '')
  1709.             ):
  1710.                 $countryKeyboard = [];
  1711.                 switch ($this->botUser->getNewServiceDetail()['serviceType']) {
  1712.                     case 'v2rayServiceUnLimited':
  1713.                         $servers $this->getDoctrine()->getRepository(Server::class)->findBy(['active' => 1]);
  1714.                         foreach ($servers as $server) {
  1715.                             $countryKeyboard[] = [
  1716.                                 [
  1717.                                     'text' => $this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle(),
  1718.                                     'callback_data' => 'country-' $server->getCountry()->getCode()
  1719.                                 ]
  1720.                             ];
  1721.                         }
  1722.                         break;
  1723.                     case 'openServiceUnLimited':
  1724.                         $servers $this->getDoctrine()->getRepository(\App\Entity\VPN\OpenVPN\Server::class)->findBy(['active' => 1]);
  1725.                         foreach ($servers as $server) {
  1726.                             $countryKeyboard[] = [
  1727.                                 [
  1728.                                     'text' => $this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle(),
  1729.                                     'callback_data' => 'country-' $server->getCountry()->getCode()
  1730.                                 ]
  1731.                             ];
  1732.                         }
  1733.                         break;
  1734.                     case 'ciscoServiceUnLimited':
  1735.                         $servers $this->getDoctrine()->getRepository(\App\Entity\VPN\OcServ\Server::class)->findBy(['active' => 1]);
  1736.                         foreach ($servers as $server) {
  1737.                             $countryKeyboard[] = [
  1738.                               [
  1739.                                   'text' => $this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle(),
  1740.                                   'callback_data' => 'country-' $server->getCountry()->getCode()
  1741.                               ]
  1742.                             ];
  1743.                         }
  1744.                         break;
  1745.                 }
  1746.                 $countryKeyboard[] = [
  1747.                     [
  1748.                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1749.                         'callback_data' => '/start'
  1750.                     ]
  1751.                 ];
  1752.                 if ($messageId) {
  1753.                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServiceLocation'], $countryKeyboard);
  1754.                 } else {
  1755.                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServiceLocation'], $countryKeyboard);
  1756.                 }
  1757.                 break;
  1758.             case (!isset($this->botUser->getNewServiceDetail()['users']) || ($this->botUser->getNewServiceDetail()['users']) == ''):
  1759.                 if ($messageId) {
  1760.                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServiceUsers'], $this->serviceUsersButtons);
  1761.                 } else {
  1762.                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServiceUsers'], $this->serviceUsersButtons);
  1763.                 }
  1764.                 break;
  1765.             case (!isset($this->botUser->getNewServiceDetail()['serviceTime']) || ($this->botUser->getNewServiceDetail()['serviceTime']) == ''):
  1766.                 if ($messageId) {
  1767.                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServiceTime'], $this->serviceTimeButtons);
  1768.                 } else {
  1769.                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServiceTime'], $this->serviceTimeButtons);
  1770.                 }
  1771.                 break;
  1772.             case (
  1773.                 isset($this->botUser->getNewServiceDetail()['serviceType']) &&
  1774.                 isset($this->botUser->getNewServiceDetail()['users']) &&
  1775.                 isset($this->botUser->getNewServiceDetail()['serviceTime'])
  1776.             ):
  1777.                 $botPlansRepo $this->getDoctrine()->getRepository(BotPlan::class);
  1778.                 try {
  1779.                     switch ($this->botUser->getNewServiceDetail()['serviceType']) {
  1780.                         case 'v2rayService':
  1781.                             $plans $botPlansRepo->findBy([
  1782.                                 'active' => 1,
  1783.                                 'bot' => $this->bot,
  1784.                             ], []);
  1785.                             foreach ($plans as $key => $plan) {
  1786.                                 if ($plan->getPlan() && $plan->getPlan()->isActive()) {
  1787.                                     if ($plan->getPlan()->getProtocol() !== 'v2ray' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getUsers() !== (int)$this->botUser->getNewServiceDetail()['users']) {
  1788.                                         unset($plans[$key]);
  1789.                                     }
  1790.                                     if ($plan->getPlan()->getProtocol() !== 'v2ray' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getDays() !== (int)$this->botUser->getNewServiceDetail()['serviceTime']) {
  1791.                                         unset($plans[$key]);
  1792.                                     }
  1793.                                 } else {
  1794.                                     unset($plans[$key]);
  1795.                                 }
  1796.                             }
  1797.                             $plansKeyboard = [];
  1798.                             foreach ($plans as $plan) {
  1799.                                 $plansKeyboard[] = [
  1800.                                     [
  1801.                                         'text' =>
  1802.                                             "\u{200F}" .
  1803.                                             $this->formatSizeUnits($plan->getPlan()->getSize()) .
  1804.                                             ' - ' .
  1805.                                             number_format($plan->getPrice(), 0) . ' تومان ',
  1806.                                         'callback_data' => 'p' $plan->getUrlSlug()
  1807.                                     ]
  1808.                                 ];
  1809.                             }
  1810.                             if (count($plans) < 1) {
  1811.                                 if ($messageId) {
  1812.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  1813.                                         [
  1814.                                             [
  1815.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1816.                                                 'callback_data' => '/start'
  1817.                                             ]
  1818.                                         ],
  1819.                                     ]);
  1820.                                 } else {
  1821.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  1822.                                         [
  1823.                                             [
  1824.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1825.                                                 'callback_data' => '/start'
  1826.                                             ]
  1827.                                         ],
  1828.                                     ]);
  1829.                                 }
  1830.                             } else {
  1831.                                 $plansKeyboard[] = [
  1832.                                     [
  1833.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1834.                                         'callback_data' => '/start'
  1835.                                     ]
  1836.                                 ];
  1837.                                 if ($messageId) {
  1838.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServicePlan'], $plansKeyboard);
  1839.                                 } else {
  1840.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServicePlan'], $plansKeyboard);
  1841.                                 }
  1842.                             }
  1843.                             break;
  1844.                         case 'v2rayServiceUnLimited':
  1845.                             $plans $botPlansRepo->findBy([
  1846.                                 'active' => 1,
  1847.                                 'bot' => $this->bot,
  1848.                             ], []);
  1849.                             foreach ($plans as $key => $plan) {
  1850.                                 if ($plan->getPlan() && $plan->getPlan()->isActive()) {
  1851.                                     if ($plan->getPlan()->getProtocol() !== 'v2ray' || $plan->getPlan()->getServiceType() !== 'unlimited' || (int)$plan->getPlan()->getUsers() !== (int)$this->botUser->getNewServiceDetail()['users']) {
  1852.                                         unset($plans[$key]);
  1853.                                     }
  1854.                                     if ($plan->getPlan()->getProtocol() !== 'v2ray' || $plan->getPlan()->getServiceType() !== 'unlimited' || (int)$plan->getPlan()->getDays() !== (int)$this->botUser->getNewServiceDetail()['serviceTime']) {
  1855.                                         unset($plans[$key]);
  1856.                                     }
  1857.                                 } else {
  1858.                                     unset($plans[$key]);
  1859.                                 }
  1860.                             }
  1861.                             $plansKeyboard = [];
  1862.                             foreach ($plans as $plan) {
  1863.                                 $plansKeyboard[] = [
  1864.                                     [
  1865.                                         'text' =>
  1866.                                             "\u{200F}" .
  1867.                                             number_format($plan->getPrice(), 0) . ' تومان ',
  1868.                                         'callback_data' => 'p' $plan->getUrlSlug()
  1869.                                     ]
  1870.                                 ];
  1871.                             }
  1872.                             if (count($plans) < 1) {
  1873.                                 if ($messageId) {
  1874.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  1875.                                         [
  1876.                                             [
  1877.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1878.                                                 'callback_data' => '/start'
  1879.                                             ]
  1880.                                         ],
  1881.                                     ]);
  1882.                                 } else {
  1883.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  1884.                                         [
  1885.                                             [
  1886.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1887.                                                 'callback_data' => '/start'
  1888.                                             ]
  1889.                                         ],
  1890.                                     ]);
  1891.                                 }
  1892.                             } else {
  1893.                                 $plansKeyboard[] = [
  1894.                                     [
  1895.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1896.                                         'callback_data' => '/start'
  1897.                                     ]
  1898.                                 ];
  1899.                                 if ($messageId) {
  1900.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServicePlan'], $plansKeyboard);
  1901.                                 } else {
  1902.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServicePlan'], $plansKeyboard);
  1903.                                 }
  1904.                             }
  1905.                             break;
  1906.                         case 'openService':
  1907.                             $plans $botPlansRepo->findBy([
  1908.                                 'active' => 1,
  1909.                                 'bot' => $this->bot,
  1910.                             ], []);
  1911.                             foreach ($plans as $key => $plan) {
  1912.                                 if ($plan->getPlan() && $plan->getPlan()->isActive()) {
  1913.                                     if ($plan->getPlan()->getProtocol() !== 'open' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getUsers() !== (int)$this->botUser->getNewServiceDetail()['users']) {
  1914.                                         unset($plans[$key]);
  1915.                                     }
  1916.                                     if ($plan->getPlan()->getProtocol() !== 'open' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getDays() !== (int)$this->botUser->getNewServiceDetail()['serviceTime']) {
  1917.                                         unset($plans[$key]);
  1918.                                     }
  1919.                                 } else {
  1920.                                     unset($plans[$key]);
  1921.                                 }
  1922.                             }
  1923.                             $plansKeyboard = [];
  1924.                             foreach ($plans as $plan) {
  1925.                                 $plansKeyboard[] = [
  1926.                                     [
  1927.                                         'text' =>
  1928.                                             "\u{200F}" .
  1929.                                             $this->formatSizeUnits($plan->getPlan()->getSize()) .
  1930.                                             ' - ' .
  1931.                                             number_format($plan->getPrice(), 0) . ' تومان ',
  1932.                                         'callback_data' => 'p' $plan->getUrlSlug()
  1933.                                     ]
  1934.                                 ];
  1935.                             }
  1936.                             if (count($plans) < 1) {
  1937.                                 if ($messageId) {
  1938.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  1939.                                         [
  1940.                                             [
  1941.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1942.                                                 'callback_data' => '/start'
  1943.                                             ]
  1944.                                         ],
  1945.                                     ]);
  1946.                                 } else {
  1947.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  1948.                                         [
  1949.                                             [
  1950.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  1951.                                                 'callback_data' => '/start'
  1952.                                             ]
  1953.                                         ],
  1954.                                     ]);
  1955.                                 }
  1956.                             } else {
  1957.                                 $plansKeyboard[] = [
  1958.                                     [
  1959.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  1960.                                         'callback_data' => '/start'
  1961.                                     ]
  1962.                                 ];
  1963.                                 if ($messageId) {
  1964.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServicePlan'], $plansKeyboard);
  1965.                                 } else {
  1966.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServicePlan'], $plansKeyboard);
  1967.                                 }
  1968.                             }
  1969.                             break;
  1970.                         case 'openServiceUnLimited':
  1971.                             $plans $botPlansRepo->findBy([
  1972.                                 'active' => 1,
  1973.                                 'bot' => $this->bot,
  1974.                             ], []);
  1975.                             foreach ($plans as $key => $plan) {
  1976.                                 if ($plan->getPlan() && $plan->getPlan()->isActive()) {
  1977.                                     if ($plan->getPlan()->getProtocol() !== 'open' || $plan->getPlan()->getServiceType() !== 'unlimited' || (int)$plan->getPlan()->getUsers() !== (int)$this->botUser->getNewServiceDetail()['users']) {
  1978.                                         unset($plans[$key]);
  1979.                                     }
  1980.                                     if ($plan->getPlan()->getProtocol() !== 'open' || $plan->getPlan()->getServiceType() !== 'unlimited' || (int)$plan->getPlan()->getDays() !== (int)$this->botUser->getNewServiceDetail()['serviceTime']) {
  1981.                                         unset($plans[$key]);
  1982.                                     }
  1983.                                 } else {
  1984.                                     unset($plans[$key]);
  1985.                                 }
  1986.                             }
  1987.                             $plansKeyboard = [];
  1988.                             foreach ($plans as $plan) {
  1989.                                 $plansKeyboard[] = [
  1990.                                     [
  1991.                                         'text' =>
  1992.                                             "\u{200F}" .
  1993.                                             number_format($plan->getPrice(), 0) . ' تومان ',
  1994.                                         'callback_data' => 'p' $plan->getUrlSlug()
  1995.                                     ]
  1996.                                 ];
  1997.                             }
  1998.                             if (count($plans) < 1) {
  1999.                                 if ($messageId) {
  2000.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2001.                                         [
  2002.                                             [
  2003.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2004.                                                 'callback_data' => '/start'
  2005.                                             ]
  2006.                                         ],
  2007.                                     ]);
  2008.                                 } else {
  2009.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2010.                                         [
  2011.                                             [
  2012.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2013.                                                 'callback_data' => '/start'
  2014.                                             ]
  2015.                                         ],
  2016.                                     ]);
  2017.                                 }
  2018.                             } else {
  2019.                                 $plansKeyboard[] = [
  2020.                                     [
  2021.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  2022.                                         'callback_data' => '/start'
  2023.                                     ]
  2024.                                 ];
  2025.                                 if ($messageId) {
  2026.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServicePlan'], $plansKeyboard);
  2027.                                 } else {
  2028.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServicePlan'], $plansKeyboard);
  2029.                                 }
  2030.                             }
  2031.                             break;
  2032.                         case 'ciscoService':
  2033.                             $plans $botPlansRepo->findBy([
  2034.                                 'active' => 1,
  2035.                                 'bot' => $this->bot,
  2036.                             ], []);
  2037.                             foreach ($plans as $key => $plan) {
  2038.                                 if ($plan->getPlan() && $plan->getPlan()->isActive()) {
  2039.                                     if ($plan->getPlan()->getProtocol() !== 'ocserv' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getUsers() !== (int)$this->botUser->getNewServiceDetail()['users']) {
  2040.                                         unset($plans[$key]);
  2041.                                     }
  2042.                                     if ($plan->getPlan()->getProtocol() !== 'ocserv' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getDays() !== (int)$this->botUser->getNewServiceDetail()['serviceTime']) {
  2043.                                         unset($plans[$key]);
  2044.                                     }
  2045.                                 } else {
  2046.                                     unset($plans[$key]);
  2047.                                 }
  2048.                             }
  2049.                             $plansKeyboard = [];
  2050.                             foreach ($plans as $plan) {
  2051.                                 $plansKeyboard[] = [
  2052.                                     [
  2053.                                         'text' =>
  2054.                                             "\u{200F}" .
  2055.                                             $this->formatSizeUnits($plan->getPlan()->getSize()) .
  2056.                                             ' - ' .
  2057.                                             number_format($plan->getPrice(), 0) . ' تومان ',
  2058.                                         'callback_data' => 'p' $plan->getUrlSlug()
  2059.                                     ]
  2060.                                 ];
  2061.                             }
  2062.                             if (count($plans) < 1) {
  2063.                                 if ($messageId) {
  2064.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2065.                                         [
  2066.                                             [
  2067.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2068.                                                 'callback_data' => '/start'
  2069.                                             ]
  2070.                                         ],
  2071.                                     ]);
  2072.                                 } else {
  2073.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2074.                                         [
  2075.                                             [
  2076.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2077.                                                 'callback_data' => '/start'
  2078.                                             ]
  2079.                                         ],
  2080.                                     ]);
  2081.                                 }
  2082.                             } else {
  2083.                                 $plansKeyboard[] = [
  2084.                                     [
  2085.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  2086.                                         'callback_data' => '/start'
  2087.                                     ]
  2088.                                 ];
  2089.                                 if ($messageId) {
  2090.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServicePlan'], $plansKeyboard);
  2091.                                 } else {
  2092.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServicePlan'], $plansKeyboard);
  2093.                                 }
  2094.                             }
  2095.                             break;
  2096.                         case 'ciscoServiceUnLimited':
  2097.                             $plans $botPlansRepo->findBy([
  2098.                                 'active' => 1,
  2099.                                 'bot' => $this->bot,
  2100.                             ], []);
  2101.                             foreach ($plans as $key => $plan) {
  2102.                                 if ($plan->getPlan() && $plan->getPlan()->isActive()) {
  2103.                                     if ($plan->getPlan()->getProtocol() !== 'ocserv' || $plan->getPlan()->getServiceType() !== 'unlimited' || (int)$plan->getPlan()->getUsers() !== (int)$this->botUser->getNewServiceDetail()['users']) {
  2104.                                         unset($plans[$key]);
  2105.                                     }
  2106.                                     if ($plan->getPlan()->getProtocol() !== 'ocserv' || $plan->getPlan()->getServiceType() !== 'unlimited' || (int)$plan->getPlan()->getDays() !== (int)$this->botUser->getNewServiceDetail()['serviceTime']) {
  2107.                                         unset($plans[$key]);
  2108.                                     }
  2109.                                 } else {
  2110.                                     unset($plans[$key]);
  2111.                                 }
  2112.                             }
  2113.                             $plansKeyboard = [];
  2114.                             foreach ($plans as $plan) {
  2115.                                 $plansKeyboard[] = [
  2116.                                     [
  2117.                                         'text' =>
  2118.                                             "\u{200F}" .
  2119.                                             number_format($plan->getPrice(), 0) . ' تومان ',
  2120.                                         'callback_data' => 'p' $plan->getUrlSlug()
  2121.                                     ]
  2122.                                 ];
  2123.                             }
  2124.                             if (count($plans) < 1) {
  2125.                                 if ($messageId) {
  2126.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2127.                                         [
  2128.                                             [
  2129.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2130.                                                 'callback_data' => '/start'
  2131.                                             ]
  2132.                                         ],
  2133.                                     ]);
  2134.                                 } else {
  2135.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2136.                                         [
  2137.                                             [
  2138.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2139.                                                 'callback_data' => '/start'
  2140.                                             ]
  2141.                                         ],
  2142.                                     ]);
  2143.                                 }
  2144.                             } else {
  2145.                                 $plansKeyboard[] = [
  2146.                                     [
  2147.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  2148.                                         'callback_data' => '/start'
  2149.                                     ]
  2150.                                 ];
  2151.                                 if ($messageId) {
  2152.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServicePlan'], $plansKeyboard);
  2153.                                 } else {
  2154.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServicePlan'], $plansKeyboard);
  2155.                                 }
  2156.                             }
  2157.                             break;
  2158.                         case 'vipService':
  2159.                             $plans $botPlansRepo->findBy([
  2160.                                 'active' => 1,
  2161.                                 'bot' => $this->bot,
  2162.                             ], []);
  2163.                             foreach ($plans as $key => $plan) {
  2164.                                 if ($plan->getPlan() && $plan->getPlan()->isActive()) {
  2165.                                     if ($plan->getPlan()->getProtocol() !== 'vip' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getUsers() !== (int)$this->botUser->getNewServiceDetail()['users']) {
  2166.                                         unset($plans[$key]);
  2167.                                     }
  2168.                                     if ($plan->getPlan()->getProtocol() !== 'vip' || $plan->getPlan()->getServiceType() !== 'sized' || (int)$plan->getPlan()->getDays() !== (int)$this->botUser->getNewServiceDetail()['serviceTime']) {
  2169.                                         unset($plans[$key]);
  2170.                                     }
  2171.                                 } else {
  2172.                                     unset($plans[$key]);
  2173.                                 }
  2174.                             }
  2175.                             $plansKeyboard = [];
  2176.                             foreach ($plans as $plan) {
  2177.                                 $plansKeyboard[] = [
  2178.                                     [
  2179.                                         'text' =>
  2180.                                             "\u{200F}" .
  2181.                                             $this->formatSizeUnits($plan->getPlan()->getSize()) .
  2182.                                             ' - ' .
  2183.                                             number_format($plan->getPrice(), 0) . ' تومان ',
  2184.                                         'callback_data' => 'p' $plan->getUrlSlug()
  2185.                                     ]
  2186.                                 ];
  2187.                             }
  2188.                             if (count($plans) < 1) {
  2189.                                 if ($messageId) {
  2190.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2191.                                         [
  2192.                                             [
  2193.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2194.                                                 'callback_data' => '/start'
  2195.                                             ]
  2196.                                         ],
  2197.                                     ]);
  2198.                                 } else {
  2199.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), 'بسته ای برای فروش با این مشخصات تعریف نشده است', [
  2200.                                         [
  2201.                                             [
  2202.                                                 'text' => '⬆️ بازگشت به صفحه اصلی',
  2203.                                                 'callback_data' => '/start'
  2204.                                             ]
  2205.                                         ],
  2206.                                     ]);
  2207.                                 }
  2208.                             } else {
  2209.                                 $plansKeyboard[] = [
  2210.                                     [
  2211.                                         'text' => '⬆️ بازگشت به صفحه اصلی',
  2212.                                         'callback_data' => '/start'
  2213.                                     ]
  2214.                                 ];
  2215.                                 if ($messageId) {
  2216.                                     $this->editAsInlineMessage($this->botUser->getUserId(), $messageId$this->messages['chooseServicePlan'], $plansKeyboard);
  2217.                                 } else {
  2218.                                     $this->sendInlineKeyboard($this->botUser->getUserId(), $this->messages['chooseServicePlan'], $plansKeyboard);
  2219.                                 }
  2220.                             }
  2221.                             break;
  2222.                     }
  2223.                 } catch (Exception $exception) {
  2224.                     $this->notificationService->exception($exception);
  2225.                     $this->sendMessage($this->adminId$exception->getMessage());
  2226.                     die;
  2227.                 }
  2228.                 break;
  2229.         }
  2230.     }
  2231.     public function formatSizeUnits($bytes): string
  2232.     {
  2233.         if ($bytes >= 1073741824) {
  2234.             $bytes number_format($bytes 10737418242) . ' گیگابایت ';
  2235.         } elseif ($bytes >= 1048576) {
  2236.             $bytes number_format($bytes 10485762) . ' MB';
  2237.         } elseif ($bytes >= 1024) {
  2238.             $bytes number_format($bytes 10242) . ' KB';
  2239.         } elseif ($bytes 1) {
  2240.             $bytes $bytes ' bytes';
  2241.         } elseif ($bytes == 1) {
  2242.             $bytes $bytes ' byte';
  2243.         } else {
  2244.             $bytes '0 bytes';
  2245.         }
  2246.         return $bytes;
  2247.     }
  2248.     private function checkIfUserIsInChannel(string $chatIdstring $channelUsername): bool
  2249.     {
  2250.         $url sprintf(
  2251.             'https://api.telegram.org/bot%s/getChatMember',
  2252.             $this->token // Replace with your bot token
  2253.         );
  2254.         $payload = [
  2255.             'chat_id' => $channelUsername// Channel's username or ID
  2256.             'user_id' => $chatId// User's chat ID
  2257.         ];
  2258.         $response $this->sendRequest($url$payload);
  2259.         $responseData json_decode($responsetrue);
  2260.         // Check if the user is a member or admin (you can also check for other statuses)
  2261.         if (isset($responseData['ok']) && $responseData['ok'] === true) {
  2262.             $status $responseData['result']['status'];
  2263.             return in_array($status, ['member''administrator''creator']);
  2264.         }
  2265.         return false// Return false if the user is not in the channel or an error occurs
  2266.     }
  2267.     private function handleCampaign(string|null $textstring $chatIdLoggerInterface $logger): void
  2268.     {
  2269.         if ($text) {
  2270.             $campaign $this->getDoctrine()->getRepository(BotCampaign::class)->findOneBy(['bot' => $this->bot'title' => $text]);
  2271.             if (!$campaign) {
  2272.                 $campaign = new BotCampaign();
  2273.                 $campaign->setBot($this->bot);
  2274.                 $campaign->setTitle($text);
  2275.             }
  2276.             $this->getDoctrine()->getManager()->persist($campaign);
  2277.             $this->getDoctrine()->getManager()->flush();
  2278.             $this->botUser->setCampaign($campaign);
  2279.             $this->getDoctrine()->getManager()->flush();
  2280.         }
  2281.     }
  2282.     private function handleConnectMessage(string|null $textstring $chatIdLoggerInterface $logger): void
  2283.     {
  2284.         if ($text) {
  2285.             $agent $this->getDoctrine()->getManager()->getRepository(User::class)->findOneBy([
  2286.                 'id' => $text,
  2287.                 'active' => 1
  2288.             ]);
  2289.             if (!$agent) {
  2290.                 $this->sendMessage($chatId'لینک اتصال به ربات منقضی شده است لطفا مجددا از پنل لینک اتصال دریافت فرمایید');
  2291.                 die;
  2292.             }
  2293.             if (!$this->getDoctrine()->getManager()->getRepository(Transaction::class)->findOneBy(['owner' => $agent'increaseType' => 'connectTelegram'])) {
  2294.                 $oldExistTelegram $this->getDoctrine()->getRepository(User::class)->getOldExistTelegramUser($this->botUser->getUserId());
  2295.                 $oldExistIncrease $this->getDoctrine()->getRepository(Transaction::class)->findOneBy(['owner' => $agent'increaseType' => 'connectTelegram']);
  2296.                 if (!$oldExistIncrease && !$oldExistTelegram) {
  2297. //                    $this->panelTrasnactionService->createTransaction($agent, 12000, 'هدیه اتصال به تلگرام و دریافت تست', 1, 0, null, 0, null, 'connectTelegram');
  2298.                     $agent->setGiftWallet($agent->getGiftWallet() + 100000);
  2299.                     $this->entityManager->flush();
  2300.                 }
  2301.             }
  2302.             $agent->setConnectedTelegramUserId(([
  2303.                 'userId' => $this->botUser->getUserId(),
  2304.                 'username' => $this->botUser->getUsername() ?? '',
  2305.                 'name' => $this->botUser->getName() ?? ''
  2306.             ]));
  2307.             $this->entityManager->flush();
  2308.             $this->sendMessage($chatId,
  2309.                 $agent->getEmail() . PHP_EOL .
  2310.                 $agent->getFirstName() . ' ' $agent->getLastName() . ' عزیز' .
  2311.                 PHP_EOL .
  2312.                 'از این پس تمامی اعلانات مربوطه از این طریق به اطلاع شما خواهد رسید'
  2313.             );
  2314.             $oldExistTelegram $this->getDoctrine()->getRepository(User::class)->getOldExistTelegramUser($this->botUser->getUserId());
  2315.             if ($oldExistTelegram) {
  2316.                 $this->sendMessage($chatId,
  2317.                     'این حساب تلگرام قبلا به حساب نمایندگی دیگری متصل شده و هدیه تست دریافت کرده است'
  2318.                 );
  2319.             }
  2320.         } else {
  2321.             $this->sendMessage($this->botUser->getUserId(), 'اتصال انجام نشد مجددا از طریق پنل نمایندگی اقدام فرمایید....');
  2322.             die;
  2323.         }
  2324.     }
  2325.     private function handleEditedMessage(array $editedMessageLoggerInterface $logger): void
  2326.     {
  2327.         $logger->info('Handling edited message', ['edited_message' => $editedMessage]);
  2328.         // Process the edited message
  2329.     }
  2330.     private function handleInlineQuery(array $inlineQueryLoggerInterface $logger): void
  2331.     {
  2332.         $logger->info('Handling inline query', ['inline_query' => $inlineQuery]);
  2333.         // Process the inline query
  2334.     }
  2335.     private function handleChannelPost(array $channelPostLoggerInterface $logger): void
  2336.     {
  2337.         $logger->info('Handling channel post', ['channel_post' => $channelPost]);
  2338. //        $this->sendMessage($channelPost['chat']['id'], $channelPost['text']);
  2339.         // Process the channel post
  2340.     }
  2341.     private function handleEditedChannelPost(array $editedChannelPostLoggerInterface $logger): void
  2342.     {
  2343.         $logger->info('Handling edited channel post', ['edited_channel_post' => $editedChannelPost]);
  2344.         // Process the edited channel post
  2345.     }
  2346.     private function handlePoll(array $pollLoggerInterface $logger): void
  2347.     {
  2348.         $logger->info('Handling poll', ['poll' => $poll]);
  2349.         // Process the poll
  2350.     }
  2351.     private function handlePollAnswer(array $pollAnswerLoggerInterface $logger): void
  2352.     {
  2353.         $logger->info('Handling poll answer', ['poll_answer' => $pollAnswer]);
  2354.         // Process the poll answer
  2355.     }
  2356.     private function handleMyChatMember(array $myChatMemberLoggerInterface $logger): void
  2357.     {
  2358.         $logger->info('Handling my chat member', ['my_chat_member' => $myChatMember]);
  2359.         // Process the my_chat_member update
  2360.     }
  2361.     private function handleChatMember(array $chatMemberLoggerInterface $logger): void
  2362.     {
  2363.         $logger->info('Handling chat member update', ['chat_member' => $chatMember]);
  2364.         // Extract relevant data from the chat_member update
  2365.         $userId $chatMember['user']['id'];  // The user ID of the chat member
  2366.         $status $chatMember['status'];  // The status of the user in the channel
  2367.         // Check if the user has left the channel
  2368.         if ($status === 'left') {
  2369.             $this->sendMessage($userId'شما از کانال خارج شدید برای دریافت اطلاعیه بر روس سفارشات خود یا تخفیف ها لطفا مجددا عضو کانال شوید.'
  2370.                 PHP_EOL .
  2371.                 $this->channelUsername
  2372.             );
  2373.         }
  2374.     }
  2375.     public function makeUserTransaction($price$type$description$user null)
  2376.     {
  2377.         $transactionObject = new Transaction();
  2378.         $transactionObject->setPrice($price);
  2379.         $transactionObject->setDescription($description);
  2380.         $transactionObject->setType($type);
  2381.         if ($user) {
  2382.             $mainUser $user;
  2383.         } else {
  2384.             $mainUser $this->botUser;
  2385.         }
  2386.         $transactionObject->setOwner($mainUser);
  2387.         $transactionObject->setBeforeWallet($mainUser->getWallet());
  2388.         if ($type) {
  2389.             $transactionObject->setAfterWallet($mainUser->getWallet() + $price);
  2390.             $mainUser->setWallet($mainUser->getWallet() + $price);
  2391.         } else {
  2392.             $transactionObject->setAfterWallet($mainUser->getWallet() - $price);
  2393.             $mainUser->setWallet($mainUser->getWallet() - $price);
  2394.         }
  2395.         $this->entityManager->persist($transactionObject);
  2396.         $this->entityManager->flush();
  2397.         return true;
  2398.     }
  2399.     private function sendMessage(string $chatIdstring $text$markdown nullbool $silent false): void
  2400.     {
  2401.         $url sprintf(
  2402.             'https://api.telegram.org/bot%s/sendMessage',
  2403.             $this->token // Replace with your bot token
  2404.         );
  2405.         $payload = [
  2406.             'chat_id' => $chatId,
  2407.             'text' => $this->beautifyText($text),
  2408.             'disable_notification' => $silent// Set to true for silent messages
  2409.         ];
  2410.         if ($markdown) {
  2411.             $payload['parse_mode'] = $markdown;
  2412.         }
  2413.         $this->sendRequest($url$payload);
  2414.     }
  2415.     private function sendMessageRaw(string $chatIdstring $text$markdown nullbool $silent false): void
  2416.     {
  2417.         $url sprintf(
  2418.             'https://api.telegram.org/bot%s/sendMessage',
  2419.             $this->token // Replace with your bot token
  2420.         );
  2421.         $payload = [
  2422.             'chat_id' => $chatId,
  2423.             'text' => ($text),
  2424.             'disable_notification' => $silent// Set to true for silent messages
  2425.         ];
  2426.         if ($markdown) {
  2427.             $payload['parse_mode'] = $markdown;
  2428.         }
  2429.         $this->sendRequest($url$payload);
  2430.     }
  2431.     private function answerCallbackQuery(string $callbackQueryIdstring $text): void
  2432.     {
  2433.         $url sprintf(
  2434.             'https://api.telegram.org/bot%s/answerCallbackQuery',
  2435.             $this->token
  2436.         );
  2437.         $payload = [
  2438.             'callback_query_id' => $callbackQueryId,
  2439.             'text' => $text,
  2440.             'show_alert' => true// Set to true to show an alert popup
  2441.         ];
  2442.         $this->sendRequest($url$payload);
  2443.     }
  2444.     private function sendInlineKeyboard(string $chatIdstring $text, array $keyborad$parseMode null): void
  2445.     {
  2446.         $url sprintf(
  2447.             'https://api.telegram.org/bot%s/sendMessage',
  2448.             $this->token
  2449.         );
  2450.         $payload = [
  2451.             'chat_id' => $chatId,
  2452.             'text' => $this->beautifyText($text),
  2453.             'parse_mode' => $parseMode,
  2454.             'reply_markup' => json_encode([
  2455.                 'inline_keyboard' =>
  2456.                     $keyborad,
  2457.             ]),
  2458.         ];
  2459.         if ($parseMode) {
  2460.             $payload['parse_mode'] = $parseMode;
  2461.         }
  2462.         $this->sendRequest($url$payload);
  2463.     }
  2464.     public function editAsInlineMessage(string $chatIdstring $messageIdstring $text, array $keyborad)
  2465.     {
  2466.         $url sprintf(
  2467.             'https://api.telegram.org/bot%s/editMessageText',
  2468.             $this->token
  2469.         );
  2470.         $payload = [
  2471.             'chat_id' => $chatId,
  2472.             'text' => $this->beautifyText($text),
  2473.             'message_id' => $messageId,
  2474.             'reply_markup' => json_encode([
  2475.                 'inline_keyboard' =>
  2476.                     $keyborad,
  2477.             ]),
  2478.         ];
  2479.         $this->sendRequest($url$payload);
  2480.     }
  2481.     private function deleteMessage(string $chatIdint $messageId): void
  2482.     {
  2483.         $url sprintf(
  2484.             'https://api.telegram.org/bot%s/deleteMessage',
  2485.             $this->token
  2486.         );
  2487.         $payload = [
  2488.             'chat_id' => $chatId,
  2489.             'message_id' => $messageId,
  2490.         ];
  2491.         $this->sendRequest($url$payload);
  2492.     }
  2493.     private function sendRequest(string $url, array $payload)
  2494.     {
  2495.         $ch curl_init($url);
  2496.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2497.         curl_setopt($chCURLOPT_POSTtrue);
  2498.         curl_setopt($chCURLOPT_POSTFIELDS$payload);
  2499.         $response curl_exec($ch);
  2500.         if (curl_errno($ch)) {
  2501.             // Log or handle the error
  2502.             throw new Exception('Curl error: ' curl_error($ch));
  2503.         }
  2504.         curl_close($ch);
  2505.         return $response// Return the response for further processing
  2506.     }
  2507.     public function createTestService($messageId null$data)
  2508.     {
  2509.         if ($this->entityManager->getRepository(Service::class)->findOneBy(['creatorBot' => $this->bot'botUser' => $this->botUser])) {
  2510. //        if (false) {
  2511.             if ($messageId) {
  2512.                 $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'شما قبل تست سرویس ها را به شکل مولتی پروتکل را دریافت کرده اید', [
  2513.                     [
  2514.                         [
  2515.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  2516.                             'callback_data' => '/start'
  2517.                         ]
  2518.                     ],
  2519.                 ]);
  2520.             } else {
  2521.                 $this->sendInlineKeyboard($this->botUser->getUserId(), 'شما قبل تست سرویس ها را به شکل مولتی پروتکل را دریافت کرده اید', [
  2522.                     [
  2523.                         [
  2524.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  2525.                             'callback_data' => '/start'
  2526.                         ]
  2527.                     ],
  2528.                 ]);
  2529.             }
  2530.         } else {
  2531.             $testPlan $this->getDoctrine()->getRepository(Plan::class)->findOneBy([
  2532.                 'protocol' => 'vip',
  2533.                 'serviceType' => 'sized',
  2534.                 'days' => 1,
  2535.                 'users' => 1
  2536.             ]);
  2537.             $this->deleteMessage($this->botUser->getUserId(), $messageId);
  2538.             $countryArray $this->botUser->getNewServiceDetail()['country'] ?? 'all';
  2539.             $service $this->createServiceInService($testPlan, [
  2540.                 'clientId' => $this->service->getFreeClientId(),
  2541.                 'username' => $this->botUser->getUserId(),
  2542.                 'password' => $this->botUser->getUserId(),
  2543.                 'note' => ''
  2544.             ], $this->botUser$countryArray);
  2545.             $newDomain str_replace('tehransub.website' 'tehrannet.org' $this->brandDomain) ;
  2546.             $caption =
  2547.                 PHP_EOL .
  2548.                 "سرویس شما با موفقیت ایجاد شد لطفا از طریق لینک زیر اطلاعات سرویس را دریافت کنید" .
  2549.                 PHP_EOL .
  2550.                 "{$newDomain}/vpn/servcie-panel/no-password/{$service->getId()}.
  2551.                 PHP_EOL .
  2552.                 'تمامی اپلیکیشن ها برای دانلود آموزش ها برای اتصال و اطلاعات سرویس در لینک بالا می باشند پس از مشاهده اطلاعات در صورت وجود مشکل یا سوال پشتیبانی در خدمت شماست...'
  2553.                 PHP_EOL;
  2554.             $startPrice $testPlan->getPrice();
  2555. //            foreach ($bot->getOwner()->getUserTrace() as $email) {
  2556. //                $thisUser = $this->getDoctrine()->getRepository(User::class)->findOneBy(['email' => $email]);
  2557. //                $startPrice = $startPrice + (($startPrice * $thisUser->getInterestRate()) / 100);
  2558. //            }
  2559.             $description "خرید سرویس ربات {$this->bot->getTitle()}
  2560.         نام کاربر : 
  2561.         {$this->botUser->getName()} - 
  2562.         نام کاربری تلگرام : 
  2563.         {$this->botUser->getUsername()}
  2564.         بسته : 
  2565.         تست
  2566.         ";
  2567.             if ($service->getPlan()->hasV2ray()) {
  2568.                 $imgUrl "{$this->brandDomain}/qr/code?data={$this->brandDomain}/service/{$service->getId()}/subscription-url";
  2569.                 $this->sendPhoto(
  2570.                     $this->botUser->getUserId(),
  2571.                     $imgUrl,
  2572.                     $caption .
  2573.                     PHP_EOL .
  2574.                     'لینک سابسکریپشن افزودن کانفیگ ها (ٰV2ray) : ' .
  2575.                     PHP_EOL .
  2576.                     "{$this->brandDomain}/service/{$service->getId()}/subscription-url"
  2577.                 );
  2578.             } else {
  2579.                 $this->sendMessage($this->botUser->getUserId(), $caption);
  2580.             }
  2581.         }
  2582.     }
  2583.     private function sendPhoto($chatIdstring $photostring $caption$keyboard null$beautify true)
  2584.     {
  2585.         $url sprintf(
  2586.             'https://api.telegram.org/bot%s/sendPhoto',
  2587.             $this->token // Replace with your bot token
  2588.         );
  2589.         if (!$keyboard) {
  2590.             $keyboard = [
  2591.                 [
  2592.                     [
  2593.                         'text' => '⬆️ بازگشت به صفحه اصلی',
  2594.                         'callback_data' => '/startd'
  2595.                     ]
  2596.                 ]
  2597.             ];
  2598.         }
  2599.         if ($beautify) {
  2600.             $text $this->beautifyText($caption);
  2601.         } else {
  2602.             $text $caption;
  2603.         }
  2604.         $payload = [
  2605.             'chat_id' => $chatId,
  2606.             'photo' => $photo,
  2607.             'caption' => $text,
  2608.             'parse_mode' => 'HTML'// Enables bold, italic, etc.
  2609.             'reply_markup' => json_encode([
  2610.                 'inline_keyboard' => $keyboard,
  2611.             ])
  2612.         ];
  2613.         $this->sendRequest($url$payload);
  2614.     }
  2615.     public function countryCodeToFlag($countryCode)
  2616.     {
  2617.         // Convert country code to uppercase
  2618.         $countryCode strtoupper($countryCode);
  2619.         // Offset between uppercase ASCII and regional indicator symbols
  2620.         $offset 127397;
  2621.         // Convert each character of the country code to its flag emoji equivalent
  2622.         $flagEmoji '';
  2623.         for ($i 0$i strlen($countryCode); $i++) {
  2624.             $flagEmoji .= $this->emoji_convert_unicode(ord($countryCode[$i]) + $offset);
  2625.         }
  2626.         return $flagEmoji;
  2627.     }
  2628.     public function emoji_convert_unicode($unicode)
  2629.     {
  2630.         return mb_convert_encoding('&#' intval($unicode) . ';''UTF-8''HTML-ENTITIES');
  2631.     }
  2632.     public function createService(?BotUser $objectUserBot $botBotPlan $botPlan$messageId)
  2633.     {
  2634.         $startPrice $botPlan->getPlan()->getPrice();
  2635. //                foreach ($bot->getOwner()->getUserTrace() as $email) {
  2636. //                    $thisUser = $this->getDoctrine()->getRepository(User::class)->findOneBy(['email' => $email]);
  2637. //                    $startPrice = $startPrice + (($startPrice * $thisUser->getInterestRate()) / 100);
  2638. //                }
  2639.         if ($objectUser->getWallet() < $startPrice) {
  2640.             if ($messageId) {
  2641.                 $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'موجودی کیف پول شما برای این عمل کافی نیست', [
  2642.                     [
  2643.                         [
  2644.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  2645.                             'callback_data' => '/start'
  2646.                         ]
  2647.                     ],
  2648.                 ]);
  2649.             } else {
  2650.                 $this->sendInlineKeyboard($this->botUser->getUserId(), 'موجودی کیف پول شما برای این عمل کافی نیست', [
  2651.                     [
  2652.                         [
  2653.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  2654.                             'callback_data' => '/start'
  2655.                         ]
  2656.                     ],
  2657.                 ]);
  2658.             }
  2659.         }
  2660.         if ($startPrice $bot->getOwner()->getWallet()) {
  2661.             if ($messageId) {
  2662.                 $this->editAsInlineMessage($this->botUser->getUserId(), $messageId'خطای مالی رخ داد لطفا با پشتیبانی در ارتباط باشید', [
  2663.                     [
  2664.                         [
  2665.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  2666.                             'callback_data' => '/start'
  2667.                         ]
  2668.                     ],
  2669.                 ]);
  2670.             } else {
  2671.                 $this->sendInlineKeyboard($this->botUser->getUserId(), 'خطای مالی رخ داد لطفا با پشتیبانی در ارتباط باشید', [
  2672.                     [
  2673.                         [
  2674.                             'text' => '⬆️ بازگشت به صفحه اصلی',
  2675.                             'callback_data' => '/start'
  2676.                         ]
  2677.                     ],
  2678.                 ]);
  2679.             }
  2680.             die;
  2681.         }
  2682. //                if ($bot->getOffPercent() && $bot->getOffPercent() > 0) {
  2683. //                    $costPrice = ($bot->getOffPercent() * $botPlan->getVipPlan()->getPrice()) / 100;
  2684. //                    $objectUser->setWallet($objectUser->getWallet() - ($botPlan->getVipPlan()->getPrice() - $costPrice));
  2685. //                } else {
  2686.         $objectUser->setWallet($objectUser->getWallet() - $botPlan->getPrice());
  2687. //                }
  2688.         $this->deleteMessage($this->botUser->getUserId(), $messageId);
  2689.         $selectedCountry 'all';
  2690.         if (isset($this->botUser->getNewServiceDetail()['country'])) {
  2691.             $selectedCountry $this->botUser->getNewServiceDetail()['country'];
  2692.         }
  2693.         $increaseTransaction = new BotTransaction();
  2694.         $increaseTransaction->setBot($this->bot);
  2695.         $increaseTransaction->setBotUser($this->botUser);
  2696.         $increaseTransaction->setPrice($botPlan->getPrice());
  2697.         $increaseTransaction->setDescription('خرید سرویس جدید');
  2698.         $increaseTransaction->setBeforeWallet($this->botUser->getWallet());
  2699.         $increaseTransaction->setAfterWallet((int)$this->botUser->getWallet() - (int)$botPlan->getPrice());
  2700.         $increaseTransaction->setType(0);
  2701.         $this->entityManager->persist($increaseTransaction);
  2702.         $this->entityManager->flush();
  2703.         $service $this->createServiceInService($botPlan->getPlan(), [
  2704.             'clientId' => $this->service->getFreeClientId(),
  2705.             'username' => $this->botUser->getUserId(),
  2706.             'password' => $this->botUser->getUserId(),
  2707.             'note' => ''
  2708.         ], $this->botUser$selectedCountry);
  2709.         $newDomain str_replace('tehransub.website' 'tehrannet.org' $this->brandDomain) ;
  2710.         $caption =
  2711.             PHP_EOL .
  2712.             "سرویس شما با موفقیت ایجاد شد لطفا از طریق لینک زیر اطلاعات سرویس را دریافت کنید" .
  2713.             PHP_EOL .
  2714.             "{$newDomain}/vpn/servcie-panel/no-password/{$service->getId()}.
  2715.             PHP_EOL .
  2716.             'تمامی اپلیکیشن ها برای دانلود آموزش ها برای اتصال و اطلاعات سرویس در لینک بالا می باشند پس از مشاهده اطلاعات در صورت وجود مشکل یا سوال پشتیبانی در خدمت شماست...'
  2717.             PHP_EOL;
  2718.         $agentPrice $botPlan->getPlan()->getPrice();
  2719.         $startPrice $botPlan->getPlan()->getPrice();
  2720. //            foreach ($bot->getOwner()->getUserTrace() as $email) {
  2721. //                $thisUser = $this->getDoctrine()->getRepository(User::class)->findOneBy(['email' => $email]);
  2722. //                $startPrice = $startPrice + (($startPrice * $thisUser->getInterestRate()) / 100);
  2723. //            }
  2724.         $description "خرید سرویس ربات {$bot->getTitle()}
  2725.         نام کاربر : 
  2726.         {$objectUser->getName()} - 
  2727.         نام کاربری تلگرام : 
  2728.         {$objectUser->getUsername()}
  2729.         بسته : 
  2730.         {$botPlan->getPlan()}
  2731.         ";
  2732.         $price $this->dynamicPriceCalculation->calculatePrice($this->bot->getOwner(), $botPlan->getPlan());
  2733.         $transaction $this->transactionService->createTransaction($this->bot->getOwner(), $price$description0);
  2734.         $oldPrice $botPlan->getPlan()->getPrice();
  2735.         $benefitedPrice $botPlan->getPlan()->getPrice();
  2736.         $traceArray = [];
  2737. //            foreach ($bot->getOwner()->getUserTrace() as $email) {
  2738. //                /**
  2739. //                 * @var User $thisUser
  2740. //                 */
  2741. //                $thisUser = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $email]);
  2742. //                if ($thisUser->getPresenter() !== null) {
  2743. //                    $presentor = $thisUser->getPresenter();
  2744. //                    $oldPrice = $traceArray[$presentor->getEmail()];
  2745. //                    $tempPrice = $oldPrice + (($oldPrice * $thisUser->getInterestRate()) / 100);
  2746. //                    $profit = $tempPrice - $oldPrice;
  2747. //                    $description = "سود شما از خرید کاربر واسط ";
  2748. //                    $transaction = $this->transactionService->createTransaction($thisUser->getPresenter(), $profit, $description, 1, 0, $service->getClientId(), 0, null, null, 1, 'Vip');
  2749. //                    $traceArray[$email] = $tempPrice;
  2750. //                } else {
  2751. //                    if ($thisUser->getInterestRate() !== 0) {
  2752. //                        $finPrice = $botPlan->getVipPlan()->getPrice() + (($botPlan->getVipPlan()->getPrice() * $thisUser->getInterestRate()) / 100);
  2753. //                        $traceArray[$email] = $finPrice;
  2754. //                    } else {
  2755. //                        $traceArray[$email] = $botPlan->getVipPlan()->getPrice();
  2756. //                    }
  2757. //
  2758. //                }
  2759. //            }
  2760.         if ($service->getPlan()->hasV2ray()) {
  2761.             $imgUrl "{$this->brandDomain}/qr/code?data={$this->brandDomain}/service/{$service->getId()}/subscription-url";
  2762.             $this->sendPhoto(
  2763.                 $this->botUser->getUserId(),
  2764.                 $imgUrl,
  2765.                 $caption .
  2766.                 PHP_EOL .
  2767.                 'لینک سابسکریپشن افزودن کانفیگ ها (ٰV2ray) : ' .
  2768.                 PHP_EOL .
  2769.                 "{$this->brandDomain}/service/{$service->getId()}/subscription-url"
  2770.             );
  2771.         } else {
  2772.             $this->sendMessage($this->botUser->getUserId(), $caption);
  2773.         }
  2774.         if ($bot->getThanksMessage()) {
  2775.             $this->sendMessage($this->botUser->getUserId(), $bot->getThanksMessage());
  2776.         }
  2777.     }
  2778.     public function createServiceInService(Plan $plan$dataArrayUser|BotUser $owner$country 'all'): Service
  2779.     {
  2780.         $service = new Service();
  2781.         $service->setCountry($country);
  2782.         $service->setClientId($dataArray['clientId']);
  2783.         $service->setPlan($plan);
  2784.         if ($owner instanceof User) {
  2785.             $service->setOwner($owner);
  2786.         } elseif ($owner instanceof BotUser) {
  2787.             $service->setBotUser($owner);
  2788.             $service->setCreatorBot($owner->getBot());
  2789.             $service->setOwner($owner->getBot()->getOwner());
  2790.         }
  2791.         $service->setActive(1);
  2792.         $service->setUsername($dataArray['username']);
  2793.         $service->setPassword($dataArray['password']);
  2794.         $service->setTotal($plan->getSize());
  2795.         $service->setUsed(0);
  2796.         $service->setIsEnabled(true);
  2797.         $service->setNote($dataArray['note'] ?? '');
  2798.         $service->setTotalPrice($plan->getPrice());
  2799.         $service->setPayMethod('paid');
  2800.         $this->entityManager->persist($service);
  2801.         $this->entityManager->flush();
  2802.         return $service;
  2803.     }
  2804.     #[Route('/ad-dev/{id}'name'ad_dev')]
  2805.     public function dev(BotRepository $botRepository)
  2806.     {
  2807.         $bot $botRepository->findOneBy(['title' => 'tehrannet_bot']);
  2808.         $this->bot $bot;
  2809.         $text 'واسطه هارو کم کردیم  و سعی میکنیم که کمترین قیمت رو به مشتری هامون ارائه بدیم' PHP_EOL '
  2810. پشتیبانی خیلی پیگیر و (تقریبا!) همیشه آنلاین' PHP_EOL '
  2811. قیمت سرویس نامحدود از ۸۰ هزارتومن  ' PHP_EOL '
  2812. اگه تا الان از جای  دیگه ای فیلترشکن خریدی و راضی نبودی ,بهمون این شانس رو بده , نظرتو عوض میکنیم...' PHP_EOL '
  2813. دارای سه پروتکل OPEN  , CISCO و V2RAY' PHP_EOL '
  2814. تهران نت  , از سال ۱۴۰۰' PHP_EOL '
  2815. تست رایگان داخل ربات هست و میتونید از قیمت ۱۵ هزارتومن سرویس های کم حجم رو بخرید' PHP_EOL '
  2816. '.'@tehrannetofficial
  2817. 🇩🇪🇳🇱🇮🇷 🇬🇧🇫🇮🇦🇪 🇮🇪🇪🇸🇧🇪🇹🇷🇫🇷🇵🇹 ' PHP_EOL '
  2818. 👇👇' PHP_EOL;
  2819.         $banner 'https://tehrannet.org/ad-banner.png';
  2820.         $this->sendPhoto($this->adminId$banner$text, [
  2821.             [
  2822.                 [
  2823.                     'text' => 'دریافت تست',
  2824.                     'url' => 'https://t.me/tehrannet_bot?start=utm=Gaymotion'
  2825.                 ]
  2826.             ]
  2827.         ], false);
  2828.     }
  2829.     #[Route('/telegram/agent-public-bot/webhook-neo/{id}/user-services/{userId}'name'app_telegram_agent_public_bot_web_hook_neon_user_services')]
  2830.     public function app_telegram_agent_public_bot_web_hook_neon_user_services(Request $request$id$userIdServiceRepository $serviceRepositoryLoggerInterface $loggerBotRepository $botRepositoryBotUserRepository $botUserRepository): Response
  2831.     {
  2832.         $bot $botRepository->find($id);
  2833.         if (!$bot) {
  2834.             throw new NotFoundHttpException();
  2835.         }
  2836.         $botUser $botUserRepository->findOneBy(['userId' => $userId'bot' => $bot]);
  2837.         if (!$botUser) {
  2838.             throw new NotFoundHttpException();
  2839.         }
  2840.         return $this->render('vpn/telegram-panel/my-services.html.twig', [
  2841.             'bot' => $bot,
  2842.             'user' => $botUser,
  2843.             'services' => $serviceRepository->findBy(['creatorBot' => $bot'botUser' => $botUser])
  2844.         ]);
  2845.     }
  2846.     #[Route('/telegram/agent-public-bot/webhook-neo/{id}/user-services/{userId}/{serviceId}'name'app_telegram_agent_public_bot_web_hook_neon_user_services_charge')]
  2847.     public function app_telegram_agent_public_bot_web_hook_neon_user_services_charge(ByteConvert $byteConvert Request $request,\App\Repository\VPN\OpenVPN\ServerRepository $openServerREpo\App\Repository\VPN\OcServ\ServerRepository $ocServerRepository ServerRepository $serverRepository$serviceIdServiceRepository $serviceRepository$id$userIdLoggerInterface $loggerBotRepository $botRepositoryBotUserRepository $botUserRepository): Response
  2848.     {
  2849.         $bot $botRepository->find($id);
  2850.         if (!$bot) {
  2851.             throw new NotFoundHttpException();
  2852.         }
  2853.         $botUser $botUserRepository->findOneBy(['userId' => $userId'bot' => $bot]);
  2854.         if (!$botUser) {
  2855.             throw new NotFoundHttpException();
  2856.         }
  2857.         $service $serviceRepository->findOneBy(['id' => $serviceId]);
  2858.         if (!$service) {
  2859.             throw new NotFoundHttpException();
  2860.         }
  2861. //        var_dump($user->getWallet());die;
  2862.         $formTypes = [
  2863.             'sizedVip' => LimitedVipType::class,
  2864.             'sizedV2ray' => LimitedV2rayType::class,
  2865.             'unlimitedV2ray' => UnlimitedV2rayType::class,
  2866.             'sizedOcServ' => LimitedOcServType::class,
  2867.             'unlimitedOcServ' => UnlimitedOcServType::class,
  2868.             'sizedOpen' => LimitedOpenType::class,
  2869.             'unlimitedOpen' => UnlimitedOpenType::class,
  2870.         ];
  2871.         $forms = [];
  2872.         foreach ($formTypes as $formName => $formClass) {
  2873.             switch ($formName) {
  2874.                 case 'unlimitedV2ray':
  2875.                     $locations = [];
  2876.                     foreach ($serverRepository->findBy(['active' => 1]) as $server) {
  2877.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  2878.                     }
  2879.                     $form $this->createForm($formClassnull, [
  2880.                         'clientId' => $service->getClientId(),
  2881.                         'locations' => $locations
  2882.                     ]);
  2883.                     break;
  2884.                 case 'unlimitedOcServ':
  2885.                     $locations = [];
  2886.                     foreach ($ocServerRepository->findBy(['active' => 1]) as $server) {
  2887.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  2888.                     }
  2889.                     $form $this->createForm($formClassnull, [
  2890.                         'clientId' => $service->getClientId(),
  2891.                         'locations' => $locations
  2892.                     ]);
  2893.                     break;
  2894.                 case 'unlimitedOpen':
  2895.                     $locations = [];
  2896.                     foreach ($openServerREpo->findBy(['active' => 1]) as $server) {
  2897.                         $locations[$this->countryCodeToFlag($server->getCountry()->getCode()) . $server->getCountry()->getTitle()] = $server->getCountry()->getCode();
  2898.                     }
  2899.                     $form $this->createForm($formClassnull, [
  2900.                         'clientId' => $service->getClientId(),
  2901.                         'locations' => $locations
  2902.                     ]);
  2903.                     break;
  2904.                 case 'sizedV2ray':
  2905.                 case 'sizedOpen':
  2906.                 case 'sizedOcServ':
  2907.                 case 'sizedVip':
  2908.                     $form $this->createForm($formClassnull, [
  2909.                         'clientId' => $service->getClientId()
  2910.                     ]);
  2911.                     break;
  2912.             }
  2913. //            $form = $this->createForm($formClass, null, [
  2914. //                'clientId' => $this->service->getFreeClientId()
  2915. //            ]);
  2916.             $form->remove('username');
  2917.             $form->remove('password');
  2918.             $form->remove('note');
  2919.             $form->handleRequest($request);
  2920.             switch ($formName) {
  2921.                 case 'sizedV2ray':
  2922.                 case 'sizedVip':
  2923.                 case 'unlimitedV2ray':
  2924.                 case 'sizedOcServ':
  2925.                 case 'unlimitedOcServ':
  2926.                 case 'sizedOpen':
  2927.                 case 'unlimitedOpen':
  2928.                     if ($form->isSubmitted() && $form->isValid()) {
  2929.                         $queryArray $form->getData();
  2930. //                        unset($queryArray['username']);
  2931. //                        unset($queryArray['password']);
  2932.                         $queryArray['size'] = $byteConvert->toByte($queryArray['size'] . 'GB');
  2933.                         $queryArray['active'] = 1;
  2934.                         $targetPlan $this->getDoctrine()->getRepository(Plan::class)->findOneBy($queryArray);
  2935.                         $targetPlanPrice $this->getDoctrine()->getRepository(BotPlan::class)->findOneBy([
  2936.                             'bot' => $bot,
  2937.                             'plan' => $targetPlan
  2938.                         ]);
  2939.                         if (!$targetPlanPrice) {
  2940.                             $this->addFlash('error''این بسته در حال حاضر ارائه نمیشود');
  2941.                             return $this->redirectToRoute('app_telegram_agent_public_bot_web_hook_neon_user_services_charge', [
  2942.                                 'id' => $bot->getId(),
  2943.                                 'userId' => $botUser->getUserId(),
  2944.                                 'serviceId' => $service->getId()
  2945.                             ]);
  2946.                         }
  2947. //                      TODO:Check User Interest Rate For Price
  2948.                         $buyPrice $targetPlanPrice->getPrice();
  2949.                         if ($botUser->getWallet() >= $buyPrice) {
  2950.                             $serviceData $form->getData();
  2951.                             $serviceData['clientId'] = $form->get('clientId')->getData();
  2952.                             $this->service->chargeService($service$targetPlan$serviceData);
  2953.                             $increaseTransaction = new BotTransaction();
  2954.                             $increaseTransaction->setBot($this->bot);
  2955.                             $increaseTransaction->setBotUser($botUser);
  2956.                             $increaseTransaction->setPrice($buyPrice);
  2957.                             $increaseTransaction->setDescription('تمدید سرویس');
  2958.                             $increaseTransaction->setBeforeWallet($botUser->getWallet());
  2959.                             $increaseTransaction->setAfterWallet((int)$botUser->getWallet() - (int)$buyPrice);
  2960.                             $increaseTransaction->setType(0);
  2961.                             $botUser->setWallet($botUser->getWallet() - $buyPrice);
  2962.                             $this->entityManager->persist($increaseTransaction);
  2963.                             $this->entityManager->flush();
  2964.                             $price $this->dynamicPriceCalculation->calculatePrice($bot->getOwner(), $targetPlan);
  2965.                             $this->transaction->createTransaction($bot->getOwner(), $price"تمدید سرویس {$service->getClientId()}
  2966.                             از ربات
  2967.                             ",
  2968.                                 0
  2969.                             );
  2970.                             $this->addFlash('success''سرویس مد نظر با موفقیت تمدید شد');
  2971.                         } else {
  2972.                             $this->addFlash('error''موجودی کیف پول شما کافی نمی باشد');
  2973.                         }
  2974.                         return $this->redirectToRoute('app_telegram_agent_public_bot_web_hook_neon_user_services_charge', [
  2975.                             'id' => $bot->getId(),
  2976.                             'userId' => $botUser->getUserId(),
  2977.                             'serviceId' => $service->getId(),
  2978.                         ]);
  2979.                     }
  2980.                     break;
  2981.                 default:
  2982.                     // Handle any default case if necessary
  2983.                     break;
  2984.             }
  2985.             $forms[$formName] = $form->createView();
  2986.         }
  2987.         return $this->render('vpn/telegram-panel/charge.html.twig', [
  2988.             'bot' => $bot,
  2989.             'user' => $botUser,
  2990.             'services' => $serviceRepository->findBy(['creatorBot' => $bot'botUser' => $botUser]),
  2991.             'service' => $service,
  2992.             'sizedVipForm' => $forms['sizedVip'] ?? '',
  2993.             'sizedV2rayForm' => $forms['sizedV2ray'] ?? '',
  2994.             'unlimitedV2rayForm' => $forms['unlimitedV2ray'] ?? '',
  2995.             'sizedOcServForm' => $forms['sizedOcServ'] ?? '',
  2996.             'unlimitedOcServForm' => $forms['unlimitedOcServ'] ?? '',
  2997.             'sizedOpenForm' => $forms['sizedOpen'] ?? '',
  2998.             'unlimitedOpenForm' => $forms['unlimitedOpen'] ?? '',
  2999.             'charge' => 1
  3000.         ]);
  3001.     }
  3002.     #[Route('/telegram/get-ajax-price/agent-public-bot/webhook-neo/{id}/user-services/{userId}/{serviceId}'name'app_telegram_agent_public_bot_web_hook_neon_user_services_charge_get_ajax_price')]
  3003.     public function app_telegram_agent_public_bot_web_hook_neon_user_services_charge_get_ajax_price(ByteConvert $byteConvert Request $request,\App\Repository\VPN\OpenVPN\ServerRepository $openServerREpo\App\Repository\VPN\OcServ\ServerRepository $ocServerRepository ServerRepository $serverRepository$serviceIdServiceRepository $serviceRepository$id$userIdLoggerInterface $loggerBotRepository $botRepositoryBotUserRepository $botUserRepository )
  3004.     {
  3005.         $bot $botRepository->find($id);
  3006.         if (!$bot) {
  3007.             throw new NotFoundHttpException();
  3008.         }
  3009.         $botUser $botUserRepository->findOneBy(['userId' => $userId'bot' => $bot]);
  3010.         if (!$botUser) {
  3011.             throw new NotFoundHttpException();
  3012.         }
  3013.         /**
  3014.          * @var User $user
  3015.          */
  3016.         $user $this->getUser();
  3017.         $queryArray $request->request->all();
  3018.         unset($queryArray['country']);
  3019.         unset($queryArray['password']);
  3020.         unset($queryArray['username']);
  3021.         unset($queryArray['price']);
  3022.         unset($queryArray['_token']);
  3023.         $queryArray['size'] = $byteConvert->toByte($queryArray['size'] . 'GB');
  3024.         $queryArray['active'] = 1;
  3025.         $targetPlan $this->getDoctrine()->getRepository(Plan::class)->findOneBy($queryArray);
  3026.         $targetBotPlan $this->getDoctrine()->getRepository(BotPlan::class)->findOneBy([
  3027.             'bot' => $bot,'plan' => $targetPlan]);
  3028. //        return $this->json(['res' => $queryArray]);
  3029.         if (!$targetBotPlan) {
  3030.             return $this->json(['message' => 'این بسته در حال حاضر ارائه نمیشود']);
  3031.         } else {
  3032.             return $this->json(['message' =>
  3033.                 number_format($targetBotPlan->getPrice()) .
  3034.                 ' تومان'
  3035.             ]);
  3036.         }
  3037.     }
  3038. }