alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
631 stars 113 forks source link

auth.sendCode cannot read property call of undefined at settings._ #193

Open barrcodes opened 3 years ago

barrcodes commented 3 years ago

Describe the bug If auth.sendCode is called per the documentation, the settings object does not have a parameter '_'.

The auth.sendCode logic can be found below. The problematic line appears to be this.predicate(params.settings), where the predicate tries to call builderMap[settings._].call(), and the settings object does not work because the resulting function is undefined.

If I remove the problematic line this.predicate(params.settings), I get a 400 error from the API.

'auth.sendCode': function(params) {
    this.int32(-1502141361);
    this.string(params.phone_number);
    this.int(params.api_id);
    this.string(params.api_hash);
    this.predicate(params.settings);
  },

Code example

const result = await mtProto.call('auth.sendCode', {
    api_id: process.env.TG_APP_ID,
    api_hash: process.env.TG_APP_HASH,
    phone_number: process.env.TG_NUMBER,
    settings: {
        allow_flashcall: false,
        current_number: false,
        allow_app_hash: false,
    },
});

Expected behavior To receive an SMS or Telegram message with the phone code

Context: NodeJS 15.14.0 @mtproto/core 6.0.1