0.6.4 • Published 17 days ago

bun-mtproto v0.6.4

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

MTProto for deno

Status: WIP

basic usage:

import MTProto from "https://deno.land/x/mtproto/mod.ts";
import factory from "https://deno.land/x/mtproto/transport/connection/deno-tcp.ts";
import Abridged from "https://deno.land/x/mtproto/transport/codec/abridged.ts";
import JsonDB from "https://deno.land/x/mtproto/storage/jsondb.ts";
import { sendCode } from "https://deno.land/x/mtproto/auth/user.ts";
import {
  Confirm,
  Input,
  Secret,
} from "https://deno.land/x/cliffy@v0.22.2/prompt/mod.ts";

const db = new JsonDB("diag_mod.json");

const proto = new MTProto({
  api_id: 0, // your api id
  api_hash: "YOUR_API_HASH",
  environment: {
    app_version: "8.6.1",
    device_model: "Unknown",
    system_version: "1.0.0",
  },
  ipv6_policy: "ipv4",
  transport_factory: factory(() => new Abridged()),
  storage: db,
});

await proto.init();

const rpc = await proto.rpc();

// TODO: check if user is logged

await sendCode(proto, {
  async askCode() {
    return await Input.prompt("Phone code");
  },
  async askPassword(hint) {
    return await Secret.prompt(
      "2FA Password" + (hint ? `(hint: ${hint})` : ""),
    );
  },
  async askSignUp() {
    if (await Confirm.prompt("Sign up")) {
      const first_name = await Input.prompt("First name");
      const last_name = await Input.prompt("Last name");
      return { first_name, last_name };
    }
  },
}, await Input.prompt("Phone number"));
0.6.3

17 days ago

0.6.2

17 days ago

0.6.4

17 days ago

0.5.2

17 days ago

0.6.0

17 days ago

0.5.1

6 months ago

0.5.0

6 months ago