mytglib 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,12 +68,16 @@ const core = new CoreClient({
|
|
|
68
68
|
phone: "+12025550123",
|
|
69
69
|
proxy: { type: "http", host: "127.0.0.1", port: 8080 },
|
|
70
70
|
sessionDirPath: resolve("telegram-sessions"),
|
|
71
|
-
deviceTokenResolver: async () => "your-device-token",
|
|
72
|
-
recaptchaMobileTokenResolver: async () =>
|
|
71
|
+
deviceTokenResolver: async () => ({ token: "your-device-token" }),
|
|
72
|
+
recaptchaMobileTokenResolver: async () => ({
|
|
73
|
+
token: process.env.TG_RECAPTCHA_TOKEN,
|
|
74
|
+
}),
|
|
73
75
|
});
|
|
74
76
|
|
|
75
77
|
try {
|
|
76
|
-
await core.init();
|
|
78
|
+
const initResult = await core.init();
|
|
79
|
+
if (!core.client) throw new Error(getCallMessage(initResult));
|
|
80
|
+
|
|
77
81
|
let response = await core.sendCode();
|
|
78
82
|
console.log(getCallMessage(response));
|
|
79
83
|
|
|
@@ -95,8 +99,12 @@ try {
|
|
|
95
99
|
}
|
|
96
100
|
```
|
|
97
101
|
|
|
102
|
+
`deviceTokenResolver` 和 `recaptchaMobileTokenResolver` 必须返回包含 `token` 字段的对象,对象可保留求解服务返回的 `errorMessage`、`message` 等附加字段。resolver 返回对象中没有有效 token 时,初始化或发送验证码流程会原样返回该对象,以便交给 `getCallMessage()` 展示具体错误。
|
|
103
|
+
|
|
98
104
|
`sessionDirPath` 是必传的会话主目录。路径已存在时必须是目录;路径不存在时会在初始化过程中递归创建。`init()` 会按照 `<主目录>/<+手机号>/<+手机号>.session` 创建 SQLite 会话文件,然后依次解析设备 token 并连接客户端。登录相关公共异步方法均返回原始 Telegram TL 响应;原始请求可通过已连接的 `core.client.call()` 发送。无论成功或失败,都应在 `finally` 中调用 `destroy()`,永久关闭连接、定时器和存储资源。
|
|
99
105
|
|
|
106
|
+
`sendEmailCode()`、`verifyEmailCode()`、`verifyPhoneCode()` 和 `register()` 会直接向 `onLog` 发出 `started`、`completed` 或 `failed` 事件。失败事件的 `error` 保留 Telegram RPC 错误的 `code`、`text` 和 `message`,方法本身也会原样抛出错误;验证码等调用参数不会写入日志。
|
|
107
|
+
|
|
100
108
|
## 代理检查
|
|
101
109
|
|
|
102
110
|
```js
|