1

If you know pyrogram is a Telegram MTProto API Framework for Python Which You can give it a phone number to create a user account as a bot:
see the doc

When you give it a phone number, telegram will send you a phone code to authentication and you can enter the phone code manually. also you can give your script the phone code automatically by phone_code parameter in Client class:
see the client doc

I send my phone number from node.js script to python script and telegram send me a phone code to verify.
But when i send the phone code, it doesn't work correctly. actually it send the phone code again
What is my mistake?

my node.js code:

if(command == 'run cli'){
    var spawn = require("child_process").spawn;

    var process = spawn('python3', ["python/cli.py"]);
  
    process.stdout.on('data', function(data) {
         console.log(data.toString());
    });
}

else if(command.substr(0, 9) == 'send code'){
    var code = command.substr(10).trim();

    var spawn = require("child_process").spawn;
    var process = spawn('python3', ["python/cli_enter_code.py", code]);

    process.stdout.on('data', function(data) {
        console.log(data.toString());
    });
}

cli.py file:

from pyrogram import Client
from pyrogram.raw import functions

api_id = someNumber
api_hash = "someHash"

with Client("my_account", api_id, api_hash, phone_number="my phone number") as app:
     print('Bot is online...')

app.run()

cli_enter_code.py file:

import sys

code = sys.argv[1]

from pyrogram import Client
from pyrogram.raw import functions


api_id = someNumber
api_hash = "someHash"


with Client("my_account", api_id, api_hash, phone_number='my phone number', phone_code=code) as app:
     print('Bot is online...')

app.run()
developer
  • 170
  • 2
  • 12

0 Answers0