diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 0a8a3c0..09b3e78 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -8,7 +8,7 @@ function Home() { useEffect(function () { getMe() .then(function (user) { - console.log(user); + setIsSignIn(true); }) .catch(function (error) { if (error.code === 401) { diff --git a/src/telegram/telegram.ts b/src/telegram/telegram.ts index 63105cc..3360296 100644 --- a/src/telegram/telegram.ts +++ b/src/telegram/telegram.ts @@ -1,5 +1,6 @@ import Client from "mtproton/envs/browser"; import { rand_id } from "../utils/rand"; +import { obj } from "../utils/log"; class TelegramHelper { private client: any; @@ -7,14 +8,17 @@ class TelegramHelper { this.client = new Client({ api_id: appID, api_hash: appHash, - test: true, + test: false, }); this.client.setDefaultDc(1); } async call(method: string, params?: object, options?: object): Promise { try { - return await this.client.call(method, params, options); + console.dir(`${method} req\n${obj(params)}`); + let resp = await this.client.call(method, params, options); + console.dir(`${method} resp\n${obj(resp)}`); + return resp; } catch (error) { console.log(`${method} error:`, error); diff --git a/src/telegram/user.ts b/src/telegram/user.ts index 0c28030..084ab12 100644 --- a/src/telegram/user.ts +++ b/src/telegram/user.ts @@ -1,8 +1,8 @@ import Telegram from "./telegram"; async function getMe() { - return await Telegram.call("users.getUsers", { - id: [{ _: "inputUserSelf" }], + return await Telegram.call("users.getFullUser", { + id: { _: "inputUserSelf" }, }); } diff --git a/src/utils/log.ts b/src/utils/log.ts new file mode 100644 index 0000000..ebb2f08 --- /dev/null +++ b/src/utils/log.ts @@ -0,0 +1,12 @@ +const maxToLog = 10240; + +export function obj(obj: any): string { + if (!obj) { + return "null"; + } + let s = JSON.stringify(obj, null, 2); + if (s.length > maxToLog) { + s = s.substr(0, maxToLog) + "..."; + } + return s; +}