Grm is an improved Deno port of GramJS, written in TypeScript

Overview

Warning: Considered as unstable. But, most of the commonly used features are working as expected.

grm

deno module

grm is an improved Deno port of GramJS, written in TypeScript. GramJS is a popular MTProto API Telegram client library written in JavaScript for Node.js and browsers, with its core being based on Telethon.

Deno Land module: https://deno.land/x/grm

What is Deno? https://deno.land

Documentation

Consider following the documentation by GramJS maintainers.

See the Quick Start section for a minimal example to get started.

Quick Start

Here you'll learn how to obtain necessary information to create a Telegram application, authorize into your account and send yourself a message.

First, you'll need to obtain an API ID and hash:

  1. Login into your Telegram account.
  2. Then click "API development tools" and fill your application details (only app title and short name are required).
  3. Finally, click "Create application".

Warning: Never share any API/authorization details, that will compromise your application and account.

When you've successfully created the application, replace the API ID and hash you got from Telegram in the following code.

prompt("Enter your phone number:")!, password: () => prompt("Enter your password:")!, phoneCode: () => prompt("Enter the code you received:")!, onError: (err) => console.log(err), }); console.log("You should now be connected."); // Save the output of the following and use it in `new SessionString("")` // to avoid logging in again next time. console.log(client.session.save()); // Send a message to yourself await client.sendMessage("me", { message: "Hello!" });">
import { StringSession, TelegramClient } from "https://deno.land/x/grm/mod.ts";

// Login and create an application on https://my.telegram.org
// to get values for API ID and API Hash.
const apiId = 123456;
const apiHash = "abcd1234";

// Fill in this later with the value from `client.session.save()`,
// so you don't have to login each time you run the file.
const stringSession = new StringSession("");

console.log("Loading interactive example...");
const client = new TelegramClient(stringSession, apiId, apiHash);

await client.start({
  phoneNumber: () => prompt("Enter your phone number:")!,
  password: () => prompt("Enter your password:")!,
  phoneCode: () => prompt("Enter the code you received:")!,
  onError: (err) => console.log(err),
});

console.log("You should now be connected.");
// Save the output of the following and use it in `new SessionString("")`
// to avoid logging in again next time.
console.log(client.session.save());

// Send a message to yourself
await client.sendMessage("me", { message: "Hello!" });

Lets run it:

deno run -A file-name.ts

You'll be prompted to enter your phone number (in international format), and the code you received from Telegram. Save the output of client.session.save() somewhere and use it in new StringSession("") to avoid logging again later. After connecting successfully, you should have a text message saying "Hello" in your Saved Messages.

Check out the examples/ directory for more examples.

Notes

This is a direct port of GramJS for Deno. This was just an attempt, which turned out to be a successful one. Most of the commonly used features are confirmed as working as expected.

It took me like 4 days; a total of 20h6m for this repository alone. Including dependency porting and figuring out the original code, its a total of almost 34.8h for the first release. I didn't just copy and paste stuff — I did, but I manually wrote lot of the files.

I had to port the following Node modules to Deno. I know that some of them is not even have to be ported, but I didn't realized that then.

Contributing

Feel free to open pull requests related to improvements and fixes to the core library and documentation. We are currently following API changes in GramJS core library and applying them here.

We'd appreciate if you could help with...

  • Migrating from using Node modules such as socks and websocket to using Deno's built-in websocket support.

Credits

This port wouldn't exist without these wonderful people. Thanks to

  • the original authors and contributors of GramJS,
  • authors of the dependencies,
  • authors of already ported dependencies,
  • contributors of this repository,
  • and everyone else who were a part of this.
