2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-09-05 08:35:22 +00:00
Files
the-guard-bot/handlers/middlewares/commandButtons.js

31 lines
810 B
JavaScript
Raw Normal View History

2019-07-10 13:01:02 +02:00
'use strict';
2020-03-12 16:15:43 +01:00
const { Context } = require('telegraf');
2020-03-10 22:10:48 +01:00
/** @type { import('../../typings/context').ContextExtensions } */
2019-07-10 13:01:02 +02:00
const contextCustomizations = require('../../bot/context');
/** @param { import('telegraf').Context } ctx */
2019-07-10 13:01:02 +02:00
module.exports = (ctx, next) => {
if (!ctx.callbackQuery) return next();
if (!ctx.callbackQuery.data.startsWith('/')) return next();
const cbUpdate = {
message: {
from: ctx.from,
chat: ctx.chat,
text: ctx.callbackQuery.data,
entities: [ { offset: 0, type: 'bot_command' } ],
},
2019-07-10 13:01:02 +02:00
};
2020-03-10 22:10:48 +01:00
/** @type { import('../../typings/context').ExtendedContext } */
2020-03-12 16:15:43 +01:00
const cbCtx = new Context(cbUpdate, ctx.tg, ctx.options);
2019-07-10 13:01:02 +02:00
Object.assign(cbCtx, contextCustomizations);
cbCtx.botInfo = ctx.botInfo;
2021-05-07 22:46:11 +02:00
cbCtx.reply = ctx.editMessageText.bind(ctx);
2019-07-10 13:01:02 +02:00
return next(cbCtx);
};