zerobias / telegram-mtproto

Telegram client api (MTProto) library
MIT License
620 stars 136 forks source link

Error at login: TypeError: Cannot read property 'resolved' of undefined #130

Closed Bestulo closed 6 years ago

Bestulo commented 6 years ago

My code is very simple. I run the app, it slowly starts, and then, without sending the code, it crashes.

const {MTProto} = require('telegram-mtproto')
const {phone, api_id, hash} = secretsObject

const api = {
    invokeWithLayer: 0xda9b0d0d,
    layer          : 57,
    initConnection : 0x69796de9,
    api_id         : api_id,
    app_version    : '1.0.1',
    lang_code      : 'en'
}

const log = value => (console.log(value), value)
const server = { dev: true }
const client = MTProto({ server, api })

const sendCode = () => 
    client('auth.sendCode', {
        phone_number: phone,
        current_number: false,
        api_id: api_id,
        api_hash: hash
    })

sendCode().catch(console.err)

It returns the same error as #107:

  var onlyAPI = units => units.filter(p => p.flags.api && p.api.resolved);
                                                                ^

TypeError: Cannot read property 'resolved' of undefined
    at units.filter.p (/path/to/bot/node_modules/telegram-mtproto/lib/state/reducer/index.js:89:65)
    at Array.filter (<anonymous>)
    at onlyAPI (/path/to/bot/node_modules/telegram-mtproto/lib/state/reducer/index.js:89:32)
    at Object.[27] api/task done (/path/to/bot/node_modules/telegram-mtproto/lib/state/reducer/index.js:65:19)
    at reduce (/path/to/bot/node_modules/redux-act/lib/createReducer.js:90:37)
    at combination (/path/to/bot/node_modules/redux/lib/combineReducers.js:133:29)
    at watcher (/path/to/bot/node_modules/telegram-mtproto/lib/state/reducer/index.js:119:17)
    at combination (/path/to/bot/node_modules/redux/lib/combineReducers.js:133:29)
    at decoratedClient (/path/to/bot/node_modules/telegram-mtproto/lib/state/reducer/index.js:287:45)
    at clientReducer (/path/to/bot/node_modules/telegram-mtproto/lib/state/reducer/index.js:300:18)
    at combination (/path/to/bot/node_modules/redux/lib/combineReducers.js:133:29)
    at dispatch (/path/to/bot/node_modules/redux/lib/createStore.js:178:22)
    at /path/to/bot/node_modules/redux-most/lib/createEpicMiddleware.js:46:22
    at action (/path/to/bot/node_modules/telegram-mtproto/lib/state/middleware.js:28:46)
    at /path/to/bot/node_modules/telegram-mtproto/lib/state/middleware.js:21:53
    at action (/path/to/bot/node_modules/telegram-mtproto/lib/state/middleware.js:21:66)
    at EventEmitter.action (/path/to/bot/node_modules/telegram-mtproto/lib/state/middleware.js:43:87)
    at EventEmitter.emit (/path/to/bot/node_modules/eventemitter2/lib/eventemitter2.js:382:22)
    at dispatch (/path/to/bot/node_modules/telegram-mtproto/lib/state/portal.js:38:11)
    at MapAction.map.map.map [as mapper] (/path/to/bot/node_modules/telegram-mtproto/lib/state/epic/task.js:176:24)
    at MapAction$resolved [as resolved] (/path/to/bot/node_modules/fluture/index.js:772:28)
    at resolved (/path/to/bot/node_modules/fluture/index.js:213:19)
    at Resolved._fork (/path/to/bot/node_modules/fluture/index.js:636:3)
    at drain (/path/to/bot/node_modules/fluture/index.js:273:25)
    at settle (/path/to/bot/node_modules/fluture/index.js:199:15)

I tested changing many things, like dev: false or true, api parameters, etc., but it always returns this except sometimes. Sometimes it sends two codes simultaneously, but only when dev is false (and then it gives me another error that I haven't been able to reproduce to post about; when I do, I'll make another issue).

tulir commented 6 years ago

It returns the same error as #107

As you noticed yourself, this is a duplicate of #107. That issue in turn has been marked as a duplicate of #96.

goodmind commented 6 years ago

Duplicate of #96

Bestulo commented 6 years ago

Which is closed and the problem has not been solved. Besides, in 96 it's a similar problem, but it's not exactly the same one. Notice the difference in the initial error message.

tulir commented 6 years ago

While the error message is slightly different, I'm pretty sure the problem is the same.