0

So I am making a Telegram bot and trying to get a phone number from a phone number provider through API and my one of the command is:

These are the states:

class States(StatesGroup):
    MIKTAR = State()
    ONAY_KODU = State()
    KULLANICI_ID_AL = State()
    KREDI_MIKTARI = State()

This is the bitay command

@dp.message_handler(commands=['bitay'])
async def bitay(message: types.Message, state: FSMContext):
    await release_numbers()
    kullanici_id = str(message.chat.id)
    with open('users.json', 'r') as file:
        data = json.load(file)

    # Kullanıcının kredi bilgilerini kontrol et
    kullanici = next((user for user in data["Users"] if str(user["kullanici_id"]) == kullanici_id), None)

    if kullanici is None:
        await message.reply("Kullanıcı kaydı bulunamadı. Lütfen önce kayıt olun.")
        return

    if kullanici["krediler"] <= 0:
        await bot.send_message(message.chat.id, "Kredi yetersiz. Lütfen kredi talep edin.")
        return

    pid = ProjectIDS.bitay
    numara_alma_url = f"https://api.provider.com"
    async with aiohttp.ClientSession() as session:
        async with session.get(numara_alma_url) as response:
            if response.status != 200:
                await bot.send_message(message.chat.id, "Numara alınamadı. Lütfen daha sonra tekrar deneyin.")
                return
            numara_data = await response.json()
            numara = numara_data["data"]
            await message.reply(f"Numaranız: {numara}")
            kullanici["numaralar"].append({"numara": numara, "pid": pid})

    with open('users.json', 'w') as file:
        json.dump(data, file, indent=4)

    # Onay kodunu almak için bir sonraki adıma geçmek üzere kaydedin
    await state.update_data(kullanici_id=kullanici_id, numara=numara, pid=pid)
    await States.ONAY_KODU.set()
    await state.finish()

and in my states there is state called "ONAY_KODU" and I set it in my "bitay" command but I can not get to the ONAY_KODU state and can't get the verification code.

This is the ONAY_KODU state

@dp.message_handler(state=States.ONAY_KODU)
async def onay_kodu_al(message: types.Message, state: FSMContext):
    data = await state.get_data()
    kullanici_id = data.get("kullanici_id")
    numara = data.get("numara")
    pid = data.get("pid")

    with open('users.json', 'r') as file:
        Jsondata = json.load(file)

    # Kullanıcının kredi bilgilerini kontrol et
    kullanici = next((user for user in Jsondata ["Users"] if str(user["kullanici_id"]) == kullanici_id), None)

    if kullanici is None:
        await message.reply("Kullanıcı kaydı bulunamadı. Lütfen önce kayıt olun.")
        return

    mesaj_url = f"https://api.provider.com/api/verificationcode"
    async with aiohttp.ClientSession() as session:
        async with session.get(mesaj_url) as response:
            if response.status != 200:
                await bot.send_message(message.chat.id, "Onay kodu alınamadı. Lütfen daha sonra tekrar deneyin.")
                return
            status = await response.json()

            if status["code"] == 200:
                mesaj = status["data"]
                await message.reply(f"{numara} numarası için onay kodunuz: {mesaj}")

                if pid == ProjectIDS.paycel:
                    kullanici["krediler"] -= ProjectCosts.paycelCost
                elif pid == ProjectIDS.tosla:
                    kullanici["krediler"] -= ProjectCosts.toslaCost
                elif pid == ProjectIDS.bitay:
                    kullanici["krediler"] -= ProjectCosts.bitayCost
                elif pid == ProjectIDS.nays:
                    kullanici["krediler"] -= ProjectCosts.naysCost

                with open('users.json', 'w') as file:
                    json.dump(data, file, indent=4)

                releaseNumberUrl = f"https://api.duraincloud.com/out/ext_api/passMobile?name=rijon333&pwd=Mert123.&ApiKey={numara_api_token}&pn={numara}&pid={pid}&serial=2"
                async with session.get(releaseNumberUrl):
                    pass

                await state.finish()

I have tried to set to the states but didn't work

0 Answers0