Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
Dmitry edited this page Dec 28, 2017 · 13 revisions

FAQs

API requests

How to send objects

When making API calls simple types like integers and strings can be passed as native javascript types, but to send objects you need to specify corresponding type name in _ field.

For example let's take this method

channels.getFullChannel#8736a09 channel:InputChannel = messages.ChatFull;

You need to specify InputChannel object here, which looks like this

inputChannelEmpty#ee8c1e86 = InputChannel;
inputChannel#afeb712e channel_id:int access_hash:long = InputChannel;

This is how it will look in JavaScript:

const myChannel = {
  _: 'inputChannel',
  channel_id: 123,
  access_hash: '...'
};

client('channels.getFullChannel', { channel: myChannel })
  .then(console.log)

Notice that if you want to send inputChannelEmpty you don't need to specify channel property at all

client('channels.getFullChannel', {  })
  .then(console.log)

Storage

How could I login without entering SMS codes every time?

Library uses storage adapters to save authorization. storage-fs for nodejs and storage-browser for browsers. They work in the background and will save necessary info right after your authorization. Every library instance connected to the same adapter will be the same.

The library has separate test to ensure that we can use previously saved authorization

const { Storage } = require('mtproto-storage-fs')
const storagePath = './storage.json'

const firstInstance = MTProto({
  app: {
    storage: new Storage(storagePath),
  }
})

// ... auth, sms code, exit

const secondInstance = MTProto({
  app: {
    storage: new Storage(storagePath), // New instance but the same file
  }
})

await secondInstance('help.getNearestDc')
await secondInstance('messages.getDialogs', {
  limit: 100,
})
// Typical requests; checks that everything works as expected

Authorization

How to obtain your API key

You can get your API key here

How to handle Two Factor Authorization