Installations
npm install telegram
Developer Guide
Typescript
Yes
Module System
CommonJS, UMD
Node Version
20.18.0
NPM Version
8.18.0
Score
64.8
Supply Chain
98
Quality
91.1
Maintenance
100
Vulnerability
98.6
License
Contributors
Languages
TypeScript (69.89%)
JavaScript (30.05%)
Batchfile (0.04%)
Shell (0.03%)
Developer
gram-js
Download Statistics
Total Downloads
2,545,895
Last Day
6,531
Last Week
43,447
Last Month
196,538
Last Year
1,598,679
GitHub Statistics
1,350 Stars
553 Commits
186 Forks
13 Watching
5 Branches
50 Contributors
Bundle Size
764.65 kB
Minified
212.25 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.26.8
Package Id
telegram@2.26.8
Unpacked Size
2.17 MB
Size
364.40 kB
File Count
226
NPM Version
8.18.0
Node Version
20.18.0
Publised On
19 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
2,545,895
Last day
-2.9%
6,531
Compared to previous day
Last week
-17.9%
43,447
Compared to previous week
Last month
55%
196,538
Compared to previous month
Last year
352.7%
1,598,679
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
16
Dev Dependencies
23
Optional Dependencies
2
GramJS
A Telegram client written in JavaScript for Node.js and browsers, with its core being based on Telethon.
How to get started
Here you'll learn how to obtain necessary information to create telegram application, authorize into your account and send yourself a message.
Note that if you want to use a GramJS inside of a browser, refer to this instructions.
Install GramJS:
1$ npm i telegram
After installation, you'll need to obtain an API ID and hash:
- Login into your telegram account
- Then click "API development tools" and fill your application details (only app title and short name required)
- Finally, click "Create application"
Never share any API/authorization details, that will compromise your application and account.
When you've successfully created the application, change apiId
and apiHash
on what you got from telegram.
Then run this code to send a message to yourself.
1import { TelegramClient } from "telegram"; 2import { StringSession } from "telegram/sessions"; 3import readline from "readline"; 4 5const apiId = 123456; 6const apiHash = "123456abcdfg"; 7const stringSession = new StringSession(""); // fill this later with the value from session.save() 8 9const rl = readline.createInterface({ 10 input: process.stdin, 11 output: process.stdout, 12}); 13 14(async () => { 15 console.log("Loading interactive example..."); 16 const client = new TelegramClient(stringSession, apiId, apiHash, { 17 connectionRetries: 5, 18 }); 19 await client.start({ 20 phoneNumber: async () => 21 new Promise((resolve) => 22 rl.question("Please enter your number: ", resolve) 23 ), 24 password: async () => 25 new Promise((resolve) => 26 rl.question("Please enter your password: ", resolve) 27 ), 28 phoneCode: async () => 29 new Promise((resolve) => 30 rl.question("Please enter the code you received: ", resolve) 31 ), 32 onError: (err) => console.log(err), 33 }); 34 console.log("You should now be connected."); 35 console.log(client.session.save()); // Save this string to avoid logging in again 36 await client.sendMessage("me", { message: "Hello!" }); 37})();
Note that you can also save auth key to a folder instead of a string, change
stringSession
into this:1const storeSession = new StoreSession("folder_name");
Be sure to save output of client.session.save()
into stringSession
or storeSession
variable to avoid logging in again.
Running GramJS inside browsers
GramJS works great in combination with frontend libraries such as React, Vue and others.
While working within browsers, GramJS is using localStorage
to cache the layers.
To get a browser bundle of GramJS, use the following command:
1NODE_ENV=production npx webpack
You can also use the helpful script generate_webpack.js
1node generate_webpack.js
Calling the raw API
To use raw telegram API methods use invoke function.
1await client.invoke(new RequestClass(args));
Documentation
General documentation, use cases, quick start, refer to gram.js.org, or older version of documentation (will be removed in the future).
For more advanced documentation refer to gram.js.org/beta (work in progress).
If your ISP is blocking Telegram, you can check My ISP blocks Telegram. How can I still use GramJS?
Ask a question
If you have any questions about GramJS, feel free to open an issue or ask directly in our telegram group - @GramJSChat.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
Reason
9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/gram-js/gramjs/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/gram-js/gramjs/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/gram-js/gramjs/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/gram-js/gramjs/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/gram-js/gramjs/ci.yml/master?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
Found 11/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact v2.17.4 not signed: https://api.github.com/repos/gram-js/gramjs/releases/102908808
- Warn: release artifact v2.17.4 does not have provenance: https://api.github.com/repos/gram-js/gramjs/releases/102908808
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More