commit
This commit is contained in:
parent
be4fd23bcf
commit
0bd53741af
728 changed files with 86573 additions and 0 deletions
59
node_modules/telegraf/lib/button.js
generated
vendored
Normal file
59
node_modules/telegraf/lib/button.js
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.webApp = exports.login = exports.pay = exports.game = exports.switchToCurrentChat = exports.switchToChat = exports.callback = exports.url = exports.pollRequest = exports.locationRequest = exports.contactRequest = exports.text = void 0;
|
||||
function text(text, hide = false) {
|
||||
return { text, hide };
|
||||
}
|
||||
exports.text = text;
|
||||
function contactRequest(text, hide = false) {
|
||||
return { text, request_contact: true, hide };
|
||||
}
|
||||
exports.contactRequest = contactRequest;
|
||||
function locationRequest(text, hide = false) {
|
||||
return { text, request_location: true, hide };
|
||||
}
|
||||
exports.locationRequest = locationRequest;
|
||||
function pollRequest(text, type, hide = false) {
|
||||
return { text, request_poll: { type }, hide };
|
||||
}
|
||||
exports.pollRequest = pollRequest;
|
||||
function url(text, url, hide = false) {
|
||||
return { text, url, hide };
|
||||
}
|
||||
exports.url = url;
|
||||
function callback(text, data, hide = false) {
|
||||
return { text, callback_data: data, hide };
|
||||
}
|
||||
exports.callback = callback;
|
||||
function switchToChat(text, value, hide = false) {
|
||||
return { text, switch_inline_query: value, hide };
|
||||
}
|
||||
exports.switchToChat = switchToChat;
|
||||
function switchToCurrentChat(text, value, hide = false) {
|
||||
return { text, switch_inline_query_current_chat: value, hide };
|
||||
}
|
||||
exports.switchToCurrentChat = switchToCurrentChat;
|
||||
function game(text, hide = false) {
|
||||
return { text, callback_game: {}, hide };
|
||||
}
|
||||
exports.game = game;
|
||||
function pay(text, hide = false) {
|
||||
return { text, pay: true, hide };
|
||||
}
|
||||
exports.pay = pay;
|
||||
function login(text, url, opts = {}, hide = false) {
|
||||
return {
|
||||
text,
|
||||
login_url: { ...opts, url },
|
||||
hide,
|
||||
};
|
||||
}
|
||||
exports.login = login;
|
||||
function webApp(text, url, hide = false) {
|
||||
return {
|
||||
text,
|
||||
web_app: { url },
|
||||
hide,
|
||||
};
|
||||
}
|
||||
exports.webApp = webApp;
|
105
node_modules/telegraf/lib/cli.mjs
generated
vendored
Normal file
105
node_modules/telegraf/lib/cli.mjs
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env node
|
||||
import debug from 'debug';
|
||||
import parse from 'mri';
|
||||
import path from 'path';
|
||||
import { Telegraf } from './index.js';
|
||||
const log = debug('telegraf:cli');
|
||||
const helpMsg = `Usage: telegraf [opts] <bot-file>
|
||||
|
||||
-t Bot token [$BOT_TOKEN]
|
||||
-d Webhook domain [$BOT_DOMAIN]
|
||||
-H Webhook host [0.0.0.0]
|
||||
-p Webhook port [$PORT or 3000]
|
||||
-l Enable logs
|
||||
-h Show this help message
|
||||
-m Bot API method to run directly
|
||||
-D Data to pass to the Bot API method`;
|
||||
const help = () => console.log(helpMsg);
|
||||
/**
|
||||
* Runs the cli program and returns exit code
|
||||
*/
|
||||
export async function main(argv, env = {}) {
|
||||
const args = parse(argv, {
|
||||
alias: {
|
||||
// string params, all optional
|
||||
t: 'token',
|
||||
d: 'domain',
|
||||
m: 'method',
|
||||
D: 'data',
|
||||
// defaults exist
|
||||
H: 'host',
|
||||
p: 'port',
|
||||
// boolean params
|
||||
l: 'logs',
|
||||
h: 'help',
|
||||
},
|
||||
boolean: ['h', 'l'],
|
||||
default: {
|
||||
H: '0.0.0.0',
|
||||
p: env.PORT || '3000',
|
||||
},
|
||||
});
|
||||
if (args.help) {
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
const token = args.token || env.BOT_TOKEN;
|
||||
const domain = args.domain || env.BOT_DOMAIN;
|
||||
if (!token) {
|
||||
console.error('Please supply Bot Token');
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
const bot = new Telegraf(token);
|
||||
if (args.method) {
|
||||
const method = args.method;
|
||||
console.log(await bot.telegram.callApi(method, JSON.parse(args.data || '{}')));
|
||||
return 0;
|
||||
}
|
||||
let [, , file] = args._;
|
||||
if (!file) {
|
||||
try {
|
||||
const packageJson = (await import(path.resolve(process.cwd(), 'package.json')));
|
||||
file = packageJson.main || 'index.js';
|
||||
// eslint-disable-next-line no-empty
|
||||
}
|
||||
catch (err) { }
|
||||
}
|
||||
if (!file) {
|
||||
console.error('Please supply a bot handler file.\n');
|
||||
help();
|
||||
return 2;
|
||||
}
|
||||
if (file[0] !== '/')
|
||||
file = path.resolve(process.cwd(), file);
|
||||
try {
|
||||
if (args.logs)
|
||||
debug.enable('telegraf:*');
|
||||
const mod = await import(file);
|
||||
const botHandler = mod.botHandler || mod.default;
|
||||
const httpHandler = mod.httpHandler;
|
||||
const tlsOptions = mod.tlsOptions;
|
||||
const config = {};
|
||||
if (domain) {
|
||||
config.webhook = {
|
||||
domain,
|
||||
host: args.host,
|
||||
port: Number(args.port),
|
||||
tlsOptions,
|
||||
cb: httpHandler,
|
||||
};
|
||||
}
|
||||
bot.use(botHandler);
|
||||
log(`Starting module ${file}`);
|
||||
await bot.launch(config);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`Error launching bot from ${file}`, err === null || err === void 0 ? void 0 : err.stack);
|
||||
return 3;
|
||||
}
|
||||
// Enable graceful stop
|
||||
process.once('SIGINT', () => bot.stop('SIGINT'));
|
||||
process.once('SIGTERM', () => bot.stop('SIGTERM'));
|
||||
return 0;
|
||||
}
|
||||
process.exitCode = await main(process.argv, process.env);
|
534
node_modules/telegraf/lib/composer.js
generated
vendored
Normal file
534
node_modules/telegraf/lib/composer.js
generated
vendored
Normal file
|
@ -0,0 +1,534 @@
|
|||
"use strict";
|
||||
/** @format */
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Composer = void 0;
|
||||
const context_1 = __importDefault(require("./context"));
|
||||
function always(x) {
|
||||
return () => x;
|
||||
}
|
||||
const anoop = always(Promise.resolve());
|
||||
class Composer {
|
||||
constructor(...fns) {
|
||||
this.handler = Composer.compose(fns);
|
||||
}
|
||||
/**
|
||||
* Registers a middleware.
|
||||
*/
|
||||
use(...fns) {
|
||||
this.handler = Composer.compose([this.handler, ...fns]);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Registers middleware for handling updates
|
||||
* matching given type guard function.
|
||||
*/
|
||||
guard(guardFn, ...fns) {
|
||||
return this.use(Composer.guard(guardFn, ...fns));
|
||||
}
|
||||
/**
|
||||
* Registers middleware for handling provided update types.
|
||||
*/
|
||||
on(updateType, ...fns) {
|
||||
return this.use(Composer.on(updateType, ...fns));
|
||||
}
|
||||
/**
|
||||
* Registers middleware for handling matching text messages.
|
||||
*/
|
||||
hears(triggers, ...fns) {
|
||||
return this.use(Composer.hears(triggers, ...fns));
|
||||
}
|
||||
/**
|
||||
* Registers middleware for handling specified commands.
|
||||
*/
|
||||
command(command, ...fns) {
|
||||
return this.use(Composer.command(command, ...fns));
|
||||
}
|
||||
/**
|
||||
* Registers middleware for handling matching callback queries.
|
||||
*/
|
||||
action(triggers, ...fns) {
|
||||
return this.use(Composer.action(triggers, ...fns));
|
||||
}
|
||||
/**
|
||||
* Registers middleware for handling matching inline queries.
|
||||
*/
|
||||
inlineQuery(triggers, ...fns) {
|
||||
return this.use(Composer.inlineQuery(triggers, ...fns));
|
||||
}
|
||||
/**
|
||||
* Registers middleware for handling game queries
|
||||
*/
|
||||
gameQuery(...fns) {
|
||||
return this.use(Composer.gameQuery(...fns));
|
||||
}
|
||||
/**
|
||||
* Registers middleware for dropping matching updates.
|
||||
*/
|
||||
drop(predicate) {
|
||||
return this.use(Composer.drop(predicate));
|
||||
}
|
||||
filter(predicate) {
|
||||
return this.use(Composer.filter(predicate));
|
||||
}
|
||||
entity(predicate, ...fns) {
|
||||
return this.use(Composer.entity(predicate, ...fns));
|
||||
}
|
||||
email(email, ...fns) {
|
||||
return this.use(Composer.email(email, ...fns));
|
||||
}
|
||||
url(url, ...fns) {
|
||||
return this.use(Composer.url(url, ...fns));
|
||||
}
|
||||
textLink(link, ...fns) {
|
||||
return this.use(Composer.textLink(link, ...fns));
|
||||
}
|
||||
textMention(mention, ...fns) {
|
||||
return this.use(Composer.textMention(mention, ...fns));
|
||||
}
|
||||
mention(mention, ...fns) {
|
||||
return this.use(Composer.mention(mention, ...fns));
|
||||
}
|
||||
phone(number, ...fns) {
|
||||
return this.use(Composer.phone(number, ...fns));
|
||||
}
|
||||
hashtag(hashtag, ...fns) {
|
||||
return this.use(Composer.hashtag(hashtag, ...fns));
|
||||
}
|
||||
cashtag(cashtag, ...fns) {
|
||||
return this.use(Composer.cashtag(cashtag, ...fns));
|
||||
}
|
||||
spoiler(text, ...fns) {
|
||||
return this.use(Composer.spoiler(text, ...fns));
|
||||
}
|
||||
/**
|
||||
* Registers a middleware for handling /start
|
||||
*/
|
||||
start(...fns) {
|
||||
const handler = Composer.compose(fns);
|
||||
return this.command('start', (ctx, next) => {
|
||||
// First entity is the /start bot_command itself
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const entity = ctx.message.entities[0];
|
||||
const startPayload = ctx.message.text.slice(entity.length + 1);
|
||||
return handler(Object.assign(ctx, { startPayload }), next);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Registers a middleware for handling /help
|
||||
*/
|
||||
help(...fns) {
|
||||
return this.command('help', ...fns);
|
||||
}
|
||||
/**
|
||||
* Registers a middleware for handling /settings
|
||||
*/
|
||||
settings(...fns) {
|
||||
return this.command('settings', ...fns);
|
||||
}
|
||||
middleware() {
|
||||
return this.handler;
|
||||
}
|
||||
static reply(...args) {
|
||||
return (ctx) => ctx.reply(...args);
|
||||
}
|
||||
static catch(errorHandler, ...fns) {
|
||||
const handler = Composer.compose(fns);
|
||||
// prettier-ignore
|
||||
return (ctx, next) => Promise.resolve(handler(ctx, next))
|
||||
.catch((err) => errorHandler(err, ctx));
|
||||
}
|
||||
/**
|
||||
* Generates middleware that runs in the background.
|
||||
*/
|
||||
static fork(middleware) {
|
||||
const handler = Composer.unwrap(middleware);
|
||||
return async (ctx, next) => {
|
||||
await Promise.all([handler(ctx, anoop), next()]);
|
||||
};
|
||||
}
|
||||
static tap(middleware) {
|
||||
const handler = Composer.unwrap(middleware);
|
||||
return (ctx, next) => Promise.resolve(handler(ctx, anoop)).then(() => next());
|
||||
}
|
||||
/**
|
||||
* Generates middleware that gives up control to the next middleware.
|
||||
*/
|
||||
static passThru() {
|
||||
return (ctx, next) => next();
|
||||
}
|
||||
static lazy(factoryFn) {
|
||||
if (typeof factoryFn !== 'function') {
|
||||
throw new Error('Argument must be a function');
|
||||
}
|
||||
return (ctx, next) => Promise.resolve(factoryFn(ctx)).then((middleware) => Composer.unwrap(middleware)(ctx, next));
|
||||
}
|
||||
static log(logFn = console.log) {
|
||||
return (ctx, next) => {
|
||||
logFn(JSON.stringify(ctx.update, null, 2));
|
||||
return next();
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @param trueMiddleware middleware to run if the predicate returns true
|
||||
* @param falseMiddleware middleware to run if the predicate returns false
|
||||
*/
|
||||
static branch(predicate, trueMiddleware, falseMiddleware) {
|
||||
if (typeof predicate !== 'function') {
|
||||
return Composer.unwrap(predicate ? trueMiddleware : falseMiddleware);
|
||||
}
|
||||
return Composer.lazy((ctx) => Promise.resolve(predicate(ctx)).then((value) => value ? trueMiddleware : falseMiddleware));
|
||||
}
|
||||
/**
|
||||
* Generates optional middleware.
|
||||
* @param predicate predicate to decide on a context object whether to run the middleware
|
||||
* @param middleware middleware to run if the predicate returns true
|
||||
*/
|
||||
static optional(predicate, ...fns) {
|
||||
return Composer.branch(predicate, Composer.compose(fns), Composer.passThru());
|
||||
}
|
||||
static filter(predicate) {
|
||||
return Composer.branch(predicate, Composer.passThru(), anoop);
|
||||
}
|
||||
/**
|
||||
* Generates middleware for dropping matching updates.
|
||||
*/
|
||||
static drop(predicate) {
|
||||
return Composer.branch(predicate, anoop, Composer.passThru());
|
||||
}
|
||||
static dispatch(routeFn, handlers) {
|
||||
return Composer.lazy((ctx) => Promise.resolve(routeFn(ctx)).then((value) => handlers[value]));
|
||||
}
|
||||
// EXPLANATION FOR THE ts-expect-error ANNOTATIONS
|
||||
// The annotations around function invocations with `...fns` are there
|
||||
// whenever we perform validation logic that the flow analysis of TypeScript
|
||||
// cannot comprehend. We always make sure that the middleware functions are
|
||||
// only invoked with properly constrained context objects, but this cannot be
|
||||
// determined automatically.
|
||||
/**
|
||||
* Generates optional middleware based on a predicate that only operates on `ctx.update`.
|
||||
*
|
||||
* Example:
|
||||
* ```ts
|
||||
* import { Composer, Update } from 'telegraf'
|
||||
*
|
||||
* const predicate = (u): u is Update.MessageUpdate => 'message' in u
|
||||
* const middleware = Composer.guard(predicate, (ctx) => {
|
||||
* const message = ctx.update.message
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* Note that `Composer.on('message')` is preferred over this.
|
||||
*
|
||||
* @param guardFn predicate to decide whether to run the middleware based on the `ctx.update` object
|
||||
* @param fns middleware to run if the predicate returns true
|
||||
* @see `Composer.optional` for a more generic version of this method that allows the predicate to operate on `ctx` itself
|
||||
*/
|
||||
static guard(guardFn, ...fns) {
|
||||
return Composer.optional((ctx) => guardFn(ctx.update),
|
||||
// @ts-expect-error see explanation above
|
||||
...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware for handling provided update types.
|
||||
* @deprecated use `Composer.on`
|
||||
*/
|
||||
static mount(updateType, ...fns) {
|
||||
return Composer.on(updateType, ...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware for handling provided update types.
|
||||
*/
|
||||
static on(updateType, ...fns) {
|
||||
const updateTypes = normalizeTextArguments(updateType);
|
||||
const predicate = (update) => updateTypes.some((type) =>
|
||||
// Check update type
|
||||
type in update ||
|
||||
// Check message sub-type
|
||||
('message' in update && type in update.message));
|
||||
return Composer.guard(predicate, ...fns);
|
||||
}
|
||||
static entity(predicate, ...fns) {
|
||||
if (typeof predicate !== 'function') {
|
||||
const entityTypes = normalizeTextArguments(predicate);
|
||||
return Composer.entity(({ type }) => entityTypes.includes(type), ...fns);
|
||||
}
|
||||
return Composer.optional((ctx) => {
|
||||
var _a;
|
||||
const msg = (_a = ctx.message) !== null && _a !== void 0 ? _a : ctx.channelPost;
|
||||
if (msg === undefined) {
|
||||
return false;
|
||||
}
|
||||
const text = getText(msg);
|
||||
const entities = getEntities(msg);
|
||||
if (text === undefined)
|
||||
return false;
|
||||
return entities.some((entity) => predicate(entity, text.substring(entity.offset, entity.offset + entity.length), ctx));
|
||||
// @ts-expect-error see explanation above
|
||||
}, ...fns);
|
||||
}
|
||||
static entityText(entityType, predicate, ...fns) {
|
||||
if (fns.length === 0) {
|
||||
// prettier-ignore
|
||||
return Array.isArray(predicate)
|
||||
// @ts-expect-error predicate is really the middleware
|
||||
? Composer.entity(entityType, ...predicate)
|
||||
// @ts-expect-error predicate is really the middleware
|
||||
: Composer.entity(entityType, predicate);
|
||||
}
|
||||
const triggers = normalizeTriggers(predicate);
|
||||
return Composer.entity(({ type }, value, ctx) => {
|
||||
if (type !== entityType) {
|
||||
return false;
|
||||
}
|
||||
for (const trigger of triggers) {
|
||||
// @ts-expect-error define so far unknown property `match`
|
||||
if ((ctx.match = trigger(value, ctx))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
// @ts-expect-error see explanation above
|
||||
}, ...fns);
|
||||
}
|
||||
static email(email, ...fns) {
|
||||
return Composer.entityText('email', email, ...fns);
|
||||
}
|
||||
static phone(number, ...fns) {
|
||||
return Composer.entityText('phone_number', number, ...fns);
|
||||
}
|
||||
static url(url, ...fns) {
|
||||
return Composer.entityText('url', url, ...fns);
|
||||
}
|
||||
static textLink(link, ...fns) {
|
||||
return Composer.entityText('text_link', link, ...fns);
|
||||
}
|
||||
static textMention(mention, ...fns) {
|
||||
return Composer.entityText('text_mention', mention, ...fns);
|
||||
}
|
||||
static mention(mention, ...fns) {
|
||||
return Composer.entityText('mention', normalizeTextArguments(mention, '@'), ...fns);
|
||||
}
|
||||
static hashtag(hashtag, ...fns) {
|
||||
return Composer.entityText('hashtag', normalizeTextArguments(hashtag, '#'), ...fns);
|
||||
}
|
||||
static cashtag(cashtag, ...fns) {
|
||||
return Composer.entityText('cashtag', normalizeTextArguments(cashtag, '$'), ...fns);
|
||||
}
|
||||
static spoiler(text, ...fns) {
|
||||
return Composer.entityText('spoiler', text, ...fns);
|
||||
}
|
||||
static match(triggers, ...fns) {
|
||||
const handler = Composer.compose(fns);
|
||||
return (ctx, next) => {
|
||||
var _a, _b, _c, _d;
|
||||
const text = (_c = (_b = (_a = getText(ctx.message)) !== null && _a !== void 0 ? _a : getText(ctx.channelPost)) !== null && _b !== void 0 ? _b : getText(ctx.callbackQuery)) !== null && _c !== void 0 ? _c : (_d = ctx.inlineQuery) === null || _d === void 0 ? void 0 : _d.query;
|
||||
if (text === undefined)
|
||||
return next();
|
||||
for (const trigger of triggers) {
|
||||
// @ts-expect-error Trust me, TS!
|
||||
const match = trigger(text, ctx);
|
||||
if (match) {
|
||||
// @ts-expect-error define so far unknown property `match`
|
||||
return handler(Object.assign(ctx, { match }), next);
|
||||
}
|
||||
}
|
||||
return next();
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Generates middleware for handling matching text messages.
|
||||
*/
|
||||
static hears(triggers, ...fns) {
|
||||
return Composer.on('text', Composer.match(normalizeTriggers(triggers), ...fns));
|
||||
}
|
||||
/**
|
||||
* Generates middleware for handling specified commands.
|
||||
*/
|
||||
static command(command, ...fns) {
|
||||
if (fns.length === 0) {
|
||||
// @ts-expect-error command is really the middleware
|
||||
return Composer.entity('bot_command', command);
|
||||
}
|
||||
const commands = normalizeTextArguments(command, '/');
|
||||
return Composer.on('text', Composer.lazy((ctx) => {
|
||||
var _a;
|
||||
const groupCommands = ctx.me && ((_a = ctx.chat) === null || _a === void 0 ? void 0 : _a.type.endsWith('group'))
|
||||
? commands.map((command) => `${command}@${ctx.me}`)
|
||||
: [];
|
||||
return Composer.entity(({ offset, type }, value) => offset === 0 &&
|
||||
type === 'bot_command' &&
|
||||
(commands.includes(value) || groupCommands.includes(value)),
|
||||
// @ts-expect-error see explanation above
|
||||
...fns);
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Generates middleware for handling matching callback queries.
|
||||
*/
|
||||
static action(triggers, ...fns) {
|
||||
return Composer.on('callback_query', Composer.match(normalizeTriggers(triggers), ...fns));
|
||||
}
|
||||
/**
|
||||
* Generates middleware for handling matching inline queries.
|
||||
*/
|
||||
static inlineQuery(triggers, ...fns) {
|
||||
return Composer.on('inline_query', Composer.match(normalizeTriggers(triggers), ...fns));
|
||||
}
|
||||
/**
|
||||
* Generates middleware responding only to specified users.
|
||||
*/
|
||||
static acl(userId, ...fns) {
|
||||
if (typeof userId === 'function') {
|
||||
return Composer.optional(userId, ...fns);
|
||||
}
|
||||
const allowed = Array.isArray(userId) ? userId : [userId];
|
||||
// prettier-ignore
|
||||
return Composer.optional((ctx) => !ctx.from || allowed.includes(ctx.from.id), ...fns);
|
||||
}
|
||||
static memberStatus(status, ...fns) {
|
||||
const statuses = Array.isArray(status) ? status : [status];
|
||||
return Composer.optional(async (ctx) => {
|
||||
if (ctx.message === undefined)
|
||||
return false;
|
||||
const member = await ctx.getChatMember(ctx.message.from.id);
|
||||
return statuses.includes(member.status);
|
||||
}, ...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware responding only to chat admins and chat creator.
|
||||
*/
|
||||
static admin(...fns) {
|
||||
return Composer.memberStatus(['administrator', 'creator'], ...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware responding only to chat creator.
|
||||
*/
|
||||
static creator(...fns) {
|
||||
return Composer.memberStatus('creator', ...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware running only in specified chat types.
|
||||
*/
|
||||
static chatType(type, ...fns) {
|
||||
const types = Array.isArray(type) ? type : [type];
|
||||
return Composer.optional((ctx) => {
|
||||
const chat = ctx.chat;
|
||||
return chat !== undefined && types.includes(chat.type);
|
||||
}, ...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware running only in private chats.
|
||||
*/
|
||||
static privateChat(...fns) {
|
||||
return Composer.chatType('private', ...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware running only in groups and supergroups.
|
||||
*/
|
||||
static groupChat(...fns) {
|
||||
return Composer.chatType(['group', 'supergroup'], ...fns);
|
||||
}
|
||||
/**
|
||||
* Generates middleware for handling game queries.
|
||||
*/
|
||||
static gameQuery(...fns) {
|
||||
return Composer.guard((u) => 'callback_query' in u && 'game_short_name' in u.callback_query, ...fns);
|
||||
}
|
||||
static unwrap(handler) {
|
||||
if (!handler) {
|
||||
throw new Error('Handler is undefined');
|
||||
}
|
||||
return 'middleware' in handler ? handler.middleware() : handler;
|
||||
}
|
||||
static compose(middlewares) {
|
||||
if (!Array.isArray(middlewares)) {
|
||||
throw new Error('Middlewares must be an array');
|
||||
}
|
||||
if (middlewares.length === 0) {
|
||||
return Composer.passThru();
|
||||
}
|
||||
if (middlewares.length === 1) {
|
||||
// Quite literally asserted in the above condition
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return Composer.unwrap(middlewares[0]);
|
||||
}
|
||||
return (ctx, next) => {
|
||||
let index = -1;
|
||||
return execute(0, ctx);
|
||||
async function execute(i, context) {
|
||||
var _a;
|
||||
if (!(context instanceof context_1.default)) {
|
||||
throw new Error('next(ctx) called with invalid context');
|
||||
}
|
||||
if (i <= index) {
|
||||
throw new Error('next() called multiple times');
|
||||
}
|
||||
index = i;
|
||||
const handler = Composer.unwrap((_a = middlewares[i]) !== null && _a !== void 0 ? _a : next);
|
||||
await handler(context, async (ctx = context) => {
|
||||
await execute(i + 1, ctx);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.Composer = Composer;
|
||||
function escapeRegExp(s) {
|
||||
// $& means the whole matched string
|
||||
return s.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
function normalizeTriggers(triggers) {
|
||||
if (!Array.isArray(triggers)) {
|
||||
triggers = [triggers];
|
||||
}
|
||||
return triggers.map((trigger) => {
|
||||
if (!trigger) {
|
||||
throw new Error('Invalid trigger');
|
||||
}
|
||||
if (typeof trigger === 'function') {
|
||||
return trigger;
|
||||
}
|
||||
if (trigger instanceof RegExp) {
|
||||
return (value = '') => {
|
||||
trigger.lastIndex = 0;
|
||||
return trigger.exec(value);
|
||||
};
|
||||
}
|
||||
const regex = new RegExp(`^${escapeRegExp(trigger)}$`);
|
||||
return (value) => regex.exec(value);
|
||||
});
|
||||
}
|
||||
function getEntities(msg) {
|
||||
var _a, _b;
|
||||
if (msg == null)
|
||||
return [];
|
||||
if ('caption_entities' in msg)
|
||||
return (_a = msg.caption_entities) !== null && _a !== void 0 ? _a : [];
|
||||
if ('entities' in msg)
|
||||
return (_b = msg.entities) !== null && _b !== void 0 ? _b : [];
|
||||
return [];
|
||||
}
|
||||
function getText(msg) {
|
||||
if (msg == null)
|
||||
return undefined;
|
||||
if ('caption' in msg)
|
||||
return msg.caption;
|
||||
if ('text' in msg)
|
||||
return msg.text;
|
||||
if ('data' in msg)
|
||||
return msg.data;
|
||||
if ('game_short_name' in msg)
|
||||
return msg.game_short_name;
|
||||
return undefined;
|
||||
}
|
||||
function normalizeTextArguments(argument, prefix = '') {
|
||||
const args = Array.isArray(argument) ? argument : [argument];
|
||||
// prettier-ignore
|
||||
return args
|
||||
.filter(Boolean)
|
||||
.map((arg) => prefix && typeof arg === 'string' && !arg.startsWith(prefix) ? `${prefix}${arg}` : arg);
|
||||
}
|
||||
exports.default = Composer;
|
842
node_modules/telegraf/lib/context.js
generated
vendored
Normal file
842
node_modules/telegraf/lib/context.js
generated
vendored
Normal file
|
@ -0,0 +1,842 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Context = void 0;
|
||||
const util_1 = require("./util");
|
||||
class Context {
|
||||
constructor(update, telegram, botInfo) {
|
||||
this.update = update;
|
||||
this.telegram = telegram;
|
||||
this.botInfo = botInfo;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
this.state = {};
|
||||
}
|
||||
get updateType() {
|
||||
for (const key in this.update) {
|
||||
if (typeof this.update[key] === 'object')
|
||||
return key;
|
||||
}
|
||||
throw new Error(`Cannot determine \`updateType\` of ${JSON.stringify(this.update)}`);
|
||||
}
|
||||
get me() {
|
||||
var _a;
|
||||
return (_a = this.botInfo) === null || _a === void 0 ? void 0 : _a.username;
|
||||
}
|
||||
/**
|
||||
* @deprecated Use ctx.telegram instead
|
||||
*/
|
||||
get tg() {
|
||||
return this.telegram;
|
||||
}
|
||||
get message() {
|
||||
return this.update.message;
|
||||
}
|
||||
get editedMessage() {
|
||||
return this.update.edited_message;
|
||||
}
|
||||
get inlineQuery() {
|
||||
return this.update.inline_query;
|
||||
}
|
||||
get shippingQuery() {
|
||||
return this.update.shipping_query;
|
||||
}
|
||||
get preCheckoutQuery() {
|
||||
return this.update.pre_checkout_query;
|
||||
}
|
||||
get chosenInlineResult() {
|
||||
return this.update.chosen_inline_result;
|
||||
}
|
||||
get channelPost() {
|
||||
return this.update.channel_post;
|
||||
}
|
||||
get editedChannelPost() {
|
||||
return this.update.edited_channel_post;
|
||||
}
|
||||
get callbackQuery() {
|
||||
return this.update.callback_query;
|
||||
}
|
||||
get poll() {
|
||||
return this.update.poll;
|
||||
}
|
||||
get pollAnswer() {
|
||||
return this.update.poll_answer;
|
||||
}
|
||||
get myChatMember() {
|
||||
return this.update.my_chat_member;
|
||||
}
|
||||
get chatMember() {
|
||||
return this.update.chat_member;
|
||||
}
|
||||
get chatJoinRequest() {
|
||||
return this.update.chat_join_request;
|
||||
}
|
||||
get chat() {
|
||||
var _a, _b, _c, _d;
|
||||
return (_d = ((_c = (_b = (_a = this.chatMember) !== null && _a !== void 0 ? _a : this.myChatMember) !== null && _b !== void 0 ? _b : this.chatJoinRequest) !== null && _c !== void 0 ? _c : getMessageFromAnySource(this))) === null || _d === void 0 ? void 0 : _d.chat;
|
||||
}
|
||||
get senderChat() {
|
||||
var _a;
|
||||
return (_a = getMessageFromAnySource(this)) === null || _a === void 0 ? void 0 : _a.sender_chat;
|
||||
}
|
||||
get from() {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
||||
return (_j = ((_h = (_g = (_f = (_e = (_d = (_c = (_b = (_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineQuery) !== null && _b !== void 0 ? _b : this.shippingQuery) !== null && _c !== void 0 ? _c : this.preCheckoutQuery) !== null && _d !== void 0 ? _d : this.chosenInlineResult) !== null && _e !== void 0 ? _e : this.chatMember) !== null && _f !== void 0 ? _f : this.myChatMember) !== null && _g !== void 0 ? _g : this.chatJoinRequest) !== null && _h !== void 0 ? _h : getMessageFromAnySource(this))) === null || _j === void 0 ? void 0 : _j.from;
|
||||
}
|
||||
get inlineMessageId() {
|
||||
var _a, _b;
|
||||
return (_b = ((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.chosenInlineResult)) === null || _b === void 0 ? void 0 : _b.inline_message_id;
|
||||
}
|
||||
get passportData() {
|
||||
var _a;
|
||||
if (this.message == null)
|
||||
return undefined;
|
||||
if (!('passport_data' in this.message))
|
||||
return undefined;
|
||||
return (_a = this.message) === null || _a === void 0 ? void 0 : _a.passport_data;
|
||||
}
|
||||
get webAppData() {
|
||||
if (!('message' in this.update &&
|
||||
this.update.message &&
|
||||
'web_app_data' in this.update.message))
|
||||
return undefined;
|
||||
const { data, button_text } = this.update.message.web_app_data;
|
||||
return {
|
||||
data: {
|
||||
json() {
|
||||
return JSON.parse(data);
|
||||
},
|
||||
text() {
|
||||
return data;
|
||||
},
|
||||
},
|
||||
button_text,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Telegram.webhookReply}
|
||||
*/
|
||||
get webhookReply() {
|
||||
return this.telegram.webhookReply;
|
||||
}
|
||||
set webhookReply(enable) {
|
||||
this.telegram.webhookReply = enable;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
assert(value, method) {
|
||||
if (value === undefined) {
|
||||
throw new TypeError(`Telegraf: "${method}" isn't available for "${this.updateType}"`);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#answerinlinequery
|
||||
*/
|
||||
answerInlineQuery(...args) {
|
||||
this.assert(this.inlineQuery, 'answerInlineQuery');
|
||||
return this.telegram.answerInlineQuery(this.inlineQuery.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#answercallbackquery
|
||||
*/
|
||||
answerCbQuery(...args) {
|
||||
this.assert(this.callbackQuery, 'answerCbQuery');
|
||||
return this.telegram.answerCbQuery(this.callbackQuery.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#answercallbackquery
|
||||
*/
|
||||
answerGameQuery(...args) {
|
||||
this.assert(this.callbackQuery, 'answerGameQuery');
|
||||
return this.telegram.answerGameQuery(this.callbackQuery.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#answershippingquery
|
||||
*/
|
||||
answerShippingQuery(...args) {
|
||||
this.assert(this.shippingQuery, 'answerShippingQuery');
|
||||
return this.telegram.answerShippingQuery(this.shippingQuery.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#answerprecheckoutquery
|
||||
*/
|
||||
answerPreCheckoutQuery(...args) {
|
||||
this.assert(this.preCheckoutQuery, 'answerPreCheckoutQuery');
|
||||
return this.telegram.answerPreCheckoutQuery(this.preCheckoutQuery.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#editmessagetext
|
||||
*/
|
||||
editMessageText(text, extra) {
|
||||
var _a, _b, _c, _d;
|
||||
this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageText');
|
||||
return this.telegram.editMessageText((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, text, extra);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#editmessagecaption
|
||||
*/
|
||||
editMessageCaption(caption, extra) {
|
||||
var _a, _b, _c, _d;
|
||||
this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageCaption');
|
||||
return this.telegram.editMessageCaption((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, caption, extra);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#editmessagemedia
|
||||
*/
|
||||
editMessageMedia(media, extra) {
|
||||
var _a, _b, _c, _d;
|
||||
this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageMedia');
|
||||
return this.telegram.editMessageMedia((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, media, extra);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#editmessagereplymarkup
|
||||
*/
|
||||
editMessageReplyMarkup(markup) {
|
||||
var _a, _b, _c, _d;
|
||||
this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageReplyMarkup');
|
||||
return this.telegram.editMessageReplyMarkup((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, markup);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#editmessagelivelocation
|
||||
*/
|
||||
editMessageLiveLocation(latitude, longitude, extra) {
|
||||
var _a, _b, _c, _d;
|
||||
this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageLiveLocation');
|
||||
return this.telegram.editMessageLiveLocation((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, latitude, longitude, extra);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#stopmessagelivelocation
|
||||
*/
|
||||
stopMessageLiveLocation(markup) {
|
||||
var _a, _b, _c, _d;
|
||||
this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'stopMessageLiveLocation');
|
||||
return this.telegram.stopMessageLiveLocation((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, markup);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendmessage
|
||||
*/
|
||||
sendMessage(...args) {
|
||||
this.assert(this.chat, 'sendMessage');
|
||||
return this.telegram.sendMessage(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendmessage
|
||||
*/
|
||||
reply(...args) {
|
||||
(0, util_1.deprecate)('ctx.reply', 'reply', 'sendMessage', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendMessage(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#getchat
|
||||
*/
|
||||
getChat(...args) {
|
||||
this.assert(this.chat, 'getChat');
|
||||
return this.telegram.getChat(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#exportchatinvitelink
|
||||
*/
|
||||
exportChatInviteLink(...args) {
|
||||
this.assert(this.chat, 'exportChatInviteLink');
|
||||
return this.telegram.exportChatInviteLink(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#createchatinvitelink
|
||||
*/
|
||||
createChatInviteLink(...args) {
|
||||
this.assert(this.chat, 'createChatInviteLink');
|
||||
return this.telegram.createChatInviteLink(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#editchatinvitelink
|
||||
*/
|
||||
editChatInviteLink(...args) {
|
||||
this.assert(this.chat, 'editChatInviteLink');
|
||||
return this.telegram.editChatInviteLink(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#revokechatinvitelink
|
||||
*/
|
||||
revokeChatInviteLink(...args) {
|
||||
this.assert(this.chat, 'revokeChatInviteLink');
|
||||
return this.telegram.revokeChatInviteLink(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#banchatmember
|
||||
*/
|
||||
banChatMember(...args) {
|
||||
this.assert(this.chat, 'banChatMember');
|
||||
return this.telegram.banChatMember(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#banchatmember
|
||||
* @deprecated since API 5.3. Use {@link Context.banChatMember}
|
||||
*/
|
||||
get kickChatMember() {
|
||||
return this.banChatMember;
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#unbanchatmember
|
||||
*/
|
||||
unbanChatMember(...args) {
|
||||
this.assert(this.chat, 'unbanChatMember');
|
||||
return this.telegram.unbanChatMember(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#restrictchatmember
|
||||
*/
|
||||
restrictChatMember(...args) {
|
||||
this.assert(this.chat, 'restrictChatMember');
|
||||
return this.telegram.restrictChatMember(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#promotechatmember
|
||||
*/
|
||||
promoteChatMember(...args) {
|
||||
this.assert(this.chat, 'promoteChatMember');
|
||||
return this.telegram.promoteChatMember(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
||||
*/
|
||||
setChatAdministratorCustomTitle(...args) {
|
||||
this.assert(this.chat, 'setChatAdministratorCustomTitle');
|
||||
return this.telegram.setChatAdministratorCustomTitle(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setchatphoto
|
||||
*/
|
||||
setChatPhoto(...args) {
|
||||
this.assert(this.chat, 'setChatPhoto');
|
||||
return this.telegram.setChatPhoto(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#deletechatphoto
|
||||
*/
|
||||
deleteChatPhoto(...args) {
|
||||
this.assert(this.chat, 'deleteChatPhoto');
|
||||
return this.telegram.deleteChatPhoto(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setchattitle
|
||||
*/
|
||||
setChatTitle(...args) {
|
||||
this.assert(this.chat, 'setChatTitle');
|
||||
return this.telegram.setChatTitle(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setchatdescription
|
||||
*/
|
||||
setChatDescription(...args) {
|
||||
this.assert(this.chat, 'setChatDescription');
|
||||
return this.telegram.setChatDescription(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#pinchatmessage
|
||||
*/
|
||||
pinChatMessage(...args) {
|
||||
this.assert(this.chat, 'pinChatMessage');
|
||||
return this.telegram.pinChatMessage(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#unpinchatmessage
|
||||
*/
|
||||
unpinChatMessage(...args) {
|
||||
this.assert(this.chat, 'unpinChatMessage');
|
||||
return this.telegram.unpinChatMessage(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#unpinallchatmessages
|
||||
*/
|
||||
unpinAllChatMessages(...args) {
|
||||
this.assert(this.chat, 'unpinAllChatMessages');
|
||||
return this.telegram.unpinAllChatMessages(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#leavechat
|
||||
*/
|
||||
leaveChat(...args) {
|
||||
this.assert(this.chat, 'leaveChat');
|
||||
return this.telegram.leaveChat(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setchatpermissions
|
||||
*/
|
||||
setChatPermissions(...args) {
|
||||
this.assert(this.chat, 'setChatPermissions');
|
||||
return this.telegram.setChatPermissions(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#getchatadministrators
|
||||
*/
|
||||
getChatAdministrators(...args) {
|
||||
this.assert(this.chat, 'getChatAdministrators');
|
||||
return this.telegram.getChatAdministrators(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#getchatmember
|
||||
*/
|
||||
getChatMember(...args) {
|
||||
this.assert(this.chat, 'getChatMember');
|
||||
return this.telegram.getChatMember(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#getchatmembercount
|
||||
*/
|
||||
getChatMembersCount(...args) {
|
||||
this.assert(this.chat, 'getChatMembersCount');
|
||||
return this.telegram.getChatMembersCount(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setpassportdataerrors
|
||||
*/
|
||||
setPassportDataErrors(errors) {
|
||||
this.assert(this.from, 'setPassportDataErrors');
|
||||
return this.telegram.setPassportDataErrors(this.from.id, errors);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendphoto
|
||||
*/
|
||||
sendPhoto(...args) {
|
||||
this.assert(this.chat, 'sendPhoto');
|
||||
return this.telegram.sendPhoto(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendphoto
|
||||
*/
|
||||
replyWithPhoto(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithPhoto', 'reply', 'sendPhoto', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendPhoto(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendmediagroup
|
||||
*/
|
||||
sendMediaGroup(...args) {
|
||||
this.assert(this.chat, 'sendMediaGroup');
|
||||
return this.telegram.sendMediaGroup(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendmediagroup
|
||||
*/
|
||||
replyWithMediaGroup(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithMediaGroup', 'reply', 'sendMediaGroup', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendMediaGroup(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendaudio
|
||||
*/
|
||||
sendAudio(...args) {
|
||||
this.assert(this.chat, 'sendAudio');
|
||||
return this.telegram.sendAudio(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendaudio
|
||||
*/
|
||||
replyWithAudio(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithAudio', 'reply', 'sendAudio', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendAudio(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#senddice
|
||||
*/
|
||||
sendDice(...args) {
|
||||
this.assert(this.chat, 'sendDice');
|
||||
return this.telegram.sendDice(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#senddice
|
||||
*/
|
||||
replyWithDice(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithDice', 'reply', 'sendDice', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendDice(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#senddocument
|
||||
*/
|
||||
sendDocument(...args) {
|
||||
this.assert(this.chat, 'sendDocument');
|
||||
return this.telegram.sendDocument(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#senddocument
|
||||
*/
|
||||
replyWithDocument(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithDocument', 'reply', 'sendDocument', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendDocument(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendsticker
|
||||
*/
|
||||
sendSticker(...args) {
|
||||
this.assert(this.chat, 'sendSticker');
|
||||
return this.telegram.sendSticker(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendsticker
|
||||
*/
|
||||
replyWithSticker(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithSticker', 'reply', 'sendSticker', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendSticker(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvideo
|
||||
*/
|
||||
sendVideo(...args) {
|
||||
this.assert(this.chat, 'sendVideo');
|
||||
return this.telegram.sendVideo(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvideo
|
||||
*/
|
||||
replyWithVideo(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithVideo', 'reply', 'sendVideo', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendVideo(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendanimation
|
||||
*/
|
||||
sendAnimation(...args) {
|
||||
this.assert(this.chat, 'sendAnimation');
|
||||
return this.telegram.sendAnimation(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendanimation
|
||||
*/
|
||||
replyWithAnimation(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithAnimation', 'reply', 'sendAnimation', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendAnimation(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvideonote
|
||||
*/
|
||||
sendVideoNote(...args) {
|
||||
this.assert(this.chat, 'sendVideoNote');
|
||||
return this.telegram.sendVideoNote(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvideonote
|
||||
*/
|
||||
replyWithVideoNote(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithVideoNote', 'reply', 'sendVideoNote', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendVideoNote(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendinvoice
|
||||
*/
|
||||
sendInvoice(...args) {
|
||||
this.assert(this.chat, 'sendInvoice');
|
||||
return this.telegram.sendInvoice(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendinvoice
|
||||
*/
|
||||
replyWithInvoice(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithInvoice', 'reply', 'sendInvoice', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendInvoice(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendgame
|
||||
*/
|
||||
sendGame(...args) {
|
||||
this.assert(this.chat, 'sendGame');
|
||||
return this.telegram.sendGame(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendgame
|
||||
*/
|
||||
replyWithGame(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithGame', 'reply', 'sendGame', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendGame(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvoice
|
||||
*/
|
||||
sendVoice(...args) {
|
||||
this.assert(this.chat, 'sendVoice');
|
||||
return this.telegram.sendVoice(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvoice
|
||||
*/
|
||||
replyWithVoice(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithVoice', 'reply', 'sendVoice', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendVoice(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendpoll
|
||||
*/
|
||||
sendPoll(...args) {
|
||||
this.assert(this.chat, 'sendPoll');
|
||||
return this.telegram.sendPoll(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendpoll
|
||||
*/
|
||||
replyWithPoll(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithPoll', 'reply', 'sendPoll', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendPoll(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendquiz
|
||||
*/
|
||||
sendQuiz(...args) {
|
||||
this.assert(this.chat, 'sendQuiz');
|
||||
return this.telegram.sendQuiz(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendquiz
|
||||
*/
|
||||
replyWithQuiz(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithQuiz', 'reply', 'sendQuiz', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendQuiz(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#stoppoll
|
||||
*/
|
||||
stopPoll(...args) {
|
||||
this.assert(this.chat, 'stopPoll');
|
||||
return this.telegram.stopPoll(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendchataction
|
||||
*/
|
||||
sendChatAction(...args) {
|
||||
this.assert(this.chat, 'sendChatAction');
|
||||
return this.telegram.sendChatAction(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Context.sendChatAction} instead
|
||||
* @see https://core.telegram.org/bots/api#sendchataction
|
||||
*/
|
||||
replyWithChatAction(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithChatAction', 'reply', 'sendChatAction');
|
||||
return this.sendChatAction(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendlocation
|
||||
*/
|
||||
sendLocation(...args) {
|
||||
this.assert(this.chat, 'sendLocation');
|
||||
return this.telegram.sendLocation(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendlocation
|
||||
*/
|
||||
replyWithLocation(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithLocation', 'reply', 'sendLocation', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendLocation(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvenue
|
||||
*/
|
||||
sendVenue(...args) {
|
||||
this.assert(this.chat, 'sendVenue');
|
||||
return this.telegram.sendVenue(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendvenue
|
||||
*/
|
||||
replyWithVenue(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithVenue', 'reply', 'sendVenue', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendVenue(...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendcontact
|
||||
*/
|
||||
sendContact(...args) {
|
||||
this.assert(this.chat, 'sendContact');
|
||||
return this.telegram.sendContact(this.chat.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendcontact
|
||||
*/
|
||||
replyWithContact(...args) {
|
||||
(0, util_1.deprecate)('ctx.replyWithContact', 'reply', 'sendContact', 'https://telegraf.js.org/experimental#new-reply');
|
||||
return this.sendContact(...args);
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Telegram.getStickerSet}
|
||||
* @see https://core.telegram.org/bots/api#getstickerset
|
||||
*/
|
||||
getStickerSet(setName) {
|
||||
return this.telegram.getStickerSet(setName);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setchatstickerset
|
||||
*/
|
||||
setChatStickerSet(setName) {
|
||||
this.assert(this.chat, 'setChatStickerSet');
|
||||
return this.telegram.setChatStickerSet(this.chat.id, setName);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#deletechatstickerset
|
||||
*/
|
||||
deleteChatStickerSet() {
|
||||
this.assert(this.chat, 'deleteChatStickerSet');
|
||||
return this.telegram.deleteChatStickerSet(this.chat.id);
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Telegram.setStickerPositionInSet}
|
||||
* @see https://core.telegram.org/bots/api#setstickerpositioninset
|
||||
*/
|
||||
setStickerPositionInSet(sticker, position) {
|
||||
return this.telegram.setStickerPositionInSet(sticker, position);
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Telegram.setStickerSetThumb}
|
||||
* @see https://core.telegram.org/bots/api#setstickersetthumb
|
||||
*/
|
||||
setStickerSetThumb(...args) {
|
||||
return this.telegram.setStickerSetThumb(...args);
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Telegram.deleteStickerFromSet}
|
||||
* @see https://core.telegram.org/bots/api#deletestickerfromset
|
||||
*/
|
||||
deleteStickerFromSet(sticker) {
|
||||
return this.telegram.deleteStickerFromSet(sticker);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#uploadstickerfile
|
||||
*/
|
||||
uploadStickerFile(...args) {
|
||||
this.assert(this.from, 'uploadStickerFile');
|
||||
return this.telegram.uploadStickerFile(this.from.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#createnewstickerset
|
||||
*/
|
||||
createNewStickerSet(...args) {
|
||||
this.assert(this.from, 'createNewStickerSet');
|
||||
return this.telegram.createNewStickerSet(this.from.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#addstickertoset
|
||||
*/
|
||||
addStickerToSet(...args) {
|
||||
this.assert(this.from, 'addStickerToSet');
|
||||
return this.telegram.addStickerToSet(this.from.id, ...args);
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Telegram.getMyCommands}
|
||||
* @see https://core.telegram.org/bots/api#getmycommands
|
||||
*/
|
||||
getMyCommands() {
|
||||
return this.telegram.getMyCommands();
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Telegram.setMyCommands}
|
||||
* @see https://core.telegram.org/bots/api#setmycommands
|
||||
*/
|
||||
setMyCommands(commands) {
|
||||
return this.telegram.setMyCommands(commands);
|
||||
}
|
||||
/**
|
||||
* @deprecated use {@link Context.replyWithMarkdownV2}
|
||||
* @see https://core.telegram.org/bots/api#sendmessage
|
||||
*/
|
||||
replyWithMarkdown(markdown, extra) {
|
||||
return this.reply(markdown, { parse_mode: 'Markdown', ...extra });
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendmessage
|
||||
*/
|
||||
replyWithMarkdownV2(markdown, extra) {
|
||||
return this.reply(markdown, { parse_mode: 'MarkdownV2', ...extra });
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#sendmessage
|
||||
*/
|
||||
replyWithHTML(html, extra) {
|
||||
return this.reply(html, { parse_mode: 'HTML', ...extra });
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#deletemessage
|
||||
*/
|
||||
deleteMessage(messageId) {
|
||||
this.assert(this.chat, 'deleteMessage');
|
||||
if (typeof messageId !== 'undefined') {
|
||||
return this.telegram.deleteMessage(this.chat.id, messageId);
|
||||
}
|
||||
const message = getMessageFromAnySource(this);
|
||||
this.assert(message, 'deleteMessage');
|
||||
return this.telegram.deleteMessage(this.chat.id, message.message_id);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#forwardmessage
|
||||
*/
|
||||
forwardMessage(chatId, extra) {
|
||||
const message = getMessageFromAnySource(this);
|
||||
this.assert(message, 'forwardMessage');
|
||||
return this.telegram.forwardMessage(chatId, message.chat.id, message.message_id, extra);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#copymessage
|
||||
*/
|
||||
copyMessage(chatId, extra) {
|
||||
const message = getMessageFromAnySource(this);
|
||||
this.assert(message, 'copyMessage');
|
||||
return this.telegram.copyMessage(chatId, message.chat.id, message.message_id, extra);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#approvechatjoinrequest
|
||||
*/
|
||||
approveChatJoinRequest(userId) {
|
||||
this.assert(this.chat, 'approveChatJoinRequest');
|
||||
return this.telegram.approveChatJoinRequest(this.chat.id, userId);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#declinechatjoinrequest
|
||||
*/
|
||||
declineChatJoinRequest(userId) {
|
||||
this.assert(this.chat, 'declineChatJoinRequest');
|
||||
return this.telegram.declineChatJoinRequest(this.chat.id, userId);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#banchatsenderchat
|
||||
*/
|
||||
banChatSenderChat(senderChatId) {
|
||||
this.assert(this.chat, 'banChatSenderChat');
|
||||
return this.telegram.banChatSenderChat(this.chat.id, senderChatId);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#unbanchatsenderchat
|
||||
*/
|
||||
unbanChatSenderChat(senderChatId) {
|
||||
this.assert(this.chat, 'unbanChatSenderChat');
|
||||
return this.telegram.unbanChatSenderChat(this.chat.id, senderChatId);
|
||||
}
|
||||
/**
|
||||
* Use this method to change the bot's menu button in the current private chat. Returns true on success.
|
||||
* @see https://core.telegram.org/bots/api#setchatmenubutton
|
||||
*/
|
||||
setChatMenuButton(menuButton) {
|
||||
this.assert(this.chat, 'setChatMenuButton');
|
||||
return this.telegram.setChatMenuButton({ chatId: this.chat.id, menuButton });
|
||||
}
|
||||
/**
|
||||
* Use this method to get the current value of the bot's menu button in the current private chat. Returns MenuButton on success.
|
||||
* @see https://core.telegram.org/bots/api#getchatmenubutton
|
||||
*/
|
||||
getChatMenuButton() {
|
||||
this.assert(this.chat, 'getChatMenuButton');
|
||||
return this.telegram.getChatMenuButton({ chatId: this.chat.id });
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#setmydefaultadministratorrights
|
||||
*/
|
||||
setMyDefaultAdministratorRights(extra) {
|
||||
return this.telegram.setMyDefaultAdministratorRights(extra);
|
||||
}
|
||||
/**
|
||||
* @see https://core.telegram.org/bots/api#getmydefaultadministratorrights
|
||||
*/
|
||||
getMyDefaultAdministratorRights(extra) {
|
||||
return this.telegram.getMyDefaultAdministratorRights(extra);
|
||||
}
|
||||
}
|
||||
exports.Context = Context;
|
||||
exports.default = Context;
|
||||
function getMessageFromAnySource(ctx) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
return ((_e = (_d = (_b = (_a = ctx.message) !== null && _a !== void 0 ? _a : ctx.editedMessage) !== null && _b !== void 0 ? _b : (_c = ctx.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : ctx.channelPost) !== null && _e !== void 0 ? _e : ctx.editedChannelPost);
|
||||
}
|
56
node_modules/telegraf/lib/core/helpers/check.js
generated
vendored
Normal file
56
node_modules/telegraf/lib/core/helpers/check.js
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.is2D = exports.hasPropType = exports.hasProp = void 0;
|
||||
/**
|
||||
* Checks if a given object has a property with a given name.
|
||||
*
|
||||
* Example invocation:
|
||||
* ```js
|
||||
* let obj = { 'foo': 'bar', 'baz': () => {} }
|
||||
* hasProp(obj, 'foo') // true
|
||||
* hasProp(obj, 'baz') // true
|
||||
* hasProp(obj, 'abc') // false
|
||||
* ```
|
||||
*
|
||||
* @param obj An object to test
|
||||
* @param prop The name of the property
|
||||
*/
|
||||
function hasProp(obj, prop) {
|
||||
return obj !== undefined && prop in obj;
|
||||
}
|
||||
exports.hasProp = hasProp;
|
||||
/**
|
||||
* Checks if a given object has a property with a given name.
|
||||
* Furthermore performs a `typeof` check on the property if it exists.
|
||||
*
|
||||
* Example invocation:
|
||||
* ```js
|
||||
* let obj = { 'foo': 'bar', 'baz': () => {} }
|
||||
* hasPropType(obj, 'foo', 'string') // true
|
||||
* hasPropType(obj, 'baz', 'function') // true
|
||||
* hasPropType(obj, 'abc', 'number') // false
|
||||
* ```
|
||||
*
|
||||
* @param obj An object to test
|
||||
* @param prop The name of the property
|
||||
* @param type The type the property is expected to have
|
||||
*/
|
||||
function hasPropType(obj, prop, type) {
|
||||
return hasProp(obj, prop) && type === typeof obj[prop];
|
||||
}
|
||||
exports.hasPropType = hasPropType;
|
||||
/**
|
||||
* Checks if the supplied array has two dimensions or not.
|
||||
*
|
||||
* Example invocations:
|
||||
* is2D([]) // false
|
||||
* is2D([[]]) // true
|
||||
* is2D([[], []]) // true
|
||||
* is2D([42]) // false
|
||||
*
|
||||
* @param arr an array with one or two dimensions
|
||||
*/
|
||||
function is2D(arr) {
|
||||
return Array.isArray(arr[0]);
|
||||
}
|
||||
exports.is2D = is2D;
|
13
node_modules/telegraf/lib/core/helpers/compact.js
generated
vendored
Normal file
13
node_modules/telegraf/lib/core/helpers/compact.js
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.compactOptions = void 0;
|
||||
function compactOptions(options) {
|
||||
if (!options) {
|
||||
return options;
|
||||
}
|
||||
const keys = Object.keys(options);
|
||||
const compactKeys = keys.filter((key) => options[key] !== undefined);
|
||||
const compactEntries = compactKeys.map((key) => [key, options[key]]);
|
||||
return Object.fromEntries(compactEntries);
|
||||
}
|
||||
exports.compactOptions = compactOptions;
|
50
node_modules/telegraf/lib/core/helpers/formatting.js
generated
vendored
Normal file
50
node_modules/telegraf/lib/core/helpers/formatting.js
generated
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.linkOrMention = exports._fmt = exports.FmtString = void 0;
|
||||
class FmtString {
|
||||
constructor(text, entities) {
|
||||
this.text = text;
|
||||
if (entities) {
|
||||
this.entities = entities;
|
||||
// force parse_mode to undefined if entities are present
|
||||
this.parse_mode = undefined;
|
||||
}
|
||||
}
|
||||
static normalise(content) {
|
||||
if (typeof content === 'string')
|
||||
return new FmtString(content);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
exports.FmtString = FmtString;
|
||||
function _fmt(kind, opts) {
|
||||
return function fmt(parts, ...items) {
|
||||
let text = '';
|
||||
const entities = [];
|
||||
parts = typeof parts === 'string' ? [parts] : parts;
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
text += parts[i];
|
||||
const item = items[i];
|
||||
if (!item)
|
||||
continue;
|
||||
if (typeof item === 'string') {
|
||||
text += item;
|
||||
continue;
|
||||
}
|
||||
for (const child of item.entities || [])
|
||||
entities.push({ ...child, offset: text.length + child.offset });
|
||||
text += item.text;
|
||||
}
|
||||
if (kind !== 'very-plain')
|
||||
entities.unshift({ type: kind, offset: 0, length: text.length, ...opts });
|
||||
return new FmtString(text, entities.length ? entities : undefined);
|
||||
};
|
||||
}
|
||||
exports._fmt = _fmt;
|
||||
const linkOrMention = (content, data) => {
|
||||
const { text, entities = [] } = FmtString.normalise(content);
|
||||
entities.unshift(Object.assign(data, { offset: 0, length: text.length }));
|
||||
return new FmtString(text, entities);
|
||||
};
|
||||
exports.linkOrMention = linkOrMention;
|
296
node_modules/telegraf/lib/core/network/client.js
generated
vendored
Normal file
296
node_modules/telegraf/lib/core/network/client.js
generated
vendored
Normal file
|
@ -0,0 +1,296 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/* eslint @typescript-eslint/restrict-template-expressions: [ "error", { "allowNumber": true, "allowBoolean": true } ] */
|
||||
const crypto = __importStar(require("crypto"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const https = __importStar(require("https"));
|
||||
const path = __importStar(require("path"));
|
||||
const node_fetch_1 = __importDefault(require("node-fetch"));
|
||||
const check_1 = require("../helpers/check");
|
||||
const compact_1 = require("../helpers/compact");
|
||||
const multipart_stream_1 = __importDefault(require("./multipart-stream"));
|
||||
const error_1 = __importDefault(require("./error"));
|
||||
const url_1 = require("url");
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const debug = require('debug')('telegraf:client');
|
||||
const { isStream } = multipart_stream_1.default;
|
||||
const WEBHOOK_REPLY_METHOD_ALLOWLIST = new Set([
|
||||
'answerCallbackQuery',
|
||||
'answerInlineQuery',
|
||||
'deleteMessage',
|
||||
'leaveChat',
|
||||
'sendChatAction',
|
||||
]);
|
||||
const DEFAULT_EXTENSIONS = {
|
||||
audio: 'mp3',
|
||||
photo: 'jpg',
|
||||
sticker: 'webp',
|
||||
video: 'mp4',
|
||||
animation: 'mp4',
|
||||
video_note: 'mp4',
|
||||
voice: 'ogg',
|
||||
};
|
||||
const DEFAULT_OPTIONS = {
|
||||
apiRoot: 'https://api.telegram.org',
|
||||
apiMode: 'bot',
|
||||
webhookReply: true,
|
||||
agent: new https.Agent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 10000,
|
||||
}),
|
||||
attachmentAgent: undefined,
|
||||
testEnv: false,
|
||||
};
|
||||
function includesMedia(payload) {
|
||||
return Object.values(payload).some((value) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.some(({ media }) => media && typeof media === 'object' && (media.source || media.url));
|
||||
}
|
||||
return (value &&
|
||||
typeof value === 'object' &&
|
||||
(((0, check_1.hasProp)(value, 'source') && value.source) ||
|
||||
((0, check_1.hasProp)(value, 'url') && value.url) ||
|
||||
((0, check_1.hasPropType)(value, 'media', 'object') &&
|
||||
(((0, check_1.hasProp)(value.media, 'source') && value.media.source) ||
|
||||
((0, check_1.hasProp)(value.media, 'url') && value.media.url)))));
|
||||
});
|
||||
}
|
||||
function replacer(_, value) {
|
||||
if (value == null)
|
||||
return undefined;
|
||||
return value;
|
||||
}
|
||||
function buildJSONConfig(payload) {
|
||||
return Promise.resolve({
|
||||
method: 'POST',
|
||||
compress: true,
|
||||
headers: { 'content-type': 'application/json', connection: 'keep-alive' },
|
||||
body: JSON.stringify(payload, replacer),
|
||||
});
|
||||
}
|
||||
const FORM_DATA_JSON_FIELDS = [
|
||||
'results',
|
||||
'reply_markup',
|
||||
'mask_position',
|
||||
'shipping_options',
|
||||
'errors',
|
||||
];
|
||||
async function buildFormDataConfig(payload, agent) {
|
||||
for (const field of FORM_DATA_JSON_FIELDS) {
|
||||
if ((0, check_1.hasProp)(payload, field) && typeof payload[field] !== 'string') {
|
||||
payload[field] = JSON.stringify(payload[field]);
|
||||
}
|
||||
}
|
||||
const boundary = crypto.randomBytes(32).toString('hex');
|
||||
const formData = new multipart_stream_1.default(boundary);
|
||||
const tasks = Object.keys(payload).map((key) => attachFormValue(formData, key, payload[key], agent));
|
||||
await Promise.all(tasks);
|
||||
return {
|
||||
method: 'POST',
|
||||
compress: true,
|
||||
headers: {
|
||||
'content-type': `multipart/form-data; boundary=${boundary}`,
|
||||
connection: 'keep-alive',
|
||||
},
|
||||
body: formData,
|
||||
};
|
||||
}
|
||||
async function attachFormValue(form, id, value, agent) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (typeof value === 'string' ||
|
||||
typeof value === 'boolean' ||
|
||||
typeof value === 'number') {
|
||||
form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: `${value}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (id === 'thumb') {
|
||||
const attachmentId = crypto.randomBytes(16).toString('hex');
|
||||
await attachFormMedia(form, value, attachmentId, agent);
|
||||
return form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: `attach://${attachmentId}`,
|
||||
});
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
const items = await Promise.all(value.map(async (item) => {
|
||||
if (typeof item.media !== 'object') {
|
||||
return await Promise.resolve(item);
|
||||
}
|
||||
const attachmentId = crypto.randomBytes(16).toString('hex');
|
||||
await attachFormMedia(form, item.media, attachmentId, agent);
|
||||
return { ...item, media: `attach://${attachmentId}` };
|
||||
}));
|
||||
return form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: JSON.stringify(items),
|
||||
});
|
||||
}
|
||||
if (value &&
|
||||
typeof value === 'object' &&
|
||||
(0, check_1.hasProp)(value, 'media') &&
|
||||
(0, check_1.hasProp)(value, 'type') &&
|
||||
typeof value.media !== 'undefined' &&
|
||||
typeof value.type !== 'undefined') {
|
||||
const attachmentId = crypto.randomBytes(16).toString('hex');
|
||||
await attachFormMedia(form, value.media, attachmentId, agent);
|
||||
return form.addPart({
|
||||
headers: { 'content-disposition': `form-data; name="${id}"` },
|
||||
body: JSON.stringify({
|
||||
...value,
|
||||
media: `attach://${attachmentId}`,
|
||||
}),
|
||||
});
|
||||
}
|
||||
return await attachFormMedia(form, value, id, agent);
|
||||
}
|
||||
async function attachFormMedia(form, media, id, agent) {
|
||||
var _a, _b, _c;
|
||||
let fileName = (_a = media.filename) !== null && _a !== void 0 ? _a : `${id}.${(_b = DEFAULT_EXTENSIONS[id]) !== null && _b !== void 0 ? _b : 'dat'}`;
|
||||
if (media.url !== undefined) {
|
||||
const res = await (0, node_fetch_1.default)(media.url, { agent });
|
||||
return form.addPart({
|
||||
headers: {
|
||||
'content-disposition': `form-data; name="${id}"; filename="${fileName}"`,
|
||||
},
|
||||
body: res.body,
|
||||
});
|
||||
}
|
||||
if (media.source) {
|
||||
let mediaSource = media.source;
|
||||
if (fs.existsSync(media.source)) {
|
||||
fileName = (_c = media.filename) !== null && _c !== void 0 ? _c : path.basename(media.source);
|
||||
mediaSource = fs.createReadStream(media.source);
|
||||
}
|
||||
if (isStream(mediaSource) || Buffer.isBuffer(mediaSource)) {
|
||||
form.addPart({
|
||||
headers: {
|
||||
'content-disposition': `form-data; name="${id}"; filename="${fileName}"`,
|
||||
},
|
||||
body: mediaSource,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
async function answerToWebhook(response, payload, options) {
|
||||
if (!includesMedia(payload)) {
|
||||
if (!response.headersSent) {
|
||||
response.setHeader('content-type', 'application/json');
|
||||
}
|
||||
response.end(JSON.stringify(payload), 'utf-8');
|
||||
return true;
|
||||
}
|
||||
const { headers, body } = await buildFormDataConfig(payload, options.attachmentAgent);
|
||||
if (!response.headersSent) {
|
||||
for (const [key, value] of Object.entries(headers)) {
|
||||
response.setHeader(key, value);
|
||||
}
|
||||
}
|
||||
await new Promise((resolve) => {
|
||||
response.on('finish', resolve);
|
||||
body.pipe(response);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
function redactToken(error) {
|
||||
error.message = error.message.replace(/\/(bot|user)(\d+):[^/]+\//, '/$1$2:[REDACTED]/');
|
||||
throw error;
|
||||
}
|
||||
class ApiClient {
|
||||
constructor(token, options, response) {
|
||||
this.token = token;
|
||||
this.response = response;
|
||||
this.options = {
|
||||
...DEFAULT_OPTIONS,
|
||||
...(0, compact_1.compactOptions)(options),
|
||||
};
|
||||
if (this.options.apiRoot.startsWith('http://')) {
|
||||
this.options.agent = undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* If set to `true`, first _eligible_ call will avoid performing a POST request.
|
||||
* Note that such a call:
|
||||
* 1. cannot report errors or return meaningful values,
|
||||
* 2. resolves before bot API has a chance to process it,
|
||||
* 3. prematurely confirms the update as processed.
|
||||
*
|
||||
* https://core.telegram.org/bots/faq#how-can-i-make-requests-in-response-to-updates
|
||||
* https://github.com/telegraf/telegraf/pull/1250
|
||||
*/
|
||||
set webhookReply(enable) {
|
||||
this.options.webhookReply = enable;
|
||||
}
|
||||
get webhookReply() {
|
||||
return this.options.webhookReply;
|
||||
}
|
||||
async callApi(method, payload, { signal } = {}) {
|
||||
const { token, options, response } = this;
|
||||
if (options.webhookReply &&
|
||||
(response === null || response === void 0 ? void 0 : response.writableEnded) === false &&
|
||||
WEBHOOK_REPLY_METHOD_ALLOWLIST.has(method)) {
|
||||
debug('Call via webhook', method, payload);
|
||||
// @ts-expect-error using webhookReply is an optimisation that doesn't respond with normal result
|
||||
// up to the user to deal with this
|
||||
return await answerToWebhook(response, { method, ...payload }, options);
|
||||
}
|
||||
if (!token) {
|
||||
throw new error_1.default({
|
||||
error_code: 401,
|
||||
description: 'Bot Token is required',
|
||||
});
|
||||
}
|
||||
debug('HTTP call', method, payload);
|
||||
const config = includesMedia(payload)
|
||||
? await buildFormDataConfig({ method, ...payload }, options.attachmentAgent)
|
||||
: await buildJSONConfig(payload);
|
||||
const apiUrl = new url_1.URL(`./${options.apiMode}${token}${options.testEnv ? '/test' : ''}/${method}`, options.apiRoot);
|
||||
config.agent = options.agent;
|
||||
config.signal = signal;
|
||||
const res = await (0, node_fetch_1.default)(apiUrl, config).catch(redactToken);
|
||||
if (res.status >= 500) {
|
||||
const errorPayload = {
|
||||
error_code: res.status,
|
||||
description: res.statusText,
|
||||
};
|
||||
throw new error_1.default(errorPayload, { method, payload });
|
||||
}
|
||||
const data = await res.json();
|
||||
if (!data.ok) {
|
||||
debug('API call failed', data);
|
||||
throw new error_1.default(data, { method, payload });
|
||||
}
|
||||
return data.result;
|
||||
}
|
||||
}
|
||||
exports.default = ApiClient;
|
21
node_modules/telegraf/lib/core/network/error.js
generated
vendored
Normal file
21
node_modules/telegraf/lib/core/network/error.js
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TelegramError = void 0;
|
||||
class TelegramError extends Error {
|
||||
constructor(response, on = {}) {
|
||||
super(`${response.error_code}: ${response.description}`);
|
||||
this.response = response;
|
||||
this.on = on;
|
||||
}
|
||||
get code() {
|
||||
return this.response.error_code;
|
||||
}
|
||||
get description() {
|
||||
return this.response.description;
|
||||
}
|
||||
get parameters() {
|
||||
return this.response.parameters;
|
||||
}
|
||||
}
|
||||
exports.TelegramError = TelegramError;
|
||||
exports.default = TelegramError;
|
61
node_modules/telegraf/lib/core/network/multipart-stream.js
generated
vendored
Normal file
61
node_modules/telegraf/lib/core/network/multipart-stream.js
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const stream = __importStar(require("stream"));
|
||||
const check_1 = require("../helpers/check");
|
||||
const sandwich_stream_1 = __importDefault(require("sandwich-stream"));
|
||||
const CRNL = '\r\n';
|
||||
class MultipartStream extends sandwich_stream_1.default {
|
||||
constructor(boundary) {
|
||||
super({
|
||||
head: `--${boundary}${CRNL}`,
|
||||
tail: `${CRNL}--${boundary}--`,
|
||||
separator: `${CRNL}--${boundary}${CRNL}`,
|
||||
});
|
||||
}
|
||||
addPart(part) {
|
||||
const partStream = new stream.PassThrough();
|
||||
for (const [key, header] of Object.entries(part.headers)) {
|
||||
partStream.write(`${key}:${header}${CRNL}`);
|
||||
}
|
||||
partStream.write(CRNL);
|
||||
if (MultipartStream.isStream(part.body)) {
|
||||
part.body.pipe(partStream);
|
||||
}
|
||||
else {
|
||||
partStream.end(part.body);
|
||||
}
|
||||
this.add(partStream);
|
||||
}
|
||||
static isStream(stream) {
|
||||
return (typeof stream === 'object' &&
|
||||
stream !== null &&
|
||||
(0, check_1.hasPropType)(stream, 'pipe', 'function'));
|
||||
}
|
||||
}
|
||||
exports.default = MultipartStream;
|
89
node_modules/telegraf/lib/core/network/polling.js
generated
vendored
Normal file
89
node_modules/telegraf/lib/core/network/polling.js
generated
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Polling = void 0;
|
||||
const abort_controller_1 = __importDefault(require("abort-controller"));
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const util_1 = require("util");
|
||||
const error_1 = require("./error");
|
||||
const debug = (0, debug_1.default)('telegraf:polling');
|
||||
const wait = (0, util_1.promisify)(setTimeout);
|
||||
function always(x) {
|
||||
return () => x;
|
||||
}
|
||||
const noop = always(Promise.resolve());
|
||||
class Polling {
|
||||
constructor(telegram, allowedUpdates) {
|
||||
this.telegram = telegram;
|
||||
this.allowedUpdates = allowedUpdates;
|
||||
this.abortController = new abort_controller_1.default();
|
||||
this.skipOffsetSync = false;
|
||||
this.offset = 0;
|
||||
}
|
||||
async *[Symbol.asyncIterator]() {
|
||||
var _a, _b;
|
||||
debug('Starting long polling');
|
||||
do {
|
||||
try {
|
||||
const updates = await this.telegram.callApi('getUpdates', {
|
||||
timeout: 50,
|
||||
offset: this.offset,
|
||||
allowed_updates: this.allowedUpdates,
|
||||
}, this.abortController);
|
||||
const last = updates[updates.length - 1];
|
||||
if (last !== undefined) {
|
||||
this.offset = last.update_id + 1;
|
||||
}
|
||||
yield updates;
|
||||
}
|
||||
catch (error) {
|
||||
const err = error;
|
||||
if (err.name === 'AbortError')
|
||||
return;
|
||||
if (err.name === 'FetchError' ||
|
||||
(err instanceof error_1.TelegramError && err.code === 429) ||
|
||||
(err instanceof error_1.TelegramError && err.code >= 500)) {
|
||||
const retryAfter = (_b = (_a = err.parameters) === null || _a === void 0 ? void 0 : _a.retry_after) !== null && _b !== void 0 ? _b : 5;
|
||||
debug('Failed to fetch updates, retrying after %ds.', retryAfter, err);
|
||||
await wait(retryAfter * 1000);
|
||||
continue;
|
||||
}
|
||||
if (err instanceof error_1.TelegramError &&
|
||||
// Unauthorized Conflict
|
||||
(err.code === 401 || err.code === 409)) {
|
||||
this.skipOffsetSync = true;
|
||||
throw err;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
} while (!this.abortController.signal.aborted);
|
||||
}
|
||||
async syncUpdateOffset() {
|
||||
if (this.skipOffsetSync)
|
||||
return;
|
||||
debug('Syncing update offset...');
|
||||
await this.telegram.callApi('getUpdates', { offset: this.offset, limit: 1 });
|
||||
}
|
||||
async loop(handleUpdate) {
|
||||
if (this.abortController.signal.aborted) {
|
||||
throw new Error('Polling instances must not be reused!');
|
||||
}
|
||||
try {
|
||||
for await (const updates of this) {
|
||||
await Promise.all(updates.map(handleUpdate));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
debug('Long polling stopped');
|
||||
// prevent instance reuse
|
||||
this.stop();
|
||||
await this.syncUpdateOffset().catch(noop);
|
||||
}
|
||||
}
|
||||
stop() {
|
||||
this.abortController.abort();
|
||||
}
|
||||
}
|
||||
exports.Polling = Polling;
|
54
node_modules/telegraf/lib/core/network/webhook.js
generated
vendored
Normal file
54
node_modules/telegraf/lib/core/network/webhook.js
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const debug = (0, debug_1.default)('telegraf:webhook');
|
||||
function generateWebhook(filter, updateHandler) {
|
||||
return async (req, res, next = () => {
|
||||
res.statusCode = 403;
|
||||
debug('Replying with status code', res.statusCode);
|
||||
res.end();
|
||||
}) => {
|
||||
debug('Incoming request', req.method, req.url);
|
||||
if (!filter(req)) {
|
||||
debug('Webhook filter failed', req.method, req.url);
|
||||
return next();
|
||||
}
|
||||
let update;
|
||||
try {
|
||||
if (req.body != null) {
|
||||
/* If req.body is already set, we expect it to be the parsed
|
||||
request body (update object) received from Telegram
|
||||
However, some libraries such as `serverless-http` set req.body to the
|
||||
raw buffer, so we'll handle that additionally */
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let body = req.body;
|
||||
// if body is Buffer, parse it into string
|
||||
if (body instanceof Buffer)
|
||||
body = String(req.body);
|
||||
// if body is string, parse it into object
|
||||
if (typeof body === 'string')
|
||||
body = JSON.parse(body);
|
||||
update = body;
|
||||
}
|
||||
else {
|
||||
let body = '';
|
||||
// parse each buffer to string and append to body
|
||||
for await (const chunk of req)
|
||||
body += String(chunk);
|
||||
// parse body to object
|
||||
update = JSON.parse(body);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// if any of the parsing steps fails, give up and respond with error
|
||||
res.writeHead(415).end();
|
||||
debug('Failed to parse request body:', error);
|
||||
return;
|
||||
}
|
||||
return await updateHandler(update, res);
|
||||
};
|
||||
}
|
||||
exports.default = generateWebhook;
|
26
node_modules/telegraf/lib/core/types/typegram.js
generated
vendored
Normal file
26
node_modules/telegraf/lib/core/types/typegram.js
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// internal type provisions
|
||||
__exportStar(require("typegram/api"), exports);
|
||||
__exportStar(require("typegram/markup"), exports);
|
||||
__exportStar(require("typegram/menu-button"), exports);
|
||||
__exportStar(require("typegram/inline"), exports);
|
||||
__exportStar(require("typegram/manage"), exports);
|
||||
__exportStar(require("typegram/message"), exports);
|
||||
__exportStar(require("typegram/passport"), exports);
|
||||
__exportStar(require("typegram/payment"), exports);
|
||||
__exportStar(require("typegram/update"), exports);
|
12
node_modules/telegraf/lib/deunionize.js
generated
vendored
Normal file
12
node_modules/telegraf/lib/deunionize.js
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deunionize = void 0;
|
||||
/**
|
||||
* Expose properties from all union variants.
|
||||
* @see https://github.com/telegraf/telegraf/issues/1388#issuecomment-791573609
|
||||
* @see https://millsp.github.io/ts-toolbelt/modules/union_strict.html
|
||||
*/
|
||||
function deunionize(t) {
|
||||
return t;
|
||||
}
|
||||
exports.deunionize = deunionize;
|
20
node_modules/telegraf/lib/format.js
generated
vendored
Normal file
20
node_modules/telegraf/lib/format.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mention = exports.link = exports.pre = exports.code = exports.underline = exports.strikethrough = exports.spoiler = exports.italic = exports.bold = exports.fmt = exports.FmtString = void 0;
|
||||
const formatting_1 = require("./core/helpers/formatting");
|
||||
Object.defineProperty(exports, "FmtString", { enumerable: true, get: function () { return formatting_1.FmtString; } });
|
||||
exports.fmt = (0, formatting_1._fmt)('very-plain');
|
||||
exports.bold = (0, formatting_1._fmt)('bold');
|
||||
exports.italic = (0, formatting_1._fmt)('italic');
|
||||
exports.spoiler = (0, formatting_1._fmt)('spoiler');
|
||||
exports.strikethrough = (0, formatting_1._fmt)('strikethrough');
|
||||
exports.underline = (0, formatting_1._fmt)('underline');
|
||||
exports.code = (0, formatting_1._fmt)('code');
|
||||
const pre = (language) => (0, formatting_1._fmt)('pre', { language });
|
||||
exports.pre = pre;
|
||||
const link = (content, url) => (0, formatting_1.linkOrMention)(content, { type: 'text_link', url });
|
||||
exports.link = link;
|
||||
const mention = (name, user) => typeof user === 'number'
|
||||
? (0, exports.link)(name, 'tg://user?id=' + user)
|
||||
: (0, formatting_1.linkOrMention)(name, { type: 'text_mention', user });
|
||||
exports.mention = mention;
|
148
node_modules/telegraf/lib/future.js
generated
vendored
Normal file
148
node_modules/telegraf/lib/future.js
generated
vendored
Normal file
|
@ -0,0 +1,148 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.useNewReplies = void 0;
|
||||
function makeReply(ctx, extra) {
|
||||
var _a;
|
||||
const reply_to_message_id = (_a = ctx.message) === null || _a === void 0 ? void 0 : _a.message_id;
|
||||
return { reply_to_message_id, ...extra };
|
||||
}
|
||||
const replyContext = {
|
||||
replyWithChatAction: function () {
|
||||
throw new TypeError('ctx.replyWithChatAction has been removed, use ctx.sendChatAction instead');
|
||||
},
|
||||
reply(text, extra) {
|
||||
this.assert(this.chat, 'reply');
|
||||
return this.telegram.sendMessage(this.chat.id, text, makeReply(this, extra));
|
||||
},
|
||||
replyWithAnimation(animation, extra) {
|
||||
this.assert(this.chat, 'replyWithAnimation');
|
||||
return this.telegram.sendAnimation(this.chat.id, animation, makeReply(this, extra));
|
||||
},
|
||||
replyWithAudio(audio, extra) {
|
||||
this.assert(this.chat, 'replyWithAudio');
|
||||
return this.telegram.sendAudio(this.chat.id, audio, makeReply(this, extra));
|
||||
},
|
||||
replyWithContact(phoneNumber, firstName, extra) {
|
||||
this.assert(this.chat, 'replyWithContact');
|
||||
return this.telegram.sendContact(this.chat.id, phoneNumber, firstName, makeReply(this, extra));
|
||||
},
|
||||
replyWithDice(extra) {
|
||||
this.assert(this.chat, 'replyWithDice');
|
||||
return this.telegram.sendDice(this.chat.id, makeReply(this, extra));
|
||||
},
|
||||
replyWithDocument(document, extra) {
|
||||
this.assert(this.chat, 'replyWithDocument');
|
||||
return this.telegram.sendDocument(this.chat.id, document, makeReply(this, extra));
|
||||
},
|
||||
replyWithGame(gameName, extra) {
|
||||
this.assert(this.chat, 'replyWithGame');
|
||||
return this.telegram.sendGame(this.chat.id, gameName, makeReply(this, extra));
|
||||
},
|
||||
replyWithHTML(html, extra) {
|
||||
var _a;
|
||||
this.assert(this.chat, 'replyWithHTML');
|
||||
return this.telegram.sendMessage(this.chat.id, html, {
|
||||
parse_mode: 'HTML',
|
||||
reply_to_message_id: (_a = this.message) === null || _a === void 0 ? void 0 : _a.message_id,
|
||||
...extra,
|
||||
});
|
||||
},
|
||||
replyWithInvoice(invoice, extra) {
|
||||
this.assert(this.chat, 'replyWithInvoice');
|
||||
return this.telegram.sendInvoice(this.chat.id, invoice, makeReply(this, extra));
|
||||
},
|
||||
replyWithLocation(latitude, longitude, extra) {
|
||||
this.assert(this.chat, 'replyWithLocation');
|
||||
return this.telegram.sendLocation(this.chat.id, latitude, longitude, makeReply(this, extra));
|
||||
},
|
||||
replyWithMarkdown(markdown, extra) {
|
||||
var _a;
|
||||
this.assert(this.chat, 'replyWithMarkdown');
|
||||
return this.telegram.sendMessage(this.chat.id, markdown, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: (_a = this.message) === null || _a === void 0 ? void 0 : _a.message_id,
|
||||
...extra,
|
||||
});
|
||||
},
|
||||
replyWithMarkdownV2(markdown, extra) {
|
||||
var _a;
|
||||
this.assert(this.chat, 'replyWithMarkdownV2');
|
||||
return this.telegram.sendMessage(this.chat.id, markdown, {
|
||||
parse_mode: 'MarkdownV2',
|
||||
reply_to_message_id: (_a = this.message) === null || _a === void 0 ? void 0 : _a.message_id,
|
||||
...extra,
|
||||
});
|
||||
},
|
||||
replyWithMediaGroup(media, extra) {
|
||||
this.assert(this.chat, 'replyWithMediaGroup');
|
||||
return this.telegram.sendMediaGroup(this.chat.id, media, makeReply(this, extra));
|
||||
},
|
||||
replyWithPhoto(photo, extra) {
|
||||
this.assert(this.chat, 'replyWithPhoto');
|
||||
return this.telegram.sendPhoto(this.chat.id, photo, makeReply(this, extra));
|
||||
},
|
||||
replyWithPoll(question, options, extra) {
|
||||
this.assert(this.chat, 'replyWithPoll');
|
||||
return this.telegram.sendPoll(this.chat.id, question, options, makeReply(this, extra));
|
||||
},
|
||||
replyWithQuiz(question, options, extra) {
|
||||
this.assert(this.chat, 'replyWithQuiz');
|
||||
return this.telegram.sendQuiz(this.chat.id, question, options, makeReply(this, extra));
|
||||
},
|
||||
replyWithSticker(sticker, extra) {
|
||||
this.assert(this.chat, 'replyWithSticker');
|
||||
return this.telegram.sendSticker(this.chat.id, sticker, makeReply(this, extra));
|
||||
},
|
||||
replyWithVenue(latitude, longitude, title, address, extra) {
|
||||
this.assert(this.chat, 'replyWithVenue');
|
||||
return this.telegram.sendVenue(this.chat.id, latitude, longitude, title, address, makeReply(this, extra));
|
||||
},
|
||||
replyWithVideo(video, extra) {
|
||||
this.assert(this.chat, 'replyWithVideo');
|
||||
return this.telegram.sendVideo(this.chat.id, video, makeReply(this, extra));
|
||||
},
|
||||
replyWithVideoNote(videoNote, extra) {
|
||||
this.assert(this.chat, 'replyWithVideoNote');
|
||||
return this.telegram.sendVideoNote(this.chat.id, videoNote, makeReply(this, extra));
|
||||
},
|
||||
replyWithVoice(voice, extra) {
|
||||
this.assert(this.chat, 'replyWithVoice');
|
||||
return this.telegram.sendVoice(this.chat.id, voice, makeReply(this, extra));
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Sets up Context to use the new reply methods.
|
||||
* This middleware makes `ctx.reply()` and `ctx.replyWith*()` methods will actually reply to the message they are replying to.
|
||||
* Use `ctx.sendMessage()` to send a message in chat without replying to it.
|
||||
*
|
||||
* If the message to reply is deleted, `reply()` will send a normal message.
|
||||
* If the update is not a message and we are unable to reply, `reply()` will send a normal message.
|
||||
*/
|
||||
function useNewReplies() {
|
||||
return (ctx, next) => {
|
||||
ctx.reply = replyContext.reply;
|
||||
ctx.replyWithPhoto = replyContext.replyWithPhoto;
|
||||
ctx.replyWithMediaGroup = replyContext.replyWithMediaGroup;
|
||||
ctx.replyWithAudio = replyContext.replyWithAudio;
|
||||
ctx.replyWithDice = replyContext.replyWithDice;
|
||||
ctx.replyWithDocument = replyContext.replyWithDocument;
|
||||
ctx.replyWithSticker = replyContext.replyWithSticker;
|
||||
ctx.replyWithVideo = replyContext.replyWithVideo;
|
||||
ctx.replyWithAnimation = replyContext.replyWithAnimation;
|
||||
ctx.replyWithVideoNote = replyContext.replyWithVideoNote;
|
||||
ctx.replyWithInvoice = replyContext.replyWithInvoice;
|
||||
ctx.replyWithGame = replyContext.replyWithGame;
|
||||
ctx.replyWithVoice = replyContext.replyWithVoice;
|
||||
ctx.replyWithPoll = replyContext.replyWithPoll;
|
||||
ctx.replyWithQuiz = replyContext.replyWithQuiz;
|
||||
ctx.replyWithChatAction = replyContext.replyWithChatAction;
|
||||
ctx.replyWithLocation = replyContext.replyWithLocation;
|
||||
ctx.replyWithVenue = replyContext.replyWithVenue;
|
||||
ctx.replyWithContact = replyContext.replyWithContact;
|
||||
ctx.replyWithMarkdown = replyContext.replyWithMarkdown;
|
||||
ctx.replyWithMarkdownV2 = replyContext.replyWithMarkdownV2;
|
||||
ctx.replyWithHTML = replyContext.replyWithHTML;
|
||||
return next();
|
||||
};
|
||||
}
|
||||
exports.useNewReplies = useNewReplies;
|
48
node_modules/telegraf/lib/index.js
generated
vendored
Normal file
48
node_modules/telegraf/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Scenes = exports.MemorySessionStore = exports.session = exports.deunionize = exports.Format = exports.Input = exports.Markup = exports.Types = exports.Telegram = exports.TelegramError = exports.Router = exports.Composer = exports.Context = exports.Telegraf = void 0;
|
||||
var telegraf_1 = require("./telegraf");
|
||||
Object.defineProperty(exports, "Telegraf", { enumerable: true, get: function () { return telegraf_1.Telegraf; } });
|
||||
var context_1 = require("./context");
|
||||
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
|
||||
var composer_1 = require("./composer");
|
||||
Object.defineProperty(exports, "Composer", { enumerable: true, get: function () { return composer_1.Composer; } });
|
||||
var router_1 = require("./router");
|
||||
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
|
||||
var error_1 = require("./core/network/error");
|
||||
Object.defineProperty(exports, "TelegramError", { enumerable: true, get: function () { return error_1.TelegramError; } });
|
||||
var telegram_1 = require("./telegram");
|
||||
Object.defineProperty(exports, "Telegram", { enumerable: true, get: function () { return telegram_1.Telegram; } });
|
||||
exports.Types = __importStar(require("./telegram-types"));
|
||||
exports.Markup = __importStar(require("./markup"));
|
||||
exports.Input = __importStar(require("./input"));
|
||||
exports.Format = __importStar(require("./format"));
|
||||
var deunionize_1 = require("./deunionize");
|
||||
Object.defineProperty(exports, "deunionize", { enumerable: true, get: function () { return deunionize_1.deunionize; } });
|
||||
var session_1 = require("./session");
|
||||
Object.defineProperty(exports, "session", { enumerable: true, get: function () { return session_1.session; } });
|
||||
Object.defineProperty(exports, "MemorySessionStore", { enumerable: true, get: function () { return session_1.MemorySessionStore; } });
|
||||
exports.Scenes = __importStar(require("./scenes"));
|
61
node_modules/telegraf/lib/input.js
generated
vendored
Normal file
61
node_modules/telegraf/lib/input.js
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.fromFileId = exports.fromURL = exports.fromURLStream = exports.fromReadableStream = exports.fromBuffer = exports.fromLocalFile = void 0;
|
||||
/**
|
||||
* The local file specified by path will be uploaded to Telegram using multipart/form-data.
|
||||
*
|
||||
* 10 MB max size for photos, 50 MB for other files.
|
||||
*/
|
||||
// prettier-ignore
|
||||
const fromLocalFile = (path, filename) => ({ source: path, filename });
|
||||
exports.fromLocalFile = fromLocalFile;
|
||||
/**
|
||||
* The buffer will be uploaded as file to Telegram using multipart/form-data.
|
||||
*
|
||||
* 10 MB max size for photos, 50 MB for other files.
|
||||
*/
|
||||
// prettier-ignore
|
||||
const fromBuffer = (buffer, filename) => ({ source: buffer, filename });
|
||||
exports.fromBuffer = fromBuffer;
|
||||
/**
|
||||
* Contents of the stream will be uploaded as file to Telegram using multipart/form-data.
|
||||
*
|
||||
* 10 MB max size for photos, 50 MB for other files.
|
||||
*/
|
||||
// prettier-ignore
|
||||
const fromReadableStream = (stream, filename) => ({ source: stream, filename });
|
||||
exports.fromReadableStream = fromReadableStream;
|
||||
/**
|
||||
* Contents of the URL will be streamed to Telegram.
|
||||
*
|
||||
* 10 MB max size for photos, 50 MB for other files.
|
||||
*/
|
||||
// prettier-ignore
|
||||
const fromURLStream = (url, filename) => ({ url: url.toString(), filename });
|
||||
exports.fromURLStream = fromURLStream;
|
||||
/**
|
||||
* Provide Telegram with an HTTP URL for the file to be sent.
|
||||
* Telegram will download and send the file.
|
||||
*
|
||||
* * The target file must have the correct MIME type (e.g., audio/mpeg for `sendAudio`, etc.).
|
||||
* * `sendDocument` with URL will currently only work for GIF, PDF and ZIP files.
|
||||
* * To use `sendVoice`, the file must have the type audio/ogg and be no more than 1MB in size.
|
||||
* 1-20MB voice notes will be sent as files.
|
||||
*
|
||||
* 5 MB max size for photos and 20 MB max for other types of content.
|
||||
*/
|
||||
const fromURL = (url) => url.toString();
|
||||
exports.fromURL = fromURL;
|
||||
/**
|
||||
* If the file is already stored somewhere on the Telegram servers, you don't need to reupload it:
|
||||
* each file object has a file_id field, simply pass this file_id as a parameter instead of uploading.
|
||||
*
|
||||
* It is not possible to change the file type when resending by file_id.
|
||||
*
|
||||
* It is not possible to resend thumbnails using file_id.
|
||||
* They have to be uploaded using one of the other Input methods.
|
||||
*
|
||||
* There are no limits for files sent this way.
|
||||
*/
|
||||
const fromFileId = (fileId) => fileId;
|
||||
exports.fromFileId = fromFileId;
|
105
node_modules/telegraf/lib/markup.js
generated
vendored
Normal file
105
node_modules/telegraf/lib/markup.js
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.inlineKeyboard = exports.keyboard = exports.forceReply = exports.removeKeyboard = exports.button = exports.Markup = void 0;
|
||||
const check_1 = require("./core/helpers/check");
|
||||
class Markup {
|
||||
constructor(reply_markup) {
|
||||
this.reply_markup = reply_markup;
|
||||
}
|
||||
selective(value = true) {
|
||||
return new Markup({ ...this.reply_markup, selective: value });
|
||||
}
|
||||
placeholder(placeholder) {
|
||||
return new Markup({
|
||||
...this.reply_markup,
|
||||
input_field_placeholder: placeholder,
|
||||
});
|
||||
}
|
||||
resize(value = true) {
|
||||
return new Markup({
|
||||
...this.reply_markup,
|
||||
resize_keyboard: value,
|
||||
});
|
||||
}
|
||||
oneTime(value = true) {
|
||||
return new Markup({
|
||||
...this.reply_markup,
|
||||
one_time_keyboard: value,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Markup = Markup;
|
||||
exports.button = __importStar(require("./button"));
|
||||
function removeKeyboard() {
|
||||
return new Markup({ remove_keyboard: true });
|
||||
}
|
||||
exports.removeKeyboard = removeKeyboard;
|
||||
function forceReply() {
|
||||
return new Markup({ force_reply: true });
|
||||
}
|
||||
exports.forceReply = forceReply;
|
||||
function keyboard(buttons, options) {
|
||||
const keyboard = buildKeyboard(buttons, {
|
||||
columns: 1,
|
||||
...options,
|
||||
});
|
||||
return new Markup({ keyboard });
|
||||
}
|
||||
exports.keyboard = keyboard;
|
||||
function inlineKeyboard(buttons, options) {
|
||||
const inlineKeyboard = buildKeyboard(buttons, {
|
||||
columns: buttons.length,
|
||||
...options,
|
||||
});
|
||||
return new Markup({ inline_keyboard: inlineKeyboard });
|
||||
}
|
||||
exports.inlineKeyboard = inlineKeyboard;
|
||||
function buildKeyboard(buttons, options) {
|
||||
const result = [];
|
||||
if (!Array.isArray(buttons)) {
|
||||
return result;
|
||||
}
|
||||
if ((0, check_1.is2D)(buttons)) {
|
||||
return buttons.map((row) => row.filter((button) => !button.hide));
|
||||
}
|
||||
const wrapFn = options.wrap !== undefined
|
||||
? options.wrap
|
||||
: (_btn, _index, currentRow) => currentRow.length >= options.columns;
|
||||
let currentRow = [];
|
||||
let index = 0;
|
||||
for (const btn of buttons.filter((button) => !button.hide)) {
|
||||
if (wrapFn(btn, index, currentRow) && currentRow.length > 0) {
|
||||
result.push(currentRow);
|
||||
currentRow = [];
|
||||
}
|
||||
currentRow.push(btn);
|
||||
index++;
|
||||
}
|
||||
if (currentRow.length > 0) {
|
||||
result.push(currentRow);
|
||||
}
|
||||
return result;
|
||||
}
|
2
node_modules/telegraf/lib/middleware.js
generated
vendored
Normal file
2
node_modules/telegraf/lib/middleware.js
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
46
node_modules/telegraf/lib/router.js
generated
vendored
Normal file
46
node_modules/telegraf/lib/router.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
"use strict";
|
||||
/** @format */
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Router = void 0;
|
||||
const composer_1 = __importDefault(require("./composer"));
|
||||
/** @deprecated in favor of {@link Composer.dispatch} */
|
||||
class Router {
|
||||
constructor(routeFn, handlers = new Map()) {
|
||||
this.routeFn = routeFn;
|
||||
this.handlers = handlers;
|
||||
this.otherwiseHandler = composer_1.default.passThru();
|
||||
if (typeof routeFn !== 'function') {
|
||||
throw new Error('Missing routing function');
|
||||
}
|
||||
}
|
||||
on(route, ...fns) {
|
||||
if (fns.length === 0) {
|
||||
throw new TypeError('At least one handler must be provided');
|
||||
}
|
||||
this.handlers.set(route, composer_1.default.compose(fns));
|
||||
return this;
|
||||
}
|
||||
otherwise(...fns) {
|
||||
if (fns.length === 0) {
|
||||
throw new TypeError('At least one otherwise handler must be provided');
|
||||
}
|
||||
this.otherwiseHandler = composer_1.default.compose(fns);
|
||||
return this;
|
||||
}
|
||||
middleware() {
|
||||
return composer_1.default.lazy((ctx) => {
|
||||
var _a;
|
||||
const result = this.routeFn(ctx);
|
||||
if (result == null) {
|
||||
return this.otherwiseHandler;
|
||||
}
|
||||
Object.assign(ctx, result.context);
|
||||
Object.assign(ctx.state, result.state);
|
||||
return (_a = this.handlers.get(result.route)) !== null && _a !== void 0 ? _a : this.otherwiseHandler;
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Router = Router;
|
39
node_modules/telegraf/lib/scenes/base.js
generated
vendored
Normal file
39
node_modules/telegraf/lib/scenes/base.js
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BaseScene = void 0;
|
||||
const composer_1 = __importDefault(require("../composer"));
|
||||
const { compose } = composer_1.default;
|
||||
class BaseScene extends composer_1.default {
|
||||
constructor(id, options) {
|
||||
const opts = {
|
||||
handlers: [],
|
||||
enterHandlers: [],
|
||||
leaveHandlers: [],
|
||||
...options,
|
||||
};
|
||||
super(...opts.handlers);
|
||||
this.id = id;
|
||||
this.ttl = opts.ttl;
|
||||
this.enterHandler = compose(opts.enterHandlers);
|
||||
this.leaveHandler = compose(opts.leaveHandlers);
|
||||
}
|
||||
enter(...fns) {
|
||||
this.enterHandler = compose([this.enterHandler, ...fns]);
|
||||
return this;
|
||||
}
|
||||
leave(...fns) {
|
||||
this.leaveHandler = compose([this.leaveHandler, ...fns]);
|
||||
return this;
|
||||
}
|
||||
enterMiddleware() {
|
||||
return this.enterHandler;
|
||||
}
|
||||
leaveMiddleware() {
|
||||
return this.leaveHandler;
|
||||
}
|
||||
}
|
||||
exports.BaseScene = BaseScene;
|
||||
exports.default = BaseScene;
|
104
node_modules/telegraf/lib/scenes/context.js
generated
vendored
Normal file
104
node_modules/telegraf/lib/scenes/context.js
generated
vendored
Normal file
|
@ -0,0 +1,104 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const composer_1 = __importDefault(require("../composer"));
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const debug = (0, debug_1.default)('telegraf:scenes:context');
|
||||
const noop = () => Promise.resolve();
|
||||
const now = () => Math.floor(Date.now() / 1000);
|
||||
class SceneContextScene {
|
||||
constructor(ctx, scenes, options) {
|
||||
this.ctx = ctx;
|
||||
this.scenes = scenes;
|
||||
this.leaving = false;
|
||||
// @ts-expect-error {} might not be assignable to D
|
||||
const fallbackSessionDefault = {};
|
||||
this.options = { defaultSession: fallbackSessionDefault, ...options };
|
||||
}
|
||||
get session() {
|
||||
var _a, _b;
|
||||
const defaultSession = this.options.defaultSession;
|
||||
let session = (_b = (_a = this.ctx.session) === null || _a === void 0 ? void 0 : _a.__scenes) !== null && _b !== void 0 ? _b : defaultSession;
|
||||
if (session.expires !== undefined && session.expires < now()) {
|
||||
session = defaultSession;
|
||||
}
|
||||
if (this.ctx.session === undefined) {
|
||||
this.ctx.session = { __scenes: session };
|
||||
}
|
||||
else {
|
||||
this.ctx.session.__scenes = session;
|
||||
}
|
||||
return session;
|
||||
}
|
||||
get state() {
|
||||
var _a;
|
||||
var _b;
|
||||
return ((_a = (_b = this.session).state) !== null && _a !== void 0 ? _a : (_b.state = {}));
|
||||
}
|
||||
set state(value) {
|
||||
this.session.state = { ...value };
|
||||
}
|
||||
get current() {
|
||||
var _a;
|
||||
const sceneId = (_a = this.session.current) !== null && _a !== void 0 ? _a : this.options.default;
|
||||
return sceneId === undefined || !this.scenes.has(sceneId)
|
||||
? undefined
|
||||
: this.scenes.get(sceneId);
|
||||
}
|
||||
reset() {
|
||||
if (this.ctx.session !== undefined)
|
||||
this.ctx.session.__scenes = this.options.defaultSession;
|
||||
}
|
||||
async enter(sceneId, initialState = {}, silent = false) {
|
||||
var _a, _b;
|
||||
if (!this.scenes.has(sceneId)) {
|
||||
throw new Error(`Can't find scene: ${sceneId}`);
|
||||
}
|
||||
if (!silent) {
|
||||
await this.leave();
|
||||
}
|
||||
debug('Entering scene', sceneId, initialState, silent);
|
||||
this.session.current = sceneId;
|
||||
this.state = initialState;
|
||||
const ttl = (_b = (_a = this.current) === null || _a === void 0 ? void 0 : _a.ttl) !== null && _b !== void 0 ? _b : this.options.ttl;
|
||||
if (ttl !== undefined) {
|
||||
this.session.expires = now() + ttl;
|
||||
}
|
||||
if (this.current === undefined || silent) {
|
||||
return;
|
||||
}
|
||||
const handler = 'enterMiddleware' in this.current &&
|
||||
typeof this.current.enterMiddleware === 'function'
|
||||
? this.current.enterMiddleware()
|
||||
: this.current.middleware();
|
||||
return await handler(this.ctx, noop);
|
||||
}
|
||||
reenter() {
|
||||
return this.session.current === undefined
|
||||
? undefined
|
||||
: this.enter(this.session.current, this.state);
|
||||
}
|
||||
async leave() {
|
||||
if (this.leaving)
|
||||
return;
|
||||
debug('Leaving scene');
|
||||
try {
|
||||
this.leaving = true;
|
||||
if (this.current === undefined) {
|
||||
return;
|
||||
}
|
||||
const handler = 'leaveMiddleware' in this.current &&
|
||||
typeof this.current.leaveMiddleware === 'function'
|
||||
? this.current.leaveMiddleware()
|
||||
: composer_1.default.passThru();
|
||||
await handler(this.ctx, noop);
|
||||
return this.reset();
|
||||
}
|
||||
finally {
|
||||
this.leaving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = SceneContextScene;
|
21
node_modules/telegraf/lib/scenes/index.js
generated
vendored
Normal file
21
node_modules/telegraf/lib/scenes/index.js
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
"use strict";
|
||||
/**
|
||||
* @see https://github.com/telegraf/telegraf/issues/705#issuecomment-549056045
|
||||
* @see https://www.npmjs.com/package/telegraf-stateless-question
|
||||
* @packageDocumentation
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WizardContextWizard = exports.WizardScene = exports.BaseScene = exports.SceneContextScene = exports.Stage = void 0;
|
||||
var stage_1 = require("./stage");
|
||||
Object.defineProperty(exports, "Stage", { enumerable: true, get: function () { return stage_1.Stage; } });
|
||||
var context_1 = require("./context");
|
||||
Object.defineProperty(exports, "SceneContextScene", { enumerable: true, get: function () { return __importDefault(context_1).default; } });
|
||||
var base_1 = require("./base");
|
||||
Object.defineProperty(exports, "BaseScene", { enumerable: true, get: function () { return base_1.BaseScene; } });
|
||||
var wizard_1 = require("./wizard");
|
||||
Object.defineProperty(exports, "WizardScene", { enumerable: true, get: function () { return wizard_1.WizardScene; } });
|
||||
var context_2 = require("./wizard/context");
|
||||
Object.defineProperty(exports, "WizardContextWizard", { enumerable: true, get: function () { return __importDefault(context_2).default; } });
|
49
node_modules/telegraf/lib/scenes/stage.js
generated
vendored
Normal file
49
node_modules/telegraf/lib/scenes/stage.js
generated
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Stage = void 0;
|
||||
const session_1 = require("../session");
|
||||
const context_1 = __importDefault(require("./context"));
|
||||
const composer_1 = require("../composer");
|
||||
class Stage extends composer_1.Composer {
|
||||
constructor(scenes = [], options) {
|
||||
super();
|
||||
this.options = { ...options };
|
||||
this.scenes = new Map();
|
||||
scenes.forEach((scene) => this.register(scene));
|
||||
}
|
||||
register(...scenes) {
|
||||
scenes.forEach((scene) => {
|
||||
if ((scene === null || scene === void 0 ? void 0 : scene.id) == null || typeof scene.middleware !== 'function') {
|
||||
throw new Error('telegraf: Unsupported scene');
|
||||
}
|
||||
this.scenes.set(scene.id, scene);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
middleware() {
|
||||
const handler = composer_1.Composer.compose([
|
||||
(ctx, next) => {
|
||||
const scenes = this.scenes;
|
||||
const scene = new context_1.default(ctx, scenes, this.options);
|
||||
ctx.scene = scene;
|
||||
return next();
|
||||
},
|
||||
super.middleware(),
|
||||
composer_1.Composer.lazy((ctx) => { var _a; return (_a = ctx.scene.current) !== null && _a !== void 0 ? _a : composer_1.Composer.passThru(); }),
|
||||
]);
|
||||
return composer_1.Composer.optional(session_1.isSessionContext, handler);
|
||||
}
|
||||
static enter(...args) {
|
||||
return (ctx) => ctx.scene.enter(...args);
|
||||
}
|
||||
static reenter(...args) {
|
||||
return (ctx) => ctx.scene.reenter(...args);
|
||||
}
|
||||
static leave(...args) {
|
||||
return (ctx) => ctx.scene.leave(...args);
|
||||
}
|
||||
}
|
||||
exports.Stage = Stage;
|
31
node_modules/telegraf/lib/scenes/wizard/context.js
generated
vendored
Normal file
31
node_modules/telegraf/lib/scenes/wizard/context.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class WizardContextWizard {
|
||||
constructor(ctx, steps) {
|
||||
var _a;
|
||||
this.ctx = ctx;
|
||||
this.steps = steps;
|
||||
this.state = ctx.scene.state;
|
||||
this.cursor = (_a = ctx.scene.session.cursor) !== null && _a !== void 0 ? _a : 0;
|
||||
}
|
||||
get step() {
|
||||
return this.steps[this.cursor];
|
||||
}
|
||||
get cursor() {
|
||||
return this.ctx.scene.session.cursor;
|
||||
}
|
||||
set cursor(cursor) {
|
||||
this.ctx.scene.session.cursor = cursor;
|
||||
}
|
||||
selectStep(index) {
|
||||
this.cursor = index;
|
||||
return this;
|
||||
}
|
||||
next() {
|
||||
return this.selectStep(this.cursor + 1);
|
||||
}
|
||||
back() {
|
||||
return this.selectStep(this.cursor - 1);
|
||||
}
|
||||
}
|
||||
exports.default = WizardContextWizard;
|
45
node_modules/telegraf/lib/scenes/wizard/index.js
generated
vendored
Normal file
45
node_modules/telegraf/lib/scenes/wizard/index.js
generated
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WizardScene = void 0;
|
||||
const base_1 = __importDefault(require("../base"));
|
||||
const context_1 = __importDefault(require("./context"));
|
||||
const composer_1 = __importDefault(require("../../composer"));
|
||||
class WizardScene extends base_1.default {
|
||||
constructor(id, options, ...steps) {
|
||||
let opts;
|
||||
let s;
|
||||
if (typeof options === 'function' || 'middleware' in options) {
|
||||
opts = undefined;
|
||||
s = [options, ...steps];
|
||||
}
|
||||
else {
|
||||
opts = options;
|
||||
s = steps;
|
||||
}
|
||||
super(id, opts);
|
||||
this.steps = s;
|
||||
}
|
||||
middleware() {
|
||||
return composer_1.default.compose([
|
||||
(ctx, next) => {
|
||||
ctx.wizard = new context_1.default(ctx, this.steps);
|
||||
return next();
|
||||
},
|
||||
super.middleware(),
|
||||
(ctx, next) => {
|
||||
if (ctx.wizard.step === undefined) {
|
||||
ctx.wizard.selectStep(0);
|
||||
return ctx.scene.leave();
|
||||
}
|
||||
return composer_1.default.unwrap(ctx.wizard.step)(ctx, next);
|
||||
},
|
||||
]);
|
||||
}
|
||||
enterMiddleware() {
|
||||
return composer_1.default.compose([this.enterHandler, this.middleware()]);
|
||||
}
|
||||
}
|
||||
exports.WizardScene = WizardScene;
|
77
node_modules/telegraf/lib/session.js
generated
vendored
Normal file
77
node_modules/telegraf/lib/session.js
generated
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isSessionContext = exports.MemorySessionStore = exports.session = void 0;
|
||||
/**
|
||||
* Returns middleware that adds `ctx.session` for storing arbitrary state per session key.
|
||||
*
|
||||
* The default `getSessionKey` is <code>\`${ctx.from.id}:${ctx.chat.id}\`</code>.
|
||||
* If either `ctx.from` or `ctx.chat` is `undefined`, default session key and thus `ctx.session` are also `undefined`.
|
||||
*
|
||||
* Session data is kept only in memory by default,
|
||||
* which means that all data will be lost when the process is terminated.
|
||||
* If you want to store data across restarts, or share it among workers,
|
||||
* you can [install persistent session middleware from npm](https://www.npmjs.com/search?q=telegraf-session),
|
||||
* or pass custom `storage`.
|
||||
*
|
||||
* @example https://github.com/telegraf/telegraf/blob/develop/docs/examples/session-bot.ts
|
||||
* @deprecated https://github.com/telegraf/telegraf/issues/1372#issuecomment-782668499
|
||||
*/
|
||||
function session(options) {
|
||||
var _a, _b;
|
||||
const getSessionKey = (_a = options === null || options === void 0 ? void 0 : options.getSessionKey) !== null && _a !== void 0 ? _a : defaultGetSessionKey;
|
||||
const store = (_b = options === null || options === void 0 ? void 0 : options.store) !== null && _b !== void 0 ? _b : new MemorySessionStore();
|
||||
return async (ctx, next) => {
|
||||
const key = await getSessionKey(ctx);
|
||||
if (key == null) {
|
||||
return await next();
|
||||
}
|
||||
ctx.session = await store.get(key);
|
||||
await next();
|
||||
if (ctx.session == null) {
|
||||
await store.delete(key);
|
||||
}
|
||||
else {
|
||||
await store.set(key, ctx.session);
|
||||
}
|
||||
};
|
||||
}
|
||||
exports.session = session;
|
||||
async function defaultGetSessionKey(ctx) {
|
||||
var _a, _b;
|
||||
const fromId = (_a = ctx.from) === null || _a === void 0 ? void 0 : _a.id;
|
||||
const chatId = (_b = ctx.chat) === null || _b === void 0 ? void 0 : _b.id;
|
||||
if (fromId == null || chatId == null) {
|
||||
return undefined;
|
||||
}
|
||||
return `${fromId}:${chatId}`;
|
||||
}
|
||||
/** @deprecated https://github.com/telegraf/telegraf/issues/1372#issuecomment-782668499 */
|
||||
class MemorySessionStore {
|
||||
constructor(ttl = Infinity) {
|
||||
this.ttl = ttl;
|
||||
this.store = new Map();
|
||||
}
|
||||
get(name) {
|
||||
const entry = this.store.get(name);
|
||||
if (entry == null) {
|
||||
return undefined;
|
||||
}
|
||||
else if (entry.expires < Date.now()) {
|
||||
this.delete(name);
|
||||
return undefined;
|
||||
}
|
||||
return entry.session;
|
||||
}
|
||||
set(name, value) {
|
||||
const now = Date.now();
|
||||
this.store.set(name, { session: value, expires: now + this.ttl });
|
||||
}
|
||||
delete(name) {
|
||||
this.store.delete(name);
|
||||
}
|
||||
}
|
||||
exports.MemorySessionStore = MemorySessionStore;
|
||||
function isSessionContext(ctx) {
|
||||
return 'session' in ctx;
|
||||
}
|
||||
exports.isSessionContext = isSessionContext;
|
241
node_modules/telegraf/lib/telegraf.js
generated
vendored
Normal file
241
node_modules/telegraf/lib/telegraf.js
generated
vendored
Normal file
|
@ -0,0 +1,241 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Telegraf = void 0;
|
||||
const crypto = __importStar(require("crypto"));
|
||||
const http = __importStar(require("http"));
|
||||
const https = __importStar(require("https"));
|
||||
const composer_1 = require("./composer");
|
||||
const compact_1 = require("./core/helpers/compact");
|
||||
const context_1 = __importDefault(require("./context"));
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const webhook_1 = __importDefault(require("./core/network/webhook"));
|
||||
const polling_1 = require("./core/network/polling");
|
||||
const p_timeout_1 = __importDefault(require("p-timeout"));
|
||||
const telegram_1 = __importDefault(require("./telegram"));
|
||||
const url_1 = require("url");
|
||||
const safeCompare = require("safe-compare");
|
||||
const debug = (0, debug_1.default)('telegraf:main');
|
||||
const DEFAULT_OPTIONS = {
|
||||
telegram: {},
|
||||
handlerTimeout: 90000,
|
||||
contextType: context_1.default,
|
||||
};
|
||||
function always(x) {
|
||||
return () => x;
|
||||
}
|
||||
const anoop = always(Promise.resolve());
|
||||
const TOKEN_HEADER = 'x-telegram-bot-api-secret-token';
|
||||
class Telegraf extends composer_1.Composer {
|
||||
constructor(token, options) {
|
||||
super();
|
||||
this.context = {};
|
||||
/** Assign to this to customise the webhook filter middleware.
|
||||
* `{ hookPath, secretToken }` will be bound to this rather than the Telegraf instance.
|
||||
* Remember to assign a regular function and not an arrow function so it's bindable.
|
||||
*/
|
||||
this.webhookFilter = function (req) {
|
||||
const debug = (0, debug_1.default)('telegraf:webhook');
|
||||
if (req.method === 'POST') {
|
||||
if (safeCompare(this.hookPath, req.url)) {
|
||||
// no need to check if secret_token was not set
|
||||
if (!this.secretToken)
|
||||
return true;
|
||||
else {
|
||||
const token = req.headers[TOKEN_HEADER];
|
||||
if (safeCompare(this.secretToken, token))
|
||||
return true;
|
||||
else
|
||||
debug('Secret token does not match:', token, this.secretToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
debug('Path does not match:', req.url, this.hookPath);
|
||||
}
|
||||
else
|
||||
debug('Unexpected request method, not POST. Received:', req.method);
|
||||
return false;
|
||||
};
|
||||
this.handleError = (err, ctx) => {
|
||||
// set exit code to emulate `warn-with-error-code` behavior of
|
||||
// https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode
|
||||
// to prevent a clean exit despite an error being thrown
|
||||
process.exitCode = 1;
|
||||
console.error('Unhandled error while processing', ctx.update);
|
||||
throw err;
|
||||
};
|
||||
// @ts-expect-error Trust me, TS
|
||||
this.options = {
|
||||
...DEFAULT_OPTIONS,
|
||||
...(0, compact_1.compactOptions)(options),
|
||||
};
|
||||
this.telegram = new telegram_1.default(token, this.options.telegram);
|
||||
debug('Created a `Telegraf` instance');
|
||||
}
|
||||
get token() {
|
||||
return this.telegram.token;
|
||||
}
|
||||
/** @deprecated use `ctx.telegram.webhookReply` */
|
||||
set webhookReply(webhookReply) {
|
||||
this.telegram.webhookReply = webhookReply;
|
||||
}
|
||||
/** @deprecated use `ctx.telegram.webhookReply` */
|
||||
get webhookReply() {
|
||||
return this.telegram.webhookReply;
|
||||
}
|
||||
/**
|
||||
* _Override_ error handling
|
||||
*/
|
||||
catch(handler) {
|
||||
this.handleError = handler;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* You must call `bot.telegram.setWebhook` for this to work.
|
||||
* You should probably use {@link Telegraf.createWebhook} instead.
|
||||
*/
|
||||
webhookCallback(hookPath = '/', opts = {}) {
|
||||
const { secretToken } = opts;
|
||||
return (0, webhook_1.default)(this.webhookFilter.bind({ hookPath, secretToken }), (update, res) => this.handleUpdate(update, res));
|
||||
}
|
||||
getDomainOpts(opts) {
|
||||
var _a;
|
||||
const protocol = opts.domain.startsWith('https://') || opts.domain.startsWith('http://');
|
||||
if (protocol)
|
||||
debug('Unexpected protocol in domain, telegraf will use https:', opts.domain);
|
||||
const domain = protocol ? new url_1.URL(opts.domain).host : opts.domain;
|
||||
const path = (_a = opts.path) !== null && _a !== void 0 ? _a : `/telegraf/${this.secretPathComponent()}`;
|
||||
const url = `https://${domain}${path}`;
|
||||
return { domain, path, url };
|
||||
}
|
||||
/**
|
||||
* Specify a url to receive incoming updates via webhook.
|
||||
* Returns an Express-style middleware you can pass to app.use()
|
||||
*/
|
||||
async createWebhook(opts) {
|
||||
const { domain, path, ...extra } = opts;
|
||||
const domainOpts = this.getDomainOpts({ domain, path });
|
||||
await this.telegram.setWebhook(domainOpts.url, extra);
|
||||
debug(`Webhook set to ${domainOpts.url}`);
|
||||
return this.webhookCallback(domainOpts.path, {
|
||||
secretToken: extra.secret_token,
|
||||
});
|
||||
}
|
||||
startPolling(allowedUpdates = []) {
|
||||
this.polling = new polling_1.Polling(this.telegram, allowedUpdates);
|
||||
this.polling.loop(async (update) => {
|
||||
await this.handleUpdate(update);
|
||||
});
|
||||
}
|
||||
startWebhook(hookPath, tlsOptions, port, host, cb, secretToken) {
|
||||
const webhookCb = this.webhookCallback(hookPath, { secretToken });
|
||||
const callback = typeof cb === 'function'
|
||||
? (req, res) => webhookCb(req, res, () => cb(req, res))
|
||||
: webhookCb;
|
||||
this.webhookServer =
|
||||
tlsOptions != null
|
||||
? https.createServer(tlsOptions, callback)
|
||||
: http.createServer(callback);
|
||||
this.webhookServer.listen(port, host, () => {
|
||||
debug('Webhook listening on port: %s', port);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
secretPathComponent() {
|
||||
return crypto
|
||||
.createHash('sha3-256')
|
||||
.update(this.token)
|
||||
.update(process.version) // salt
|
||||
.digest('hex');
|
||||
}
|
||||
/**
|
||||
* @see https://github.com/telegraf/telegraf/discussions/1344#discussioncomment-335700
|
||||
*/
|
||||
async launch(config = {}) {
|
||||
var _a;
|
||||
debug('Connecting to Telegram');
|
||||
(_a = this.botInfo) !== null && _a !== void 0 ? _a : (this.botInfo = await this.telegram.getMe());
|
||||
debug(`Launching @${this.botInfo.username}`);
|
||||
if (config.webhook === undefined) {
|
||||
await this.telegram.deleteWebhook({
|
||||
drop_pending_updates: config.dropPendingUpdates,
|
||||
});
|
||||
this.startPolling(config.allowedUpdates);
|
||||
debug('Bot started with long polling');
|
||||
return;
|
||||
}
|
||||
const domainOpts = this.getDomainOpts({
|
||||
domain: config.webhook.domain,
|
||||
path: config.webhook.hookPath,
|
||||
});
|
||||
const { tlsOptions, port, host, cb, secretToken } = config.webhook;
|
||||
this.startWebhook(domainOpts.path, tlsOptions, port, host, cb, secretToken);
|
||||
await this.telegram.setWebhook(domainOpts.url, {
|
||||
drop_pending_updates: config.dropPendingUpdates,
|
||||
allowed_updates: config.allowedUpdates,
|
||||
ip_address: config.webhook.ipAddress,
|
||||
max_connections: config.webhook.maxConnections,
|
||||
secret_token: config.webhook.secretToken,
|
||||
certificate: config.webhook.certificate,
|
||||
});
|
||||
debug(`Bot started with webhook @ ${domainOpts.url}`);
|
||||
}
|
||||
stop(reason = 'unspecified') {
|
||||
var _a, _b;
|
||||
debug('Stopping bot... Reason:', reason);
|
||||
// https://github.com/telegraf/telegraf/pull/1224#issuecomment-742693770
|
||||
if (this.polling === undefined && this.webhookServer === undefined) {
|
||||
throw new Error('Bot is not running!');
|
||||
}
|
||||
(_a = this.webhookServer) === null || _a === void 0 ? void 0 : _a.close();
|
||||
(_b = this.polling) === null || _b === void 0 ? void 0 : _b.stop();
|
||||
}
|
||||
async handleUpdate(update, webhookResponse) {
|
||||
var _a, _b;
|
||||
(_a = this.botInfo) !== null && _a !== void 0 ? _a : (this.botInfo = (debug('Update %d is waiting for `botInfo` to be initialized', update.update_id),
|
||||
await ((_b = this.botInfoCall) !== null && _b !== void 0 ? _b : (this.botInfoCall = this.telegram.getMe()))));
|
||||
debug('Processing update', update.update_id);
|
||||
const tg = new telegram_1.default(this.token, this.telegram.options, webhookResponse);
|
||||
const TelegrafContext = this.options.contextType;
|
||||
const ctx = new TelegrafContext(update, tg, this.botInfo);
|
||||
Object.assign(ctx, this.context);
|
||||
try {
|
||||
await (0, p_timeout_1.default)(Promise.resolve(this.middleware()(ctx, anoop)), this.options.handlerTimeout);
|
||||
}
|
||||
catch (err) {
|
||||
return await this.handleError(err, ctx);
|
||||
}
|
||||
finally {
|
||||
if ((webhookResponse === null || webhookResponse === void 0 ? void 0 : webhookResponse.writableEnded) === false) {
|
||||
webhookResponse.end();
|
||||
}
|
||||
debug('Finished processing update', update.update_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Telegraf = Telegraf;
|
6
node_modules/telegraf/lib/telegram-types.js
generated
vendored
Normal file
6
node_modules/telegraf/lib/telegram-types.js
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
"use strict";
|
||||
/** @format */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Markup = void 0;
|
||||
var markup_1 = require("./markup");
|
||||
Object.defineProperty(exports, "Markup", { enumerable: true, get: function () { return markup_1.Markup; } });
|
900
node_modules/telegraf/lib/telegram.js
generated
vendored
Normal file
900
node_modules/telegraf/lib/telegram.js
generated
vendored
Normal file
|
@ -0,0 +1,900 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Telegram = void 0;
|
||||
const client_1 = __importDefault(require("./core/network/client"));
|
||||
const path_1 = require("path");
|
||||
const url_1 = require("url");
|
||||
const format_1 = require("./format");
|
||||
const util_1 = require("./util");
|
||||
class Telegram extends client_1.default {
|
||||
/**
|
||||
* Get basic information about the bot
|
||||
*/
|
||||
getMe() {
|
||||
return this.callApi('getMe', {});
|
||||
}
|
||||
/**
|
||||
* Get basic info about a file and prepare it for downloading.
|
||||
* @param fileId Id of file to get link to
|
||||
*/
|
||||
getFile(fileId) {
|
||||
return this.callApi('getFile', { file_id: fileId });
|
||||
}
|
||||
/**
|
||||
* Get download link to a file.
|
||||
*/
|
||||
async getFileLink(fileId) {
|
||||
if (typeof fileId === 'string') {
|
||||
fileId = await this.getFile(fileId);
|
||||
}
|
||||
else if (fileId.file_path === undefined) {
|
||||
fileId = await this.getFile(fileId.file_id);
|
||||
}
|
||||
// Local bot API instances return the absolute path to the file
|
||||
if (fileId.file_path !== undefined && (0, path_1.isAbsolute)(fileId.file_path)) {
|
||||
const url = new url_1.URL(this.options.apiRoot);
|
||||
url.port = '';
|
||||
url.pathname = fileId.file_path;
|
||||
url.protocol = 'file:';
|
||||
return url;
|
||||
}
|
||||
return new url_1.URL(
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
`./file/${this.options.apiMode}${this.token}/${fileId.file_path}`, this.options.apiRoot);
|
||||
}
|
||||
/**
|
||||
* Directly request incoming updates.
|
||||
* You should probably use `Telegraf::launch` instead.
|
||||
*/
|
||||
getUpdates(timeout, limit, offset, allowedUpdates) {
|
||||
return this.callApi('getUpdates', {
|
||||
allowed_updates: allowedUpdates,
|
||||
limit,
|
||||
offset,
|
||||
timeout,
|
||||
});
|
||||
}
|
||||
getWebhookInfo() {
|
||||
return this.callApi('getWebhookInfo', {});
|
||||
}
|
||||
getGameHighScores(userId, inlineMessageId, chatId, messageId) {
|
||||
return this.callApi('getGameHighScores', {
|
||||
user_id: userId,
|
||||
inline_message_id: inlineMessageId,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
setGameScore(userId, score, inlineMessageId, chatId, messageId, editMessage = true, force = false) {
|
||||
return this.callApi('setGameScore', {
|
||||
force,
|
||||
score,
|
||||
user_id: userId,
|
||||
inline_message_id: inlineMessageId,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
disable_edit_message: !editMessage,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Specify a url to receive incoming updates via an outgoing webhook.
|
||||
* @param url HTTPS url to send updates to. Use an empty string to remove webhook integration
|
||||
*/
|
||||
setWebhook(url, extra) {
|
||||
return this.callApi('setWebhook', {
|
||||
url,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Remove webhook integration.
|
||||
*/
|
||||
deleteWebhook(extra) {
|
||||
return this.callApi('deleteWebhook', {
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send a text message.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param text Text of the message to be sent
|
||||
*/
|
||||
sendMessage(chatId, text, extra) {
|
||||
const t = format_1.FmtString.normalise(text);
|
||||
return this.callApi('sendMessage', { chat_id: chatId, ...extra, ...t });
|
||||
}
|
||||
/**
|
||||
* Forward existing message.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
|
||||
* @param messageId Message identifier in the chat specified in from_chat_id
|
||||
*/
|
||||
forwardMessage(chatId, fromChatId, messageId, extra) {
|
||||
return this.callApi('forwardMessage', {
|
||||
chat_id: chatId,
|
||||
from_chat_id: fromChatId,
|
||||
message_id: messageId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Use this method when you need to tell the user that something is happening on the bot's side.
|
||||
* The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendChatAction(chatId, action) {
|
||||
return this.callApi('sendChatAction', { chat_id: chatId, action });
|
||||
}
|
||||
getUserProfilePhotos(userId, offset, limit) {
|
||||
return this.callApi('getUserProfilePhotos', {
|
||||
user_id: userId,
|
||||
offset,
|
||||
limit,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send point on the map.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendLocation(chatId, latitude, longitude, extra) {
|
||||
return this.callApi('sendLocation', {
|
||||
chat_id: chatId,
|
||||
latitude,
|
||||
longitude,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
sendVenue(chatId, latitude, longitude, title, address, extra) {
|
||||
return this.callApi('sendVenue', {
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
address,
|
||||
chat_id: chatId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param chatId Unique identifier for the target private chat
|
||||
*/
|
||||
sendInvoice(chatId, invoice, extra) {
|
||||
return this.callApi('sendInvoice', {
|
||||
chat_id: chatId,
|
||||
...invoice,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
sendContact(chatId, phoneNumber, firstName, extra) {
|
||||
return this.callApi('sendContact', {
|
||||
chat_id: chatId,
|
||||
phone_number: phoneNumber,
|
||||
first_name: firstName,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendPhoto(chatId, photo, extra) {
|
||||
return this.callApi('sendPhoto', {
|
||||
chat_id: chatId,
|
||||
photo,
|
||||
...(0, util_1.fmtCaption)(extra),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send a dice, which will have a random value from 1 to 6.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendDice(chatId, extra) {
|
||||
return this.callApi('sendDice', { chat_id: chatId, ...extra });
|
||||
}
|
||||
/**
|
||||
* Send general files. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendDocument(chatId, document, extra) {
|
||||
return this.callApi('sendDocument', {
|
||||
chat_id: chatId,
|
||||
document,
|
||||
...(0, util_1.fmtCaption)(extra),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send audio files, if you want Telegram clients to display them in the music player.
|
||||
* Your audio must be in the .mp3 format.
|
||||
* Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendAudio(chatId, audio, extra) {
|
||||
return this.callApi('sendAudio', {
|
||||
chat_id: chatId,
|
||||
audio,
|
||||
...(0, util_1.fmtCaption)(extra),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send .webp, animated .tgs, or video .webm stickers
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendSticker(chatId, sticker, extra) {
|
||||
return this.callApi('sendSticker', { chat_id: chatId, sticker, ...extra });
|
||||
}
|
||||
/**
|
||||
* Send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
|
||||
* Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendVideo(chatId, video, extra) {
|
||||
return this.callApi('sendVideo', {
|
||||
chat_id: chatId,
|
||||
video,
|
||||
...(0, util_1.fmtCaption)(extra),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send .gif animations.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendAnimation(chatId, animation, extra) {
|
||||
return this.callApi('sendAnimation', {
|
||||
chat_id: chatId,
|
||||
animation,
|
||||
...(0, util_1.fmtCaption)(extra),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send video messages.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendVideoNote(chatId, videoNote, extra) {
|
||||
return this.callApi('sendVideoNote', {
|
||||
chat_id: chatId,
|
||||
video_note: videoNote,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
sendVoice(chatId, voice, extra) {
|
||||
return this.callApi('sendVoice', {
|
||||
chat_id: chatId,
|
||||
voice,
|
||||
...(0, util_1.fmtCaption)(extra),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat
|
||||
* @param gameShortName Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
|
||||
*/
|
||||
sendGame(chatId, gameName, extra) {
|
||||
return this.callApi('sendGame', {
|
||||
chat_id: chatId,
|
||||
game_short_name: gameName,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send a group of photos or videos as an album.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param media A JSON-serialized array describing photos and videos to be sent, must include 2–10 items
|
||||
*/
|
||||
sendMediaGroup(chatId, media, extra) {
|
||||
return this.callApi('sendMediaGroup', { chat_id: chatId, media, ...extra });
|
||||
}
|
||||
/**
|
||||
* Send a native poll.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param question Poll question, 1-255 characters
|
||||
* @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
|
||||
*/
|
||||
sendPoll(chatId, question, options, extra) {
|
||||
return this.callApi('sendPoll', {
|
||||
chat_id: chatId,
|
||||
type: 'regular',
|
||||
question,
|
||||
options,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send a native quiz.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param question Poll question, 1-255 characters
|
||||
* @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each
|
||||
*/
|
||||
sendQuiz(chatId, question, options, extra) {
|
||||
return this.callApi('sendPoll', {
|
||||
chat_id: chatId,
|
||||
type: 'quiz',
|
||||
question,
|
||||
options,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param messageId Identifier of the original message with the poll
|
||||
*/
|
||||
stopPoll(chatId, messageId, extra) {
|
||||
return this.callApi('stopPoll', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
*/
|
||||
getChat(chatId) {
|
||||
return this.callApi('getChat', { chat_id: chatId });
|
||||
}
|
||||
/**
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
*/
|
||||
getChatAdministrators(chatId) {
|
||||
return this.callApi('getChatAdministrators', { chat_id: chatId });
|
||||
}
|
||||
/**
|
||||
* Get information about a member of a chat.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
* @param userId Unique identifier of the target user
|
||||
*/
|
||||
getChatMember(chatId, userId) {
|
||||
return this.callApi('getChatMember', { chat_id: chatId, user_id: userId });
|
||||
}
|
||||
/**
|
||||
* Get the number of members in a chat.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
*/
|
||||
getChatMembersCount(chatId) {
|
||||
return this.callApi('getChatMembersCount', { chat_id: chatId });
|
||||
}
|
||||
/**
|
||||
* Send answers to an inline query.
|
||||
* No more than 50 results per query are allowed.
|
||||
*/
|
||||
answerInlineQuery(inlineQueryId, results, extra) {
|
||||
return this.callApi('answerInlineQuery', {
|
||||
inline_query_id: inlineQueryId,
|
||||
results,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
setChatPermissions(chatId, permissions) {
|
||||
return this.callApi('setChatPermissions', { chat_id: chatId, permissions });
|
||||
}
|
||||
/**
|
||||
* Kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||
* @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
|
||||
* @param untilDate Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
|
||||
*/
|
||||
banChatMember(chatId, userId, untilDate, extra) {
|
||||
return this.callApi('banChatMember', {
|
||||
chat_id: chatId,
|
||||
user_id: userId,
|
||||
until_date: untilDate,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||
* @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
|
||||
* @param untilDate Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever
|
||||
* @deprecated since API 5.3. Use {@link Telegram.banChatMember}
|
||||
*/
|
||||
get kickChatMember() {
|
||||
return this.banChatMember;
|
||||
}
|
||||
/**
|
||||
* Promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
|
||||
*/
|
||||
promoteChatMember(chatId, userId, extra) {
|
||||
return this.callApi('promoteChatMember', {
|
||||
chat_id: chatId,
|
||||
user_id: userId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
restrictChatMember(chatId, userId, extra) {
|
||||
return this.callApi('restrictChatMember', {
|
||||
chat_id: chatId,
|
||||
user_id: userId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
setChatAdministratorCustomTitle(chatId, userId, title) {
|
||||
return this.callApi('setChatAdministratorCustomTitle', {
|
||||
chat_id: chatId,
|
||||
user_id: userId,
|
||||
custom_title: title,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
exportChatInviteLink(chatId) {
|
||||
return this.callApi('exportChatInviteLink', { chat_id: chatId });
|
||||
}
|
||||
createChatInviteLink(chatId, extra) {
|
||||
return this.callApi('createChatInviteLink', {
|
||||
chat_id: chatId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
createInvoiceLink(invoice) {
|
||||
return this.callApi('createInvoiceLink', {
|
||||
...invoice,
|
||||
});
|
||||
}
|
||||
editChatInviteLink(chatId, inviteLink, extra) {
|
||||
return this.callApi('editChatInviteLink', {
|
||||
chat_id: chatId,
|
||||
invite_link: inviteLink,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
revokeChatInviteLink(chatId, inviteLink) {
|
||||
return this.callApi('revokeChatInviteLink', {
|
||||
chat_id: chatId,
|
||||
invite_link: inviteLink,
|
||||
});
|
||||
}
|
||||
setChatPhoto(chatId, photo) {
|
||||
return this.callApi('setChatPhoto', { chat_id: chatId, photo });
|
||||
}
|
||||
deleteChatPhoto(chatId) {
|
||||
return this.callApi('deleteChatPhoto', { chat_id: chatId });
|
||||
}
|
||||
/**
|
||||
* Change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||
* @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
|
||||
* @param title New chat title, 1-255 characters
|
||||
*/
|
||||
setChatTitle(chatId, title) {
|
||||
return this.callApi('setChatTitle', { chat_id: chatId, title });
|
||||
}
|
||||
setChatDescription(chatId, description) {
|
||||
return this.callApi('setChatDescription', { chat_id: chatId, description });
|
||||
}
|
||||
/**
|
||||
* Pin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in the supergroup or 'can_edit_messages' admin right in the channel.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
||||
*/
|
||||
pinChatMessage(chatId, messageId, extra) {
|
||||
return this.callApi('pinChatMessage', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Unpin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in the supergroup or 'can_edit_messages' admin right in the channel.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
unpinChatMessage(chatId, messageId) {
|
||||
return this.callApi('unpinChatMessage', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Clear the list of pinned messages in a chat.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
unpinAllChatMessages(chatId) {
|
||||
return this.callApi('unpinAllChatMessages', { chat_id: chatId });
|
||||
}
|
||||
/**
|
||||
* Use this method for your bot to leave a group, supergroup or channel.
|
||||
* @param chatId Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
|
||||
*/
|
||||
leaveChat(chatId) {
|
||||
return this.callApi('leaveChat', { chat_id: chatId });
|
||||
}
|
||||
/**
|
||||
* Unban a user from a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
|
||||
* @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @username)
|
||||
* @param userId Unique identifier of the target user
|
||||
*/
|
||||
unbanChatMember(chatId, userId, extra) {
|
||||
return this.callApi('unbanChatMember', {
|
||||
chat_id: chatId,
|
||||
user_id: userId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
answerCbQuery(callbackQueryId, text, extra) {
|
||||
return this.callApi('answerCallbackQuery', {
|
||||
text,
|
||||
callback_query_id: callbackQueryId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
answerGameQuery(callbackQueryId, url) {
|
||||
return this.callApi('answerCallbackQuery', {
|
||||
url,
|
||||
callback_query_id: callbackQueryId,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* If you sent an invoice requesting a shipping address and the parameter is_flexible was specified,
|
||||
* the Bot API will send an Update with a shipping_query field to the bot.
|
||||
* Reply to shipping queries.
|
||||
* @param ok Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
|
||||
* @param shippingOptions Required if ok is True. A JSON-serialized array of available shipping options.
|
||||
* @param errorMessage Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
|
||||
*/
|
||||
answerShippingQuery(shippingQueryId, ok, shippingOptions, errorMessage) {
|
||||
return this.callApi('answerShippingQuery', {
|
||||
ok,
|
||||
shipping_query_id: shippingQueryId,
|
||||
shipping_options: shippingOptions,
|
||||
error_message: errorMessage,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query.
|
||||
* Respond to such pre-checkout queries. On success, True is returned.
|
||||
* Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
|
||||
* @param ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
|
||||
* @param errorMessage Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
|
||||
*/
|
||||
answerPreCheckoutQuery(preCheckoutQueryId, ok, errorMessage) {
|
||||
return this.callApi('answerPreCheckoutQuery', {
|
||||
ok,
|
||||
pre_checkout_query_id: preCheckoutQueryId,
|
||||
error_message: errorMessage,
|
||||
});
|
||||
}
|
||||
answerWebAppQuery(webAppQueryId, result) {
|
||||
return this.callApi('answerWebAppQuery', {
|
||||
web_app_query_id: webAppQueryId,
|
||||
result,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Edit text and game messages sent by the bot or via the bot (for inline bots).
|
||||
* On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
* @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
|
||||
* @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
|
||||
* @param text New text of the message
|
||||
*/
|
||||
editMessageText(chatId, messageId, inlineMessageId, text, extra) {
|
||||
const t = format_1.FmtString.normalise(text);
|
||||
return this.callApi('editMessageText', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
...extra,
|
||||
...t,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Edit captions of messages sent by the bot or via the bot (for inline bots).
|
||||
* On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
* @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
|
||||
* @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
|
||||
* @param caption New caption of the message
|
||||
* @param markup A JSON-serialized object for an inline keyboard.
|
||||
*/
|
||||
editMessageCaption(chatId, messageId, inlineMessageId, caption, extra) {
|
||||
// fmt may have entities (and parse_mode: undefined if entities are present)
|
||||
const { text, ...fmt } = caption
|
||||
? format_1.FmtString.normalise(caption)
|
||||
: { text: undefined };
|
||||
return this.callApi('editMessageCaption', {
|
||||
caption: text,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
...extra,
|
||||
...fmt,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Edit animation, audio, document, photo, or video messages.
|
||||
* If a message is a part of a message album, then it can be edited only to a photo or a video.
|
||||
* Otherwise, message type can be changed arbitrarily.
|
||||
* When inline message is edited, new file can't be uploaded.
|
||||
* Use previously uploaded file via its file_id or specify a URL.
|
||||
* @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
|
||||
* @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
|
||||
* @param media New media of message
|
||||
* @param markup Markup of inline keyboard
|
||||
*/
|
||||
editMessageMedia(chatId, messageId, inlineMessageId, media, extra) {
|
||||
return this.callApi('editMessageMedia', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
media,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
|
||||
* @param chatId Required if inlineMessageId is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param messageId Required if inlineMessageId is not specified. Identifier of the sent message
|
||||
* @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message
|
||||
* @param markup A JSON-serialized object for an inline keyboard.
|
||||
* @returns If edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
|
||||
*/
|
||||
editMessageReplyMarkup(chatId, messageId, inlineMessageId, markup) {
|
||||
return this.callApi('editMessageReplyMarkup', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
reply_markup: markup,
|
||||
});
|
||||
}
|
||||
editMessageLiveLocation(chatId, messageId, inlineMessageId, latitude, longitude, extra) {
|
||||
return this.callApi('editMessageLiveLocation', {
|
||||
latitude,
|
||||
longitude,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
stopMessageLiveLocation(chatId, messageId, inlineMessageId, markup) {
|
||||
return this.callApi('stopMessageLiveLocation', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
inline_message_id: inlineMessageId,
|
||||
reply_markup: markup,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Delete a message, including service messages, with the following limitations:
|
||||
* - A message can only be deleted if it was sent less than 48 hours ago.
|
||||
* - Bots can delete outgoing messages in groups and supergroups.
|
||||
* - Bots granted can_post_messages permissions can delete outgoing messages in channels.
|
||||
* - If the bot is an administrator of a group, it can delete any message there.
|
||||
* - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
*/
|
||||
deleteMessage(chatId, messageId) {
|
||||
return this.callApi('deleteMessage', {
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
setChatStickerSet(chatId, setName) {
|
||||
return this.callApi('setChatStickerSet', {
|
||||
chat_id: chatId,
|
||||
sticker_set_name: setName,
|
||||
});
|
||||
}
|
||||
deleteChatStickerSet(chatId) {
|
||||
return this.callApi('deleteChatStickerSet', { chat_id: chatId });
|
||||
}
|
||||
getStickerSet(name) {
|
||||
return this.callApi('getStickerSet', { name });
|
||||
}
|
||||
/**
|
||||
* Upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times).
|
||||
* https://core.telegram.org/bots/api#sending-files
|
||||
* @param ownerId User identifier of sticker file owner
|
||||
* @param stickerFile Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
|
||||
*/
|
||||
uploadStickerFile(ownerId, stickerFile) {
|
||||
return this.callApi('uploadStickerFile', {
|
||||
user_id: ownerId,
|
||||
png_sticker: stickerFile,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create new sticker set owned by a user. The bot will be able to edit the created sticker set.
|
||||
* @param ownerId User identifier of created sticker set owner
|
||||
* @param name Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
|
||||
* @param title Sticker set title, 1-64 characters
|
||||
*/
|
||||
createNewStickerSet(ownerId, name, title, stickerData) {
|
||||
return this.callApi('createNewStickerSet', {
|
||||
name,
|
||||
title,
|
||||
user_id: ownerId,
|
||||
...stickerData,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Add a new sticker to a set created by the bot.
|
||||
* @param ownerId User identifier of sticker set owner
|
||||
* @param name Sticker set name
|
||||
*/
|
||||
addStickerToSet(ownerId, name, stickerData) {
|
||||
return this.callApi('addStickerToSet', {
|
||||
name,
|
||||
user_id: ownerId,
|
||||
...stickerData,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Move a sticker in a set created by the bot to a specific position.
|
||||
* @param sticker File identifier of the sticker
|
||||
* @param position New sticker position in the set, zero-based
|
||||
*/
|
||||
setStickerPositionInSet(sticker, position) {
|
||||
return this.callApi('setStickerPositionInSet', {
|
||||
sticker,
|
||||
position,
|
||||
});
|
||||
}
|
||||
setStickerSetThumb(name, userId, thumb) {
|
||||
return this.callApi('setStickerSetThumb', { name, user_id: userId, thumb });
|
||||
}
|
||||
/**
|
||||
* Delete a sticker from a set created by the bot.
|
||||
* @param sticker File identifier of the sticker
|
||||
*/
|
||||
deleteStickerFromSet(sticker) {
|
||||
return this.callApi('deleteStickerFromSet', { sticker });
|
||||
}
|
||||
getCustomEmojiStickers(custom_emoji_ids) {
|
||||
return this.callApi('getCustomEmojiStickers', { custom_emoji_ids });
|
||||
}
|
||||
/**
|
||||
* Get the current list of the bot's commands.
|
||||
*/
|
||||
getMyCommands(extra = {}) {
|
||||
return this.callApi('getMyCommands', extra);
|
||||
}
|
||||
/**
|
||||
* Change the list of the bot's commands.
|
||||
* @param commands A list of bot commands to be set as the list of the bot's commands. At most 100 commands can be specified.
|
||||
*/
|
||||
setMyCommands(commands, extra) {
|
||||
return this.callApi('setMyCommands', { commands, ...extra });
|
||||
}
|
||||
deleteMyCommands(extra = {}) {
|
||||
return this.callApi('deleteMyCommands', extra);
|
||||
}
|
||||
setPassportDataErrors(userId, errors) {
|
||||
return this.callApi('setPassportDataErrors', {
|
||||
user_id: userId,
|
||||
errors: errors,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send copy of existing message.
|
||||
* @deprecated use `copyMessage` instead
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param message Received message object
|
||||
*/
|
||||
sendCopy(chatId, message, extra) {
|
||||
return this.copyMessage(chatId, message.chat.id, message.message_id, extra);
|
||||
}
|
||||
/**
|
||||
* Send copy of existing message.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
|
||||
* @param messageId Message identifier in the chat specified in from_chat_id
|
||||
*/
|
||||
copyMessage(chatId, fromChatId, messageId, extra) {
|
||||
return this.callApi('copyMessage', {
|
||||
chat_id: chatId,
|
||||
from_chat_id: fromChatId,
|
||||
message_id: messageId,
|
||||
...(0, util_1.fmtCaption)(extra),
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Approve a chat join request.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param userId Unique identifier of the target user
|
||||
*/
|
||||
approveChatJoinRequest(chatId, userId) {
|
||||
return this.callApi('approveChatJoinRequest', {
|
||||
chat_id: chatId,
|
||||
user_id: userId,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Decline a chat join request.
|
||||
* The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param userId Unique identifier of the target user
|
||||
*/
|
||||
declineChatJoinRequest(chatId, userId) {
|
||||
return this.callApi('declineChatJoinRequest', {
|
||||
chat_id: chatId,
|
||||
user_id: userId,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first.
|
||||
* The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param senderChatId Unique identifier of the target sender chat
|
||||
*/
|
||||
banChatSenderChat(chatId, senderChatId, extra) {
|
||||
return this.callApi('banChatSenderChat', {
|
||||
chat_id: chatId,
|
||||
sender_chat_id: senderChatId,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Unban a previously banned channel chat in a supergroup or channel.
|
||||
* The bot must be an administrator for this to work and must have the appropriate administrator rights.
|
||||
* @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
* @param senderChatId Unique identifier of the target sender chat
|
||||
*/
|
||||
unbanChatSenderChat(chatId, senderChatId) {
|
||||
return this.callApi('unbanChatSenderChat', {
|
||||
chat_id: chatId,
|
||||
sender_chat_id: senderChatId,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Use this method to change the bot's menu button in a private chat, or the default menu button. Returns true on success.
|
||||
* @param chatId Unique identifier for the target private chat. If not specified, default bot's menu button will be changed.
|
||||
* @param menuButton An object for the bot's new menu button.
|
||||
*/
|
||||
setChatMenuButton({ chatId, menuButton, } = {}) {
|
||||
return this.callApi('setChatMenuButton', {
|
||||
chat_id: chatId,
|
||||
menu_button: menuButton,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success.
|
||||
* @param chatId Unique identifier for the target private chat. If not specified, default bot's menu button will be returned.
|
||||
*/
|
||||
getChatMenuButton({ chatId } = {}) {
|
||||
return this.callApi('getChatMenuButton', {
|
||||
chat_id: chatId,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels.
|
||||
* These rights will be suggested to users, but they are are free to modify the list before adding the bot.
|
||||
*/
|
||||
setMyDefaultAdministratorRights({ rights, forChannels, } = {}) {
|
||||
return this.callApi('setMyDefaultAdministratorRights', {
|
||||
rights,
|
||||
for_channels: forChannels,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.
|
||||
* @param forChannels Pass true to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned.
|
||||
*/
|
||||
getMyDefaultAdministratorRights({ forChannels, } = {}) {
|
||||
return this.callApi('getMyDefaultAdministratorRights', {
|
||||
for_channels: forChannels,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Log out from the cloud Bot API server before launching the bot locally.
|
||||
*/
|
||||
logOut() {
|
||||
return this.callApi('logOut', {});
|
||||
}
|
||||
/**
|
||||
* Close the bot instance before moving it from one local server to another.
|
||||
*/
|
||||
close() {
|
||||
return this.callApi('close', {});
|
||||
}
|
||||
}
|
||||
exports.Telegram = Telegram;
|
||||
exports.default = Telegram;
|
38
node_modules/telegraf/lib/util.js
generated
vendored
Normal file
38
node_modules/telegraf/lib/util.js
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deprecate = exports.fmtCaption = exports.env = void 0;
|
||||
exports.env = process.env;
|
||||
function fmtCaption(extra) {
|
||||
const caption = extra === null || extra === void 0 ? void 0 : extra.caption;
|
||||
if (!caption || typeof caption === 'string')
|
||||
return extra;
|
||||
const { text, entities } = caption;
|
||||
return {
|
||||
...extra,
|
||||
caption: text,
|
||||
...(entities && {
|
||||
caption_entities: entities,
|
||||
parse_mode: undefined,
|
||||
}),
|
||||
};
|
||||
}
|
||||
exports.fmtCaption = fmtCaption;
|
||||
function deprecate(method, ignorable, use, see) {
|
||||
// don't use deprecate() yet
|
||||
// wait for a couple minor releases of telegraf so the news reaches more people
|
||||
return;
|
||||
const ignorer = `IGNORE_DEPRECATED_${ignorable}`;
|
||||
if (exports.env[ignorer])
|
||||
return;
|
||||
const stack = { stack: '' };
|
||||
Error.captureStackTrace(stack);
|
||||
const line = (stack.stack.split('\n')[3] || '').trim();
|
||||
const useOther = use ? `; use ${use} instead` : '';
|
||||
const pad = ' '.repeat('[WARN]'.length);
|
||||
console.warn(`[WARN] ${method} is deprecated${useOther}`);
|
||||
if (line)
|
||||
console.warn(pad, line);
|
||||
if (see)
|
||||
console.warn(pad, `SEE ${see}`);
|
||||
}
|
||||
exports.deprecate = deprecate;
|
Loading…
Add table
Add a link
Reference in a new issue