olexnzarov / telegraf-session-mongodb

MongoDB session middleware for Telegraf
25 stars 14 forks source link

Cannot read property id of undefined #8

Closed expelliamus closed 4 years ago

expelliamus commented 4 years ago

This issue happen only when the bot is admin of a channel, if the bot is admin of a group the bug isn't happening. Anyway, the problem is on that method:

getSessionKey(ctx) {
    // if ctx has chat object, we use chat.id
    // if ctx has callbackquery object, we use cb.chat_instance
    // if ctx does not have any of the fields mentioned above, we use from.id

    const id = ctx.chat ? ctx.chat.id : (ctx.callbackQuery ? ctx.callbackQuery.chat_instance : ctx.from.id);
    return `${id}:${ctx.from.id}`;
}

specifically here: return${id}:${ctx.from.id};

don't know why you did this, you should return only id 'cause in channel ctx.from.id is undefined

olexnzarov commented 4 years ago

Should be working now, thanks.