浏览代码

Add js example

painor 4 年之前
父节点
当前提交
5eaa1573c8
共有 3 个文件被更改,包括 25 次插入2 次删除
  1. 23 0
      examples/mainjs.js
  2. 1 1
      gramjs/Version.ts
  3. 1 1
      package.json

+ 23 - 0
examples/mainjs.js

@@ -0,0 +1,23 @@
+// if you're using TS import from here
+//const {TelegramClient} = require("telegram/gramjs");
+//const {StringSession} = require("telegram/gramjs/sessions");
+// if you're not then import from here
+const { TelegramClient } = require('telegram/dist')
+const { StringSession } = require('telegram/dist/sessions');
+
+(async () => {
+    console.log('Loading interactive example...')
+    const apiId = -1 // put your api id here [for example 123456789]
+    const apiHash = '' // put your api hash here [for example '123456abcfghe']
+    const client = new TelegramClient(new StringSession(''), apiId, apiHash, {
+        connectionRetries: 3,
+    })
+    await client.start({
+        botAuthToken: 'YOUR BOT TOKEN',
+
+    })
+    console.log('You should now be connected.')
+    console.log(await client.getMe())
+    // USE THIS STRING TO AVOID RELOGGING EACH TIME
+    console.log(await client.session.save())
+})()

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "1.0.2-alpha.2";
+export const version = "1.2.0";

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "1.1.0",
+  "version": "1.2.0",
   "description": "NodeJS MTProto API Telegram client library,",
   "main": "dist/index.js",
   "types": "dist/index.d.ts",