update
parent
8b8cfc64bc
commit
907409203c
|
@ -8,7 +8,7 @@ function Home() {
|
|||
useEffect(function () {
|
||||
getMe()
|
||||
.then(function (user) {
|
||||
console.log(user);
|
||||
setIsSignIn(true);
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (error.code === 401) {
|
||||
|
|
|
@ -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<any> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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" },
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue