Compare commits
10 Commits
e2f6d55d47
...
f8ed030081
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8ed030081 | ||
|
|
094f854a6a | ||
|
|
1570ec2d80 | ||
|
|
44e4d5e74c | ||
|
|
8970262485 | ||
|
|
a77b90658d | ||
|
|
88e791dc6b | ||
|
|
7e3521f889 | ||
|
|
d6ad779654 | ||
|
|
d026b112fb |
4
.env.example
Normal file
4
.env.example
Normal file
@@ -0,0 +1,4 @@
|
||||
TOKEN1=
|
||||
TOKEN2=
|
||||
BACKEND_URL=
|
||||
ADMIN_ID=
|
||||
73
main.py
73
main.py
@@ -4,19 +4,30 @@ from aiogram import Bot, Dispatcher, types, filters
|
||||
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, WebAppInfo
|
||||
from aiogram.fsm.state import StatesGroup, State
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from dotenv import load_dotenv
|
||||
|
||||
TOKEN = "8147952177:AAEsR2ejafoKVb_OFcm6rEJAzUt_BKiOr5A"
|
||||
# TOKEN = '7060272362:AAE2-q9smV-mr0oaMvKz-Hjt1kBet8JebuM'
|
||||
BACKEND_URL = 'https://horeca.felixits.uz/'
|
||||
bot = Bot(token=TOKEN)
|
||||
dp = Dispatcher()
|
||||
load_dotenv()
|
||||
|
||||
TOKEN1 = os.getenv("TOKEN1")
|
||||
TOKEN2 = os.getenv("TOKEN2")
|
||||
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):
|
||||
phone = 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):
|
||||
url = f"{BACKEND_URL}/api/v1/orders/supplier/{message.from_user.id}/"
|
||||
res = requests.get(url)
|
||||
@@ -39,15 +50,15 @@ async def start_handler(message: types.Message, state: FSMContext):
|
||||
await state.clear()
|
||||
|
||||
|
||||
@dp.message(CodeStates.phone)
|
||||
@dp2.message(CodeStates.phone)
|
||||
async def get_code(message: types.Message, state: FSMContext):
|
||||
phone = message.contact.phone_number
|
||||
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)
|
||||
|
||||
|
||||
@dp.message(CodeStates.full_name)
|
||||
@dp2.message(CodeStates.full_name)
|
||||
async def get_code(message: types.Message, state: FSMContext):
|
||||
full_name = message.text
|
||||
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())
|
||||
|
||||
|
||||
@dp.message(filters.Command(commands=['web_app']))
|
||||
@dp1.message(filters.Command(commands=['web_app']))
|
||||
async def start_handler(message: types.Message):
|
||||
keyboard = ReplyKeyboardMarkup(
|
||||
keyboard=[
|
||||
[KeyboardButton(
|
||||
text="Open",
|
||||
web_app=WebAppInfo(url="https://agro360.vercel.app")
|
||||
web_app=WebAppInfo(url="https://agro365.felixits.uz")
|
||||
)]
|
||||
],
|
||||
resize_keyboard=True
|
||||
)
|
||||
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 yo‘q")
|
||||
|
||||
await message.answer("Yubormoqchi bo‘lgan 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():
|
||||
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__":
|
||||
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
||||
asyncio.run(main())
|
||||
asyncio.run(main())
|
||||
@@ -16,4 +16,5 @@ pydantic_core==2.33.2
|
||||
typing-inspection==0.4.1
|
||||
typing_extensions==4.15.0
|
||||
yarl==1.20.1
|
||||
requests
|
||||
requests
|
||||
python-dotenv
|
||||
Reference in New Issue
Block a user