Home

Awesome

Grm deno module

[!TIP] As of now, Grm is not regularly updated. MTKruto is recommended as an alternative for Deno users.

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


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.