simpleLogin.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const phoneDiv = document.getElementById("phoneDiv");
  2. const phone = document.getElementById("phone");
  3. const phoneSend = document.getElementById("phoneSend");
  4. const codeDiv = document.getElementById("codeDiv");
  5. const code = document.getElementById("code");
  6. const codeSend = document.getElementById("codeSend");
  7. const passDiv = document.getElementById("passDiv");
  8. const pass = document.getElementById("pass");
  9. const passSend = document.getElementById("passSend");
  10. const logger = document.getElementById("log");
  11. function phoneCallback() {
  12. phone.disabled = false;
  13. phoneSend.disabled = false;
  14. return new Promise((resolve) => {
  15. phoneSend.addEventListener("click", function () {
  16. phone.disabled = true;
  17. phoneSend.disabled = true;
  18. resolve(phone.value);
  19. });
  20. });
  21. }
  22. function passwordCallback() {
  23. passDiv.style.visibility = "visible";
  24. return new Promise((resolve) => {
  25. passSend.addEventListener("click", function () {
  26. code.disabled = true;
  27. codeSend.disabled = true;
  28. resolve(pass.value);
  29. alert("welcome");
  30. });
  31. });
  32. }
  33. function codeCallback() {
  34. code.disabled = false;
  35. codeSend.disabled = false;
  36. codeDiv.style.visibility = "visible";
  37. return new Promise((resolve) => {
  38. codeSend.addEventListener("click", function () {
  39. code.disabled = true;
  40. codeSend.disabled = true;
  41. resolve(code.value);
  42. });
  43. });
  44. }
  45. const { TelegramClient } = gramjs;
  46. const { StringSession } = gramjs.sessions;
  47. const apiId = 1; // put your api id here [for example 123456789]
  48. const apiHash = "1 "; // put your api hash here [for example '123456abcfghe']
  49. const client = new TelegramClient(new StringSession(""), apiId, apiHash, {
  50. connectionRetries: 3,
  51. }); // you can pass a string session here from previous logins.
  52. // If you want to run this example in the test servers uncomment this line
  53. // client.session.setDC(2, '149.154.167.40', 80)
  54. client
  55. .start({
  56. botAuthToken: phoneCallback,
  57. })
  58. .then(() => {
  59. console.log("%c you should now be connected", "color:#B54128");
  60. console.log(
  61. "%c your string session is " + client.session.save(),
  62. "color:#B54128"
  63. );
  64. console.log(
  65. "%c you can save it to login with it next time",
  66. "color:#B54128"
  67. );
  68. });