#!/usr/bin/expect -f # Expect script to automate Pyrogram session creation set timeout 120 set phone_number "+66621394851" log_user 1 spawn python3 create_session_correct.py # 等待电话号码提示 expect { "Enter phone number*" { send "$phone_number\r" } timeout { puts "\n超时:未收到电话号码提示" exit 1 } } # 等待确认提示 expect { "*correct*" { send "y\r" } timeout { puts "\n超时:未收到确认提示" exit 1 } } # 等待验证码提示 puts "\n\n\033\[1;33m================================================\033\[0m" puts "\033\[1;33m请查看您的 Telegram 应用,输入收到的验证码:\033\[0m" puts "\033\[1;33m================================================\033\[0m" expect "Enter*code*" { # 从标准输入读取验证码 exec stty -echo expect_user -re "(.*)\n" set code $expect_out(1,string) exec stty echo send "$code\r" } # 等待验证码确认 expect { "*correct*" { send "y\r" } "*Invalid*" { puts "\n验证码错误,请重试" exit 1 } } # 等待完成 expect { "Session*成功*" { puts "\n\n✅ Session 创建成功!" } "错误*" { puts "\n❌ 创建失败" exit 1 } timeout { puts "\n超时" exit 1 } } expect eof