I try to initialize custom TelegramClient and use the code sample from the original library (TelegramClient.d.ts), so the error might be in package.json dependencies / index.js imports. Could you please help to solve that?
The comment from TelegramClient.d.ts:
/**
* The TelegramClient uses several methods in different files to provide all the common functionality in a nice interface.</br>
* **In short, to create a client you must do:**
*
* ```ts
* import {TelegramClient} from "telegram";
*
* const client = new TelegramClient(new StringSession(''),apiId,apiHash,{});
* ```
*
* You don't need to import any methods that are inside the TelegramClient class as they binding in it.
*/
index.js
const Promise = require('bluebird');
Promise.config({
cancellation: true
});
const TelegramBot = require('node-telegram-bot-api');
const path = require('path');
const MTProto = require('@mtproto/core');
const ogs = require('open-graph-scraper');
const firebase = require('firebase-admin');
const TelegramClient = require('telegram')
const StringSession = require('telegram/sessions')
const api_id = 123456789;
const api_hash = 'somehashhere';
const client = new TelegramClient(new StringSession('') ,api_id, api_hash,{});
package.json
"dependencies": {
"@mtproto/core": "6.1.1",
"firebase-admin": "^10.0.1",
"node-telegram-bot-api": "^0.56.0",
"open-graph-scraper": "^4.11.0",
"telegram-mtproto": "^2.2.2",
"telegram": "^2.2.3"
},
"devDependencies": {
"@babel/helper-compilation-targets": "^7.16.7"
}
error:
const client = new TelegramClient(new StringSession('') ,api_id, api_hash,{});
^
TypeError: StringSession is not a constructor
at Object.<anonymous> (.../index.js:29:35)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
node version - v16.13.2