Compare commits

...

10 Commits

Author SHA1 Message Date
behruz-dev
f8ed030081 fix text 2025-10-06 18:04:50 +05:00
behruz-dev
094f854a6a fix 2025-09-30 18:09:38 +05:00
behruz-dev
1570ec2d80 fix 2025-09-27 18:32:25 +05:00
behruz-dev
44e4d5e74c add new feature 2025-09-27 18:27:46 +05:00
behruz-dev
8970262485 fix 2025-09-06 17:55:12 +05:00
behruz-dev
a77b90658d add: add features 2025-09-06 17:54:22 +05:00
behruz-dev
88e791dc6b change url 2025-09-05 20:50:30 +05:00
behruz-dev
7e3521f889 fix 2025-09-05 20:47:05 +05:00
behruz-dev
d6ad779654 change bot token 2025-09-05 20:44:33 +05:00
behruz-dev
d026b112fb change backend url 2025-09-04 20:01:48 +05:00
3 changed files with 66 additions and 14 deletions

4
.env.example Normal file
View File

@@ -0,0 +1,4 @@
TOKEN1=
TOKEN2=
BACKEND_URL=
ADMIN_ID=

73
main.py
View File

@@ -4,19 +4,30 @@ from aiogram import Bot, Dispatcher, types, filters
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, WebAppInfo from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, WebAppInfo
from aiogram.fsm.state import StatesGroup, State from aiogram.fsm.state import StatesGroup, State
from aiogram.fsm.context import FSMContext from aiogram.fsm.context import FSMContext
from dotenv import load_dotenv
TOKEN = "8147952177:AAEsR2ejafoKVb_OFcm6rEJAzUt_BKiOr5A" load_dotenv()
# TOKEN = '7060272362:AAE2-q9smV-mr0oaMvKz-Hjt1kBet8JebuM'
BACKEND_URL = 'https://horeca.felixits.uz/' TOKEN1 = os.getenv("TOKEN1")
bot = Bot(token=TOKEN) TOKEN2 = os.getenv("TOKEN2")
dp = Dispatcher() BACKEND_URL = os.getenv("BACKEND_URL")
ADMIN_ID = int(os.getenv("ADMIN_ID", "0"))
bot1 = Bot(token=TOKEN1)
bot2 = Bot(token=TOKEN2)
dp1 = Dispatcher()
dp2 = Dispatcher()
class CodeStates(StatesGroup): class CodeStates(StatesGroup):
phone = State() phone = State()
full_name = State() full_name = State()
class Broadcast(StatesGroup):
waiting_for_message = State()
@dp.message(filters.CommandStart())
@dp2.message(filters.CommandStart())
async def start_handler(message: types.Message, state: FSMContext): async def start_handler(message: types.Message, state: FSMContext):
url = f"{BACKEND_URL}/api/v1/orders/supplier/{message.from_user.id}/" url = f"{BACKEND_URL}/api/v1/orders/supplier/{message.from_user.id}/"
res = requests.get(url) res = requests.get(url)
@@ -39,15 +50,15 @@ async def start_handler(message: types.Message, state: FSMContext):
await state.clear() await state.clear()
@dp.message(CodeStates.phone) @dp2.message(CodeStates.phone)
async def get_code(message: types.Message, state: FSMContext): async def get_code(message: types.Message, state: FSMContext):
phone = message.contact.phone_number phone = message.contact.phone_number
await state.update_data(phone=phone) await state.update_data(phone=phone)
await message.answer('Ims Familiyangizni kirting:') await message.answer('Ism Familiyangizni kirting:')
await state.set_state(CodeStates.full_name) await state.set_state(CodeStates.full_name)
@dp.message(CodeStates.full_name) @dp2.message(CodeStates.full_name)
async def get_code(message: types.Message, state: FSMContext): async def get_code(message: types.Message, state: FSMContext):
full_name = message.text full_name = message.text
await state.update_data(full_name=full_name) await state.update_data(full_name=full_name)
@@ -66,22 +77,58 @@ async def get_code(message: types.Message, state: FSMContext):
await message.answer(res.json()) await message.answer(res.json())
@dp.message(filters.Command(commands=['web_app'])) @dp1.message(filters.Command(commands=['web_app']))
async def start_handler(message: types.Message): async def start_handler(message: types.Message):
keyboard = ReplyKeyboardMarkup( keyboard = ReplyKeyboardMarkup(
keyboard=[ keyboard=[
[KeyboardButton( [KeyboardButton(
text="Open", text="Open",
web_app=WebAppInfo(url="https://agro360.vercel.app") web_app=WebAppInfo(url="https://agro365.felixits.uz")
)] )]
], ],
resize_keyboard=True resize_keyboard=True
) )
await message.answer("Salom! Web Appni ochish uchun tugmani bosing 👇", reply_markup=keyboard) await message.answer("Salom! Web Appni ochish uchun tugmani bosing 👇", reply_markup=keyboard)
@dp1.message(filters.Command("send"))
async def start_broadcast(message: types.Message, state: FSMContext):
if message.from_user.id != ADMIN_ID:
return await message.answer("❌ Sizda ruxsat yoq")
await message.answer("Yubormoqchi bolgan xabaringizni kiriting:")
await state.set_state(Broadcast.waiting_for_message)
@dp1.message(Broadcast.waiting_for_message)
async def broadcast_message(message: types.Message, state: FSMContext):
msg = message.text
count = 0
url = f'{BACKEND_URL}/api/v1/accounts/user/list/'
res = requests.get(url)
for chat_id in res.json():
if chat_id['tg_id'] == ADMIN_ID:
continue
try:
await bot1.send_message(chat_id['tg_id'], msg)
count += 1
except Exception as e:
print(f"Xato {chat_id['tg_id']}: {e}")
await message.answer(f"{count} ta foydalanuvchiga yuborildi")
await state.clear()
async def main(): async def main():
await dp.start_polling(bot) await bot1.delete_webhook(drop_pending_updates=True)
await bot2.delete_webhook(drop_pending_updates=True)
await asyncio.gather(
dp1.start_polling(bot1),
dp2.start_polling(bot2),
)
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout) logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main()) asyncio.run(main())

View File

@@ -16,4 +16,5 @@ pydantic_core==2.33.2
typing-inspection==0.4.1 typing-inspection==0.4.1
typing_extensions==4.15.0 typing_extensions==4.15.0
yarl==1.20.1 yarl==1.20.1
requests requests
python-dotenv