Comments
  • Add database session and fix store session

    Add database session and fix store session

    This PR adds a DatabaseSession which uses denodb to allow session creation with Postgres, MySQL, MariaDB, SQLite, and MongoDB. For now this makes us dependent on denodb, which I don't love, but that could be mitigated by separating this out into its own package or relying on some kind of dependency injection.

    I also managed to fix StoreSession. It was actually just a single missed line that was keeping it from working.

    opened by watzon 13
  • Module not found

    Module not found "https://deno.land/std/hash/mod.ts"

    Hi,

    I'm trying to use this module but i looks like hash is no longer available in the standard library. Here's the error log

    error: Module not found "https://deno.land/std/hash/mod.ts".
        at https://deno.land/x/[email protected]/src/eme_oaep.ts:1:28
    
    
    opened by waptik 5
  • chore: remove database sessions

    chore: remove database sessions

    1. They are a big obstacle against browser support. (We cannot support browsers if we have them in here.)
    2. They are not depending on the internals, meaning that they can be directly moved to an outer module.
    opened by roj1512 4
  • Event handling not working

    Event handling not working

    MWE:

    import { events, StringSession, TelegramClient } from "https://deno.land/x/grm/mod.ts";
    
    const client = new TelegramClient(
      new StringSession(''),
      0,
      '',
      {},
    );
    
    client.addEventHandler(console.log);
    
    await client.start({ botAuthToken: "" });
    
    opened by roj1512 1
  • Cannot connect

    Cannot connect

    error: Uncaught Error: Connection to telegram failed after Infinity time(s)
          throw new Error(
                ^
        at MTProtoSender._connect (https://raw.githubusercontent.com/grmjs/grm/d6fcd50a0f674bfdb0e0c3aa169ed67e9b32cd7f/src/network/mtproto_sender.ts:284:13)
        at async MTProtoSender.connect (https://raw.githubusercontent.com/grmjs/grm/d6fcd50a0f674bfdb0e0c3aa169ed67e9b32cd7f/src/network/mtproto_sender.ts:205:7)
        at async Client.connect (https://raw.githubusercontent.com/grmjs/grm/d6fcd50a0f674bfdb0e0c3aa169ed67e9b32cd7f/src/client/telegram_client.ts:489:11)
        at async Module.start (https://raw.githubusercontent.com/grmjs/grm/d6fcd50a0f674bfdb0e0c3aa169ed67e9b32cd7f/src/client/auth.ts:21:5)
        at async file:///home/roj/src/xor/main.ts:35:1
    
    opened by roj1512 0
  • Error while sending back response `sendFile`

    Error while sending back response `sendFile`

    Screenshot 2022-12-30 at 19 29 56

    I think response structure might be typo? how I can fix in my local? and then if solved I can PR 🙂 or it's because my code wrong?

    note: the file (image) successfully send, but while sending back response showing error.

    Thank you.

    opened by FarizInk 1
  • Removing circular dependencies

    Removing circular dependencies

    According to madge, there are around 53 circular dependencies left which we need to remove.

    The main parts, namely:

    • client
    • crypto
    • errors
    • extensions
    • network
    • sessions
    • tl

    should be made as independent as we can.

    opened by roj1512 0
  • Browser support

    Browser support

    We need to support browsers. For this, we might want to keep away from std/node as much as we can, since it has many Deno-only code, and we have already faced enough problems with it.

    • [x] Reduce bundle size to work. (Done in #19.)
    • [x] Stop depending on std/node/crypto.ts. (Done in #20.)
    • [x] Stop depending on std/node/fs.ts. (Done in #23.)
    • [x] Stop depending on std/node/net.ts. (Done in #24/#25.)
    • [x] Replace w3cwebsocket with the already-implemented WebSocket. (Done in #26.)
    help wanted 
    opened by roj1512 1
Owner
Dunkan
I love @grammyjs and 3446!
Dunkan
Opinionated collection of TypeScript definitions and utilities for Deno and Deno Deploy. With complete types for Deno/NPM/TS config files, constructed from official JSON schemas.

Schemas Note: You can also import any type from the default module, ./mod.ts deno.json import { type DenoJson } from "https://deno.land/x/[email protected]

deno911 2 Oct 12, 2022
solid material ui port (ported from blazor port)

solid-material-ui solid material ui port (porting from blazor port) In preparation for solid hack Turbo Mono-repository is used for component package

skclusive 18 Apr 30, 2022
Fluent for Deno. Port of @the-moebius/fluent.

Fluent for Deno [better_fluent] Deno port of the-moebius/fluent Better Fluent integration for TypeScript/JavaScript. See the original repository for m

Dunkan 5 May 29, 2022
Unofficial port of the Sentry SDK for JavaScript to Deno.

Sentry_deno This is an unofficial port of the Sentry SDK (@sentry/browser) to Deno. import * as Sentry from "https://deno.land/x/sentry_deno/main.ts";

Geert-Jan Zwiers 11 Aug 11, 2022
Deno port of Gnome libraries (such as Gtk).

Deno GI Deno port of Gnome libraries (such as Gtk). Early Stage and Unstable Usage You must specify --allow-ffi and --unstable flags to run your progr

Ahmadreza Gilak 20 Dec 24, 2022
🦕 Deno port of Microsoft/vscode-textmate: A library that helps tokenize text using TextMate grammars.

TextMate A library that helps tokenize text using TextMate grammars. Deno port of Microsoft/vscode-textmate. See original license here. An interpreter

Dunkan 2 Sep 13, 2022
Technical indicators (TALib) written in typescript for deno.

description cover coverY Technical Analysis written in Typescript for Deno .gitbook/assets/dylan-calluy-JpflvzEl5cg-unsplash.jpeg 0 ?? deno-talib Inst

nenjo tsu 5 Aug 25, 2022
A Roblox OpenCloud API wrapper for Deno (and NodeJS) written in TypeScript.

Active Development This module is currently in active development. Nothing is going to stay consistent as it reaches a stable release. Dynablox Docs |

null 12 Oct 28, 2022
Framework for interacting with instagrams private api in a usable manner (forked from andre's work and improved and fixed)

node-ig-framework Framework for interacting with instagrams private api in a usable manner (forked from andre's work and improved and fixed) Installat

nine ecksen 3 Dec 31, 2022
a Logseq plugin to float items (e.g. videos) for an improved note-taking experience

logseq-helium-plugin Features Float videos for better note-taking in 3 ways: Block context menu (right-click on bullet) → ?? Start float Slash (/) com

Vivian Leung 58 Jan 2, 2023
This is the improved version of Simon game using JavaScript and Html.

simon-game simonoo.mp4 What is this Game This is the improved version of Simon game using JavaScript and Html. you have 10 levels to complete until yo

salah alhashmi 15 Oct 23, 2022
Ticket system v2, many new and improved features. Optimized code.

Global Ticket System V2 Ticket system v2, many new and improved features. Optimized code. Dependencies: mongoose => npm i mongoose dotenv => npm i dot

LunarCodes 14 Dec 2, 2022
This is a simple boilerplate for a Deno website, deployed with Deno Deploy.

Simple Deno Website Boilerplate This is a simple website boilerplate built using Deno and deployed using Deno Deploy. Demo at simple-deno-website-boil

Bruno Bernardino 15 Dec 3, 2022
TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy

Atlas SDK atlas_sdk is a TypeSafe MongoDB Atlas Data API SDK for Deno & Deno Deploy Links Docs Import Replace LATEST_VERSION with current latest versi

Erfan Safari 20 Dec 26, 2022
Deno bindings for yoga, using Deno FFI.

deno_yoga Deno bindings for yoga, using Deno FFI. Usage flags: --allow-ffi: Requires ffi access to "yogacore.dll", "libyogacore.so", "libyogacore.dyli

迷渡 6 Feb 11, 2022
🛣️ A tiny and fast http request router designed for use with deno and deno deploy

Rutt Rutt is a tiny http router designed for use with deno and deno deploy. It is written in about 200 lines of code and is pretty fast, using an exte

Denosaurs 26 Dec 10, 2022
A small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity

Wren Wren is a small, but powerful HTTP library for Deno & Deno Deploy, built for convenience and simplicity. convenient aliases for HTTP responses au

Jakub Neander 69 Dec 12, 2022
deno-ja (Deno Japanese community) showcase

Showcase Deno本家よりも気軽に作ったものを公開できるようなShowcaseです。 スクリーンショットの撮影方法 短めのidを決めていただいて、下記のようにスクリプトを実行してください。 deno task screenshot [url] [id] ※エラーが出る場合は、下記を実行してみ

deno-ja 17 Oct 28, 2022
A command-line tool to manage Deno scripts installed via deno install

??️ nublar nublar is a command-line tool to manage your scripts installed via deno install. ??️ Installation deno install --allow-read --allow-write -

Shun Ueda 16 Dec 26, 2022