MTProto API Client for Deno 🦕

Overview

Grm deno module

MTProto client for Deno ported from GramJS.

Documentation

Currently, there is no documentation dedicated to Grm. You can use the GramJS documentation and API reference.

Quick Start

Here you'll learn how to obtain necessary information to initialize the client, authorize your personal account and send yourself a message.

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

  1. Visit my.telegram.org and sign in.
  2. Click "API development tools" and fill your application details (only the app title and the short name are required).
  3. Click "Create application".

Don't leak your API credentials. They can't be revoked.

Then use your API credentials with the following example code:

import { StringSession, TelegramClient } from "https://deno.land/x/grm/mod.ts";

const apiId = 123456;
const apiHash = "abcd1234";

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

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

await client.start({
  phoneNumber: () => prompt("Phone number:")!,
  password: () => prompt("Password:")!,
  phoneCode: () => prompt("Verification code:")!,
  onError: console.error,
});

console.log("Connected.");
console.log(client.session.save());

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

You'll be prompted to enter your phone number (in international format), the code you received from Telegram, and your 2FA password if you have one set.

You can then save output of client.session.save() and use it in new StringSession("here") to not login again each time.

After connecting successfully, you should have a text message saying "Hello, world!" in your Saved Messages.

Check out examples/ for more examples.

Used by

Here are some awesome projects powered by Grm:

Add yours to this list by opening a pull request.

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 the original GramJS repository applying them here.

We'd appreciate if you could help with migrating from Node.js modules such as socks and websocket to Deno APIs.

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 the already ported dependencies,
  • contributors of this repository,
  • and everyone else who were a part of this.

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 working as expected.

It took me like 4 days; a total of 20h6m for this repository alone. Including dependency porting and reading the original code, it is 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. It made me realize how much effort have been put into the development of GramJS. You should definitely give it a star if you're using this library.

I had to port the following Node.js modules to Deno:

I know that some of them should not have been ported, but I didn't realized that then.

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
Grm
Grm
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
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
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
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
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
Deno client library for Bitwarden CLI's local REST API.

Bweno Think outside the bun ?? Bweno is a client library for Bitwarden CLI's local REST API. Pronounced as Spanish 'bueno', meaning 'good'. Requiremen

Wyatt Goettsch 3 May 26, 2022
Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services.

Tidbyt Client for Node.js Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services. Insta

Nicholas Penree 19 Dec 17, 2022
Postgres.js - The Fastest full featured PostgreSQL client for Node.js and Deno

?? Fastest full-featured node & deno client ?? ES6 Tagged Template Strings at the core ??‍♀️ Simple surface API ??️ Dynamic query support ?? Chat and

Rasmus Porsager 4.3k Jan 1, 2023
Simple, lightweight Redis client library for Deno.

r2d2 Simple, lightweight Redis client library for Deno. Usage Basic commands import { sendCommand } from "https://deno.land/x/r2d2/mod.ts"; const red

Asher Gomez 22 Dec 28, 2022
Minimalistic pre-configured OAuth 2.0 client for Deno. Inspired by grant.

DenoGrant Minimalistic pre-configured OAuth 2.0 client for Deno. Inspired by Grant. NOTE: this is alpha software subject to breaking changes at anytim

CJ R. 12 Dec 13, 2022
Fastest JavaScript client for MySQL, with Deno FFI.

mysql-native The fastest [1] JavaScript MySQL client. import { Connection } from "https://deno.land/x/mysql_native/mod.ts"; const conn = new Connectio

Deno Drivers 7 Sep 27, 2022
Tiny Telegra.ph API wrapper for Deno

Telegra.ph API wrapper for Deno ?? This is a tiny Telegra.ph API wrapper for Deno written in TypeScript. All methods as listed here are available. See

Dunkan 9 Jul 28, 2022
[WIP] WebGL API implementation for Deno, built on GLFW using FFI.

Note I'm no longer working on this project because I have just realized macOS does not support OpenGL ES API, and adding Desktop GL backend to this mo

DjDeveloper 14 Jun 11, 2022