Как встроить subgram?? | End Way — сообщество разработчиков и готовых решений
  • Больше материалов без ожидания и лишних условий
    Доступ к скрытым публикациям на 2 месяца, 3 месяца или навсегда. Ограничения «Команда форума» и «Личный» сохраняются.

    Сравнить варианты доступа →

    🔔 EndWay в Telegram

    Следите за новостями и релизами:
    EndWay | EndSoft

Как встроить subgram??

Node

Джун
Автор темы
5 Сен 2025
4
0
Ребят, мучаюсь с сабграмом, вроде ошибок не выдаёт в терминале, но и каналы не появляются при запуске продажи трафика, что тут не так подскажите пожалуйста


user_private.py

@user_private_router.message(Command("start"))
async def cmd_start(message: types.Message, state: FSMContext, bot: Bot):
need_subs = await send_subscription_tasks(message.from_user.id, message.chat.id, message)
if need_subs:
return
async with async_session() as session:
user = await UserRequests.get_user(session, message.from_user.id)
if not user:
await UserRequests.create_user(
session,
message.from_user.id,
message.from_user.username,
message.from_user.full_name,
None
)
await state.clear()


async def send_subscription_tasks(user_id: int, chat_id: int, message: types.Message):
response = await request_op(user_id, chat_id)
sponsors = response.get("additional", {}).get("sponsors", []) if response.get("status") == "ok" else []
unsubscribed = [s for s in sponsors if s.get("status") in ["unsubscribed", "notgetted"]]
if not unsubscribed:
await message.answer("✅ Все задания выполнены! Доступ открыт.", reply_markup=main_menu())
return False
await message.answer("📋 Подпишитесь на каналы, чтобы продолжить:")
for sponsor in unsubscribed:
link = sponsor.get("link")
name = sponsor.get("resource_name", "Без названия")
username = link.split("/")[-1] if "t.me" in link else link
await message.answer(
f"• {name}\n{link}",
reply_markup=task_keyboard(link, username)
)
return True


subgram_api.py
HEADERS = {
"Content-Type": "application/json",
"Auth": SUBGRAM_API_KEY,
"Accept": "application/json"
}

async def request_op(user_id: int, chat_id: int, gender: str = None):
data = {
"UserId": user_id,
"ChatId": chat_id
}
if gender:
data["Gender"] = gender
async with aiohttp.ClientSession() as session:
async with session.post(f"{SUBGRAM_API_URL}/request-op/", headers=HEADERS, json=data) as resp:
try:
return await resp.json()
except Exception as e:
logging.error(f"SubGram request_op error: {e}")
return {"status": "error"}


async def check_subscription(user_id: int, chat_id: int):
data = {"UserId": user_id, "ChatId": chat_id}
async with aiohttp.ClientSession() as session:
async with session.post(f"{SUBGRAM_API_URL}/check-subscription/", headers=HEADERS, json=data) as resp:
try:
return await resp.json()
except Exception as e:
logging.error(f"SubGram check_subscription error: {e}")
return {"status": "error"}

async def get_channels(user_id: int, chat_id: int):
response = await request_op(user_id, chat_id)
if response.get("status") == "ok":
return response.get("additional", {}).get("sponsors", [])
return []
 
Активность:
Пока что здесь никого нет