UNPKG

telegraf-session-mongoose

Version:
26 lines (25 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLegacySessionKey = exports.getSessionKey = void 0; // Mocking the behaviour from the default memory session implementation. // Source: https://telegraf.js.org/modules.html#session // This is possible due to getters that fetch 'from' and 'chat' values from different sources. const getSessionKey = ({ from, chat }) => { if (from == null || chat == null) { return null; } return `${from.id}:${chat.id}`; }; exports.getSessionKey = getSessionKey; /** * @deprecated Use getSessionKey function and follow the default logic from the official documentation. */ const getLegacySessionKey = (ctx) => { const { chat, callbackQuery, from } = ctx; if (chat && chat.type === 'channel' && !from) { return `ch:${chat.id}`; } const id = chat ? chat.id : (callbackQuery ? callbackQuery.chat_instance : from.id); return `${id}:${from.id}`; }; exports.getLegacySessionKey = getLegacySessionKey;