initial commit
This commit is contained in:
54
node_modules/grammy/out/convenience/constants.d.ts
generated
vendored
Normal file
54
node_modules/grammy/out/convenience/constants.d.ts
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Contains lists of constants which are useful when working with the Bot API.
|
||||
*/
|
||||
export declare const API_CONSTANTS: Readonly<{
|
||||
/**
|
||||
* List of all available update types. Useful if you want to receive all
|
||||
* updates from the Bot API, rather than just those that are delivered by
|
||||
* default.
|
||||
*
|
||||
* The main use case for this is when you want to receive `chat_member`
|
||||
* updates, as they need to be enabled first. Use it like so:
|
||||
*
|
||||
* ```ts
|
||||
* // Built-in polling:
|
||||
* bot.start({ allowed_updates: ALL_UPDATE_TYPES });
|
||||
* // grammY runner:
|
||||
* run(bot, { runner: { fetch: { allowed_updates: ALL_UPDATE_TYPES } } });
|
||||
* // Webhooks:
|
||||
* await bot.api.setWebhook(url, { allowed_updates: ALL_UPDATE_TYPES });
|
||||
* ```
|
||||
*/
|
||||
readonly ALL_UPDATE_TYPES: readonly ["message", "edited_message", "channel_post", "edited_channel_post", "inline_query", "chosen_inline_result", "callback_query", "shipping_query", "pre_checkout_query", "poll", "poll_answer", "my_chat_member", "chat_join_request", "chat_member"];
|
||||
/**
|
||||
* An object containing all available chat permissions. Useful if you want
|
||||
* to lift restrictions from a user, as this action requires you to pass
|
||||
* `true` for all permissions. Use it like so:
|
||||
*
|
||||
* ```ts
|
||||
* // On `Bot`:
|
||||
* await bot.api.restrictChatMember(chat_id, user_id, ALL_CHAT_PERMISSIONS);
|
||||
* // On `Api`:
|
||||
* await ctx.api.restrictChatMember(chat_id, user_id, ALL_CHAT_PERMISSIONS);
|
||||
* // On `Context`:
|
||||
* await ctx.restrictChatMember(user_id, ALL_CHAT_PERMISSIONS);
|
||||
* await ctx.restrictAuthor(ALL_CHAT_PERMISSIONS);
|
||||
* ```
|
||||
*/
|
||||
readonly ALL_CHAT_PERMISSIONS: {
|
||||
readonly can_send_messages: true;
|
||||
readonly can_send_audios: true;
|
||||
readonly can_send_documents: true;
|
||||
readonly can_send_photos: true;
|
||||
readonly can_send_videos: true;
|
||||
readonly can_send_video_notes: true;
|
||||
readonly can_send_voice_notes: true;
|
||||
readonly can_send_polls: true;
|
||||
readonly can_send_other_messages: true;
|
||||
readonly can_add_web_page_previews: true;
|
||||
readonly can_change_info: true;
|
||||
readonly can_invite_users: true;
|
||||
readonly can_pin_messages: true;
|
||||
readonly can_manage_topics: true;
|
||||
};
|
||||
}>;
|
60
node_modules/grammy/out/convenience/constants.js
generated
vendored
Normal file
60
node_modules/grammy/out/convenience/constants.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.API_CONSTANTS = void 0;
|
||||
const bot_js_1 = require("../bot.js");
|
||||
const ALL_UPDATE_TYPES = [...bot_js_1.DEFAULT_UPDATE_TYPES, "chat_member"];
|
||||
const ALL_CHAT_PERMISSIONS = {
|
||||
can_send_messages: true,
|
||||
can_send_audios: true,
|
||||
can_send_documents: true,
|
||||
can_send_photos: true,
|
||||
can_send_videos: true,
|
||||
can_send_video_notes: true,
|
||||
can_send_voice_notes: true,
|
||||
can_send_polls: true,
|
||||
can_send_other_messages: true,
|
||||
can_add_web_page_previews: true,
|
||||
can_change_info: true,
|
||||
can_invite_users: true,
|
||||
can_pin_messages: true,
|
||||
can_manage_topics: true,
|
||||
};
|
||||
/**
|
||||
* Contains lists of constants which are useful when working with the Bot API.
|
||||
*/
|
||||
exports.API_CONSTANTS = Object.freeze({
|
||||
/**
|
||||
* List of all available update types. Useful if you want to receive all
|
||||
* updates from the Bot API, rather than just those that are delivered by
|
||||
* default.
|
||||
*
|
||||
* The main use case for this is when you want to receive `chat_member`
|
||||
* updates, as they need to be enabled first. Use it like so:
|
||||
*
|
||||
* ```ts
|
||||
* // Built-in polling:
|
||||
* bot.start({ allowed_updates: ALL_UPDATE_TYPES });
|
||||
* // grammY runner:
|
||||
* run(bot, { runner: { fetch: { allowed_updates: ALL_UPDATE_TYPES } } });
|
||||
* // Webhooks:
|
||||
* await bot.api.setWebhook(url, { allowed_updates: ALL_UPDATE_TYPES });
|
||||
* ```
|
||||
*/
|
||||
ALL_UPDATE_TYPES,
|
||||
/**
|
||||
* An object containing all available chat permissions. Useful if you want
|
||||
* to lift restrictions from a user, as this action requires you to pass
|
||||
* `true` for all permissions. Use it like so:
|
||||
*
|
||||
* ```ts
|
||||
* // On `Bot`:
|
||||
* await bot.api.restrictChatMember(chat_id, user_id, ALL_CHAT_PERMISSIONS);
|
||||
* // On `Api`:
|
||||
* await ctx.api.restrictChatMember(chat_id, user_id, ALL_CHAT_PERMISSIONS);
|
||||
* // On `Context`:
|
||||
* await ctx.restrictChatMember(user_id, ALL_CHAT_PERMISSIONS);
|
||||
* await ctx.restrictAuthor(ALL_CHAT_PERMISSIONS);
|
||||
* ```
|
||||
*/
|
||||
ALL_CHAT_PERMISSIONS,
|
||||
});
|
66
node_modules/grammy/out/convenience/frameworks.d.ts
generated
vendored
Normal file
66
node_modules/grammy/out/convenience/frameworks.d.ts
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { type Update } from "../types.js";
|
||||
/**
|
||||
* HTTP Web frameworks for which grammY provides compatible callback out of the
|
||||
* box.
|
||||
*/
|
||||
export type SupportedFrameworks = keyof typeof adapters;
|
||||
/**
|
||||
* Abstraction over a request-response cycle, providing access to the update, as
|
||||
* well as a mechanism for responding to the request and to end it.
|
||||
*/
|
||||
export interface ReqResHandler {
|
||||
/**
|
||||
* The update object sent from Telegram, usually resolves the request's JSON
|
||||
* body
|
||||
*/
|
||||
update: Promise<Update>;
|
||||
/**
|
||||
* X-Telegram-Bot-Api-Secret-Token header of the request, or undefined if
|
||||
* not present
|
||||
*/
|
||||
header?: string;
|
||||
/**
|
||||
* Ends the request immediately without body, called after every request
|
||||
* unless a webhook reply was performed
|
||||
*/
|
||||
end?: () => void;
|
||||
/**
|
||||
* Sends the specified JSON as a payload in the body, used for webhook
|
||||
* replies
|
||||
*/
|
||||
respond: (json: string) => unknown | Promise<unknown>;
|
||||
/**
|
||||
* Responds that the request is unauthorized due to mismatching
|
||||
* X-Telegram-Bot-Api-Secret-Token headers
|
||||
*/
|
||||
unauthorized: () => unknown | Promise<unknown>;
|
||||
/**
|
||||
* Some frameworks (e.g. Deno's std/http `listenAndServe`) assume that
|
||||
* handler returns something
|
||||
*/
|
||||
handlerReturn?: any;
|
||||
}
|
||||
/**
|
||||
* Middleware for a web framework. Creates a request-response handler for a
|
||||
* request. The handler will be used to integrate with the compatible framework.
|
||||
*/
|
||||
export type FrameworkAdapter = (...args: any[]) => ReqResHandler;
|
||||
export declare const adapters: {
|
||||
express: FrameworkAdapter;
|
||||
koa: FrameworkAdapter;
|
||||
fastify: FrameworkAdapter;
|
||||
serveHttp: FrameworkAdapter;
|
||||
"std/http": FrameworkAdapter;
|
||||
oak: FrameworkAdapter;
|
||||
http: FrameworkAdapter;
|
||||
https: FrameworkAdapter;
|
||||
"aws-lambda": FrameworkAdapter;
|
||||
"aws-lambda-async": FrameworkAdapter;
|
||||
azure: FrameworkAdapter;
|
||||
"next-js": FrameworkAdapter;
|
||||
sveltekit: FrameworkAdapter;
|
||||
cloudflare: FrameworkAdapter;
|
||||
"cloudflare-mod": FrameworkAdapter;
|
||||
hono: FrameworkAdapter;
|
||||
worktop: FrameworkAdapter;
|
||||
};
|
288
node_modules/grammy/out/convenience/frameworks.js
generated
vendored
Normal file
288
node_modules/grammy/out/convenience/frameworks.js
generated
vendored
Normal file
@@ -0,0 +1,288 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.adapters = void 0;
|
||||
const SECRET_HEADER = "X-Telegram-Bot-Api-Secret-Token";
|
||||
const SECRET_HEADER_LOWERCASE = SECRET_HEADER.toLowerCase();
|
||||
const WRONG_TOKEN_ERROR = "secret token is wrong";
|
||||
const ok = () => new Response(null, { status: 200 });
|
||||
const okJson = (json) => new Response(json, {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
const unauthorized = () => new Response('"unauthorized"', {
|
||||
status: 401,
|
||||
statusText: WRONG_TOKEN_ERROR,
|
||||
});
|
||||
/** express web framework */
|
||||
const express = (req, res) => ({
|
||||
update: Promise.resolve(req.body),
|
||||
header: req.header(SECRET_HEADER),
|
||||
end: () => res.end(),
|
||||
respond: (json) => {
|
||||
res.set("Content-Type", "application/json");
|
||||
res.send(json);
|
||||
},
|
||||
unauthorized: () => {
|
||||
res.status(401).send(WRONG_TOKEN_ERROR);
|
||||
},
|
||||
});
|
||||
/** koa web framework */
|
||||
const koa = (ctx) => ({
|
||||
update: Promise.resolve(ctx.request.body),
|
||||
header: ctx.get(SECRET_HEADER),
|
||||
end: () => {
|
||||
ctx.body = "";
|
||||
},
|
||||
respond: (json) => {
|
||||
ctx.set("Content-Type", "application/json");
|
||||
ctx.response.body = json;
|
||||
},
|
||||
unauthorized: () => {
|
||||
ctx.status = 401;
|
||||
},
|
||||
});
|
||||
/** fastify web framework */
|
||||
const fastify = (req, reply) => ({
|
||||
update: Promise.resolve(req.body),
|
||||
header: req.headers[SECRET_HEADER_LOWERCASE],
|
||||
end: () => reply.status(200).send(),
|
||||
respond: (json) => reply.send(json),
|
||||
unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR),
|
||||
});
|
||||
const serveHttp = (requestEvent) => ({
|
||||
update: requestEvent.request.json(),
|
||||
header: requestEvent.request.headers.get(SECRET_HEADER) || undefined,
|
||||
end: () => requestEvent.respondWith(ok()),
|
||||
respond: (json) => requestEvent.respondWith(okJson(json)),
|
||||
unauthorized: () => requestEvent.respondWith(unauthorized()),
|
||||
});
|
||||
/** std/http web server */
|
||||
const stdHttp = (req) => {
|
||||
let resolveResponse;
|
||||
return {
|
||||
update: req.json(),
|
||||
header: req.headers.get(SECRET_HEADER) || undefined,
|
||||
end: () => {
|
||||
if (resolveResponse)
|
||||
resolveResponse(ok());
|
||||
},
|
||||
respond: (json) => {
|
||||
if (resolveResponse)
|
||||
resolveResponse(okJson(json));
|
||||
},
|
||||
unauthorized: () => {
|
||||
if (resolveResponse)
|
||||
resolveResponse(unauthorized());
|
||||
},
|
||||
handlerReturn: new Promise((resolve) => {
|
||||
resolveResponse = resolve;
|
||||
}),
|
||||
};
|
||||
};
|
||||
/** oak web framework */
|
||||
const oak = (ctx) => ({
|
||||
update: ctx.request.body({ type: "json" }).value,
|
||||
header: ctx.request.headers.get(SECRET_HEADER) || undefined,
|
||||
end: () => {
|
||||
ctx.response.status = 200;
|
||||
},
|
||||
respond: (json) => {
|
||||
ctx.response.type = "json";
|
||||
ctx.response.body = json;
|
||||
},
|
||||
unauthorized: () => {
|
||||
ctx.response.status = 401;
|
||||
},
|
||||
});
|
||||
/** Node.js native 'http' and 'https' modules */
|
||||
const http = (req, res) => {
|
||||
const secretHeaderFromRequest = req.headers[SECRET_HEADER_LOWERCASE];
|
||||
return {
|
||||
update: new Promise((resolve, reject) => {
|
||||
const chunks = [];
|
||||
req.on("data", (chunk) => chunks.push(chunk))
|
||||
.once("end", () => {
|
||||
// @ts-ignore `Buffer` is Node-only
|
||||
const raw = Buffer.concat(chunks).toString("utf-8");
|
||||
resolve(JSON.parse(raw));
|
||||
})
|
||||
.once("error", reject);
|
||||
}),
|
||||
header: Array.isArray(secretHeaderFromRequest)
|
||||
? secretHeaderFromRequest[0]
|
||||
: secretHeaderFromRequest,
|
||||
end: () => res.end(),
|
||||
respond: (json) => res
|
||||
.writeHead(200, { "Content-Type": "application/json" })
|
||||
.end(json),
|
||||
unauthorized: () => res.writeHead(401).end(WRONG_TOKEN_ERROR),
|
||||
};
|
||||
};
|
||||
/** AWS lambda serverless functions */
|
||||
const awsLambda = (event, _context, callback) => ({
|
||||
update: JSON.parse(event.body),
|
||||
header: event.headers[SECRET_HEADER],
|
||||
end: () => callback(null, { statusCode: 200 }),
|
||||
respond: (json) => callback(null, {
|
||||
statusCode: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: json,
|
||||
}),
|
||||
unauthorized: () => callback(null, { statusCode: 401 }),
|
||||
});
|
||||
/** AWS lambda async/await serverless functions */
|
||||
const awsLambdaAsync = (event, _context) => {
|
||||
let resolveResponse;
|
||||
return {
|
||||
update: JSON.parse(event.body),
|
||||
header: event.headers[SECRET_HEADER],
|
||||
end: () => resolveResponse({ statusCode: 200 }),
|
||||
respond: (json) => resolveResponse({
|
||||
statusCode: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: json,
|
||||
}),
|
||||
unauthorized: () => resolveResponse({ statusCode: 401 }),
|
||||
handlerReturn: new Promise((resolve) => {
|
||||
resolveResponse = resolve;
|
||||
}),
|
||||
};
|
||||
};
|
||||
/** Azure Functions */
|
||||
const azure = (context, req) => ({
|
||||
update: Promise.resolve(req.body),
|
||||
header: context.res.headers[SECRET_HEADER],
|
||||
end: () => (context.res = {
|
||||
status: 200,
|
||||
body: "",
|
||||
}),
|
||||
respond: (json) => {
|
||||
context.res.set("Content-Type", "application/json");
|
||||
context.res.send(json);
|
||||
},
|
||||
unauthorized: () => {
|
||||
context.res.send(401, WRONG_TOKEN_ERROR);
|
||||
},
|
||||
});
|
||||
/** Next.js Serverless Functions */
|
||||
const nextJs = (req, res) => ({
|
||||
update: Promise.resolve(req.body),
|
||||
header: req.headers[SECRET_HEADER_LOWERCASE],
|
||||
end: () => res.end(),
|
||||
respond: (json) => res.status(200).json(json),
|
||||
unauthorized: () => res.status(401).send(WRONG_TOKEN_ERROR),
|
||||
});
|
||||
/** Sveltekit Serverless Functions */
|
||||
const sveltekit = ({ request }) => {
|
||||
let resolveResponse;
|
||||
return {
|
||||
update: Promise.resolve(request.json()),
|
||||
header: request.headers.get(SECRET_HEADER) || undefined,
|
||||
end: () => {
|
||||
if (resolveResponse)
|
||||
resolveResponse(ok());
|
||||
},
|
||||
respond: (json) => {
|
||||
if (resolveResponse)
|
||||
resolveResponse(okJson(json));
|
||||
},
|
||||
unauthorized: () => {
|
||||
if (resolveResponse)
|
||||
resolveResponse(unauthorized());
|
||||
},
|
||||
handlerReturn: new Promise((resolve) => {
|
||||
resolveResponse = resolve;
|
||||
}),
|
||||
};
|
||||
};
|
||||
/** Native CloudFlare workers (service worker) */
|
||||
const cloudflare = (event) => {
|
||||
let resolveResponse;
|
||||
event.respondWith(new Promise((resolve) => {
|
||||
resolveResponse = resolve;
|
||||
}));
|
||||
return {
|
||||
update: event.request.json(),
|
||||
header: event.request.headers.get(SECRET_HEADER) || undefined,
|
||||
end: () => {
|
||||
resolveResponse(ok());
|
||||
},
|
||||
respond: (json) => {
|
||||
resolveResponse(okJson(json));
|
||||
},
|
||||
unauthorized: () => {
|
||||
resolveResponse(unauthorized());
|
||||
},
|
||||
};
|
||||
};
|
||||
/** Native CloudFlare workers (module worker) */
|
||||
const cloudflareModule = (request) => {
|
||||
let resolveResponse;
|
||||
return {
|
||||
update: request.json(),
|
||||
header: request.headers.get(SECRET_HEADER) || undefined,
|
||||
end: () => {
|
||||
resolveResponse(ok());
|
||||
},
|
||||
respond: (json) => {
|
||||
resolveResponse(okJson(json));
|
||||
},
|
||||
unauthorized: () => {
|
||||
resolveResponse(unauthorized());
|
||||
},
|
||||
handlerReturn: new Promise((resolve) => {
|
||||
resolveResponse = resolve;
|
||||
}),
|
||||
};
|
||||
};
|
||||
/** hono web framework */
|
||||
const hono = (ctx) => {
|
||||
let resolveResponse;
|
||||
return {
|
||||
update: ctx.req.json(),
|
||||
header: ctx.req.headers.get(SECRET_HEADER) || undefined,
|
||||
end: () => {
|
||||
resolveResponse(ctx.body());
|
||||
},
|
||||
respond: (json) => {
|
||||
ctx.header('Content-Type", "application/json');
|
||||
resolveResponse(ctx.body(json));
|
||||
},
|
||||
unauthorized: () => {
|
||||
ctx.status(401);
|
||||
ctx.statusText(WRONG_TOKEN_ERROR);
|
||||
resolveResponse(ctx.body());
|
||||
},
|
||||
handlerReturn: new Promise((resolve) => {
|
||||
resolveResponse = resolve;
|
||||
}),
|
||||
};
|
||||
};
|
||||
/** worktop CloudFlare workers framework */
|
||||
const worktop = (req, res) => ({
|
||||
update: Promise.resolve(req.body.json()),
|
||||
header: req.headers.get(SECRET_HEADER),
|
||||
end: () => res.end(),
|
||||
respond: (json) => res.send(200, json),
|
||||
unauthorized: () => res.send(401, WRONG_TOKEN_ERROR),
|
||||
});
|
||||
// Please open a PR if you want to add another adapter
|
||||
exports.adapters = {
|
||||
express,
|
||||
koa,
|
||||
fastify,
|
||||
serveHttp,
|
||||
"std/http": stdHttp,
|
||||
oak,
|
||||
http,
|
||||
https: http,
|
||||
"aws-lambda": awsLambda,
|
||||
"aws-lambda-async": awsLambdaAsync,
|
||||
azure,
|
||||
"next-js": nextJs,
|
||||
sveltekit,
|
||||
cloudflare,
|
||||
"cloudflare-mod": cloudflareModule,
|
||||
hono,
|
||||
worktop,
|
||||
};
|
401
node_modules/grammy/out/convenience/inline_query.d.ts
generated
vendored
Normal file
401
node_modules/grammy/out/convenience/inline_query.d.ts
generated
vendored
Normal file
@@ -0,0 +1,401 @@
|
||||
import { type InlineQueryResultArticle, type InlineQueryResultAudio, type InlineQueryResultCachedAudio, type InlineQueryResultCachedDocument, type InlineQueryResultCachedGif, type InlineQueryResultCachedMpeg4Gif, type InlineQueryResultCachedPhoto, type InlineQueryResultCachedSticker, type InlineQueryResultCachedVideo, type InlineQueryResultCachedVoice, type InlineQueryResultContact, type InlineQueryResultDocument, type InlineQueryResultGame, type InlineQueryResultGif, type InlineQueryResultLocation, type InlineQueryResultMpeg4Gif, type InlineQueryResultPhoto, type InlineQueryResultVenue, type InlineQueryResultVideo, type InlineQueryResultVoice, type InputContactMessageContent, type InputInvoiceMessageContent, type InputLocationMessageContent, type InputTextMessageContent, type InputVenueMessageContent, type LabeledPrice } from "../types.js";
|
||||
type InlineQueryResultOptions<T, K extends keyof T> = Omit<T, "type" | "id" | "input_message_content" | K>;
|
||||
type OptionalKeys<T> = {
|
||||
[K in keyof T]-?: undefined extends T[K] ? K : never;
|
||||
};
|
||||
type OptionalFields<T> = Pick<T, OptionalKeys<T>[keyof T]>;
|
||||
/**
|
||||
* Holds a number of helper methods for building `InlineQueryResult*` objects.
|
||||
*
|
||||
* For example, letting the user pick one out of three photos can be done like
|
||||
* this.
|
||||
*
|
||||
* ```ts
|
||||
* const results = [
|
||||
* InlineQueryResultBuilder.photo('id0', 'https://grammy.dev/images/Y.png'),
|
||||
* InlineQueryResultBuilder.photo('id1', 'https://grammy.dev/images/Y.png'),
|
||||
* InlineQueryResultBuilder.photo('id2', 'https://grammy.dev/images/Y.png'),
|
||||
* ];
|
||||
* await ctx.answerInlineQuery(results)
|
||||
* ```
|
||||
*
|
||||
* If you want the message content to be different from the content in the
|
||||
* inline query result, you can perform another method call on the resulting
|
||||
* objects.
|
||||
*
|
||||
* ```ts
|
||||
* const results = [
|
||||
* InlineQueryResultBuilder.photo("id0", "https://grammy.dev/images/Y.png")
|
||||
* .text("Picked photo 0!"),
|
||||
* InlineQueryResultBuilder.photo("id1", "https://grammy.dev/images/Y.png")
|
||||
* .text("Picked photo 1!"),
|
||||
* InlineQueryResultBuilder.photo("id2", "https://grammy.dev/images/Y.png")
|
||||
* .text("Picked photo 2!"),
|
||||
* ];
|
||||
* await ctx.answerInlineQuery(results)
|
||||
* ```
|
||||
*
|
||||
* Be sure to check the
|
||||
* [documentation](https://core.telegram.org/bots/api#inline-mode) on inline
|
||||
* mode.
|
||||
*/
|
||||
export declare const InlineQueryResultBuilder: {
|
||||
/**
|
||||
* Builds an InlineQueryResultArticle object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultarticle. Requires you
|
||||
* to specify the actual message content by calling another function on the
|
||||
* object returned from this method.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param title Title of the result
|
||||
* @param options Remaining options
|
||||
*/
|
||||
article(id: string, title: string, options?: InlineQueryResultOptions<InlineQueryResultArticle, "title">): {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultArticle;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultArticle;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultArticle;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultArticle;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultArticle;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultAudio object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultaudio.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title
|
||||
* @param audio_url A valid URL for the audio file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
audio(id: string, title: string, audio_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultAudio, "title" | "audio_url">): InlineQueryResultAudio & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultAudio;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultAudio;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultAudio;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultAudio;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultAudio;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedAudio object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedaudio.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param audio_file_id A valid file identifier for the audio file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
audioCached(id: string, audio_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedAudio, "audio_file_id">): InlineQueryResultCachedAudio & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedAudio;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedAudio;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedAudio;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedAudio;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedAudio;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultContact object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcontact.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param phone_number Contact's phone number
|
||||
* @param first_name Contact's first name
|
||||
* @param options Remaining options
|
||||
*/
|
||||
contact(id: string, phone_number: string, first_name: string, options?: InlineQueryResultOptions<InlineQueryResultContact, "phone_number" | "first_name">): InlineQueryResultContact & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultContact;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultContact;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultContact;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultContact;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultContact;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultDocument object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultdocument with
|
||||
* mime_type set to "application/pdf".
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param document_url A valid URL for the file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
documentPdf(id: string, title: string, document_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultDocument, "mime_type" | "title" | "document_url">): InlineQueryResultDocument & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultDocument;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultDocument;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultDocument;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultDocument;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultDocument;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultDocument object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultdocument with
|
||||
* mime_type set to "application/zip".
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param document_url A valid URL for the file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
documentZip(id: string, title: string, document_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultDocument, "mime_type" | "title" | "document_url">): InlineQueryResultDocument & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultDocument;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultDocument;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultDocument;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultDocument;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultDocument;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedDocument object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcacheddocument.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param document_file_id A valid file identifier for the file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
documentCached(id: string, title: string, document_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedDocument, "title" | "document_file_id">): InlineQueryResultCachedDocument & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedDocument;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedDocument;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedDocument;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedDocument;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedDocument;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultGame object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultgame.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param game_short_name Short name of the game
|
||||
* @param options Remaining options
|
||||
*/
|
||||
game(id: string, game_short_name: string, options?: InlineQueryResultOptions<InlineQueryResultGame, "game_short_name">): {
|
||||
reply_markup?: import("@grammyjs/types/markup.js").InlineKeyboardMarkup | undefined;
|
||||
type: string;
|
||||
id: string;
|
||||
game_short_name: string;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultGif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultgif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param gif_url A valid URL for the GIF file. File size must not exceed 1MB
|
||||
* @param thumbnail_url URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
|
||||
* @param options Remaining options
|
||||
*/
|
||||
gif(id: string, gif_url: string | URL, thumbnail_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultGif, "gif_url" | "thumbnail_url">): InlineQueryResultGif & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultGif;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultGif;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultGif;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultGif;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultGif;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedGif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedgif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param gif_file_id A valid file identifier for the GIF file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
gifCached(id: string, gif_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedGif, "gif_file_id">): InlineQueryResultCachedGif & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedGif;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedGif;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedGif;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedGif;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedGif;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultLocation object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultlocation.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param title Location title
|
||||
* @param latitude Location latitude in degrees
|
||||
* @param longitude Location longitude in degrees
|
||||
* @param options Remaining options
|
||||
*/
|
||||
location(id: string, title: string, latitude: number, longitude: number, options?: InlineQueryResultOptions<InlineQueryResultLocation, "title" | "latitude" | "longitude">): InlineQueryResultLocation & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultLocation;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultLocation;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultLocation;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultLocation;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultLocation;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultMpeg4Gif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param mpeg4_url A valid URL for the MPEG4 file. File size must not exceed 1MB
|
||||
* @param thumbnail_url URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
|
||||
* @param options Remaining options
|
||||
*/
|
||||
mpeg4gif(id: string, mpeg4_url: string | URL, thumbnail_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultMpeg4Gif, "mpeg4_url" | "thumbnail_url">): InlineQueryResultMpeg4Gif & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultMpeg4Gif;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultMpeg4Gif;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultMpeg4Gif;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultMpeg4Gif;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultMpeg4Gif;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedMpeg4Gif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param mpeg4_file_id A valid file identifier for the MPEG4 file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
mpeg4gifCached(id: string, mpeg4_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedMpeg4Gif, "mpeg4_file_id">): InlineQueryResultCachedMpeg4Gif & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedMpeg4Gif;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedMpeg4Gif;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedMpeg4Gif;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedMpeg4Gif;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedMpeg4Gif;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultPhoto object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultphoto with the
|
||||
* thumbnail defaulting to the photo itself.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param photo_url A valid URL of the photo. Photo must be in JPEG format. Photo size must not exceed 5MB
|
||||
* @param options Remaining options
|
||||
*/
|
||||
photo(id: string, photo_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultPhoto, "photo_url">): InlineQueryResultPhoto & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultPhoto;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultPhoto;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultPhoto;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultPhoto;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultPhoto;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedPhoto object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedphoto.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param photo_file_id A valid file identifier of the photo
|
||||
* @param options Remaining options
|
||||
*/
|
||||
photoCached(id: string, photo_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedPhoto, "photo_file_id">): InlineQueryResultCachedPhoto & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedPhoto;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedPhoto;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedPhoto;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedPhoto;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedPhoto;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedSticker object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedsticker.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param sticker_file_id A valid file identifier of the sticker
|
||||
* @param options Remaining options
|
||||
*/
|
||||
stickerCached(id: string, sticker_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedSticker, "sticker_file_id">): InlineQueryResultCachedSticker & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedSticker;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedSticker;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedSticker;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedSticker;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedSticker;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultVenue object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvenue.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param title Title of the venue
|
||||
* @param latitude Latitude of the venue location in degrees
|
||||
* @param longitude Longitude of the venue location in degrees
|
||||
* @param address Address of the venue
|
||||
* @param options Remaining options
|
||||
*/
|
||||
venue(id: string, title: string, latitude: number, longitude: number, address: string, options?: InlineQueryResultOptions<InlineQueryResultVenue, "title" | "latitude" | "longitude" | "address">): InlineQueryResultVenue & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultVenue;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultVenue;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultVenue;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultVenue;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultVenue;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultVideo object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvideo with mime_type
|
||||
* set to "text/html". This will send an embedded video player. Requires you
|
||||
* to specify the actual message content by calling another function on the
|
||||
* object returned from this method.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param video_url A valid URL for the embedded video player
|
||||
* @param thumbnail_url URL of the thumbnail (JPEG only) for the video
|
||||
* @param options Remaining options
|
||||
*/
|
||||
videoHtml(id: string, title: string, video_url: string | URL, thumbnail_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultVideo, "mime_type" | "title" | "video_url" | "thumbnail_url">): {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultVideo;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultVideo;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultVideo;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultVideo;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultVideo;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultVideo object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvideo with mime_type
|
||||
* set to "video/mp4".
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param video_url A valid URL for the video file
|
||||
* @param thumbnail_url URL of the thumbnail (JPEG only) for the video
|
||||
* @param options Remaining options
|
||||
*/
|
||||
videoMp4(id: string, title: string, video_url: string | URL, thumbnail_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultVideo, "mime_type" | "title" | "video_url" | "thumbnail_url">): InlineQueryResultVideo & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultVideo;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultVideo;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultVideo;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultVideo;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultVideo;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedVideo object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedvideo.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param video_file_id A valid file identifier for the video file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
videoCached(id: string, title: string, video_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedVideo, "title" | "video_file_id">): InlineQueryResultCachedVideo & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedVideo;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedVideo;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedVideo;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedVideo;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedVideo;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultVoice object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvoice.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Voice message title
|
||||
* @param voice_url A valid URL for the voice recording
|
||||
* @param options Remaining options
|
||||
*/
|
||||
voice(id: string, title: string, voice_url: string | URL, options?: InlineQueryResultOptions<InlineQueryResultVoice, "title" | "voice_url">): InlineQueryResultVoice & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultVoice;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultVoice;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultVoice;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultVoice;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultVoice;
|
||||
};
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedVoice object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedvoice.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Voice message title
|
||||
* @param voice_file_id A valid file identifier for the voice message
|
||||
* @param options Remaining options
|
||||
*/
|
||||
voiceCached(id: string, title: string, voice_file_id: string, options?: InlineQueryResultOptions<InlineQueryResultCachedVoice, "title" | "voice_file_id">): InlineQueryResultCachedVoice & {
|
||||
text(message_text: string, options?: OptionalFields<InputTextMessageContent>): InlineQueryResultCachedVoice;
|
||||
location(latitude: number, longitude: number, options?: OptionalFields<InputLocationMessageContent>): InlineQueryResultCachedVoice;
|
||||
venue(title: string, latitude: number, longitude: number, address: string, options: OptionalFields<InputVenueMessageContent>): InlineQueryResultCachedVoice;
|
||||
contact(first_name: string, phone_number: string, options?: OptionalFields<InputContactMessageContent>): InlineQueryResultCachedVoice;
|
||||
invoice(title: string, description: string, payload: string, provider_token: string, currency: string, prices: LabeledPrice[], options?: OptionalFields<InputInvoiceMessageContent>): InlineQueryResultCachedVoice;
|
||||
};
|
||||
};
|
||||
export {};
|
461
node_modules/grammy/out/convenience/inline_query.js
generated
vendored
Normal file
461
node_modules/grammy/out/convenience/inline_query.js
generated
vendored
Normal file
@@ -0,0 +1,461 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InlineQueryResultBuilder = void 0;
|
||||
function inputMessage(queryTemplate) {
|
||||
return {
|
||||
...queryTemplate,
|
||||
...inputMessageMethods(queryTemplate),
|
||||
};
|
||||
}
|
||||
function inputMessageMethods(queryTemplate) {
|
||||
return {
|
||||
text(message_text, options = {}) {
|
||||
const content = {
|
||||
message_text,
|
||||
...options,
|
||||
};
|
||||
return { ...queryTemplate, input_message_content: content };
|
||||
},
|
||||
location(latitude, longitude, options = {}) {
|
||||
const content = {
|
||||
latitude,
|
||||
longitude,
|
||||
...options,
|
||||
};
|
||||
return { ...queryTemplate, input_message_content: content };
|
||||
},
|
||||
venue(title, latitude, longitude, address, options) {
|
||||
const content = {
|
||||
title,
|
||||
latitude,
|
||||
longitude,
|
||||
address,
|
||||
...options,
|
||||
};
|
||||
return { ...queryTemplate, input_message_content: content };
|
||||
},
|
||||
contact(first_name, phone_number, options = {}) {
|
||||
const content = {
|
||||
first_name,
|
||||
phone_number,
|
||||
...options,
|
||||
};
|
||||
return { ...queryTemplate, input_message_content: content };
|
||||
},
|
||||
invoice(title, description, payload, provider_token, currency, prices, options = {}) {
|
||||
const content = {
|
||||
title,
|
||||
description,
|
||||
payload,
|
||||
provider_token,
|
||||
currency,
|
||||
prices,
|
||||
...options,
|
||||
};
|
||||
return { ...queryTemplate, input_message_content: content };
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Holds a number of helper methods for building `InlineQueryResult*` objects.
|
||||
*
|
||||
* For example, letting the user pick one out of three photos can be done like
|
||||
* this.
|
||||
*
|
||||
* ```ts
|
||||
* const results = [
|
||||
* InlineQueryResultBuilder.photo('id0', 'https://grammy.dev/images/Y.png'),
|
||||
* InlineQueryResultBuilder.photo('id1', 'https://grammy.dev/images/Y.png'),
|
||||
* InlineQueryResultBuilder.photo('id2', 'https://grammy.dev/images/Y.png'),
|
||||
* ];
|
||||
* await ctx.answerInlineQuery(results)
|
||||
* ```
|
||||
*
|
||||
* If you want the message content to be different from the content in the
|
||||
* inline query result, you can perform another method call on the resulting
|
||||
* objects.
|
||||
*
|
||||
* ```ts
|
||||
* const results = [
|
||||
* InlineQueryResultBuilder.photo("id0", "https://grammy.dev/images/Y.png")
|
||||
* .text("Picked photo 0!"),
|
||||
* InlineQueryResultBuilder.photo("id1", "https://grammy.dev/images/Y.png")
|
||||
* .text("Picked photo 1!"),
|
||||
* InlineQueryResultBuilder.photo("id2", "https://grammy.dev/images/Y.png")
|
||||
* .text("Picked photo 2!"),
|
||||
* ];
|
||||
* await ctx.answerInlineQuery(results)
|
||||
* ```
|
||||
*
|
||||
* Be sure to check the
|
||||
* [documentation](https://core.telegram.org/bots/api#inline-mode) on inline
|
||||
* mode.
|
||||
*/
|
||||
exports.InlineQueryResultBuilder = {
|
||||
/**
|
||||
* Builds an InlineQueryResultArticle object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultarticle. Requires you
|
||||
* to specify the actual message content by calling another function on the
|
||||
* object returned from this method.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param title Title of the result
|
||||
* @param options Remaining options
|
||||
*/
|
||||
article(id, title, options = {}) {
|
||||
return inputMessageMethods({ type: "article", id, title, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultAudio object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultaudio.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title
|
||||
* @param audio_url A valid URL for the audio file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
audio(id, title, audio_url, options = {}) {
|
||||
return inputMessage({
|
||||
type: "audio",
|
||||
id,
|
||||
title,
|
||||
audio_url: typeof audio_url === "string"
|
||||
? audio_url
|
||||
: audio_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedAudio object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedaudio.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param audio_file_id A valid file identifier for the audio file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
audioCached(id, audio_file_id, options = {}) {
|
||||
return inputMessage({ type: "audio", id, audio_file_id, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultContact object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcontact.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param phone_number Contact's phone number
|
||||
* @param first_name Contact's first name
|
||||
* @param options Remaining options
|
||||
*/
|
||||
contact(id, phone_number, first_name, options = {}) {
|
||||
return inputMessage({ type: "contact", id, phone_number, first_name, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultDocument object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultdocument with
|
||||
* mime_type set to "application/pdf".
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param document_url A valid URL for the file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
documentPdf(id, title, document_url, options = {}) {
|
||||
return inputMessage({
|
||||
type: "document",
|
||||
mime_type: "application/pdf",
|
||||
id,
|
||||
title,
|
||||
document_url: typeof document_url === "string"
|
||||
? document_url
|
||||
: document_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultDocument object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultdocument with
|
||||
* mime_type set to "application/zip".
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param document_url A valid URL for the file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
documentZip(id, title, document_url, options = {}) {
|
||||
return inputMessage({
|
||||
type: "document",
|
||||
mime_type: "application/zip",
|
||||
id,
|
||||
title,
|
||||
document_url: typeof document_url === "string"
|
||||
? document_url
|
||||
: document_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedDocument object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcacheddocument.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param document_file_id A valid file identifier for the file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
documentCached(id, title, document_file_id, options = {}) {
|
||||
return inputMessage({ type: "document", id, title, document_file_id, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultGame object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultgame.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param game_short_name Short name of the game
|
||||
* @param options Remaining options
|
||||
*/
|
||||
game(id, game_short_name, options = {}) {
|
||||
return { type: "game", id, game_short_name, ...options };
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultGif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultgif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param gif_url A valid URL for the GIF file. File size must not exceed 1MB
|
||||
* @param thumbnail_url URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
|
||||
* @param options Remaining options
|
||||
*/
|
||||
gif(id, gif_url, thumbnail_url, options = {}) {
|
||||
return inputMessage({
|
||||
type: "gif",
|
||||
id,
|
||||
gif_url: typeof gif_url === "string" ? gif_url : gif_url.href,
|
||||
thumbnail_url: typeof thumbnail_url === "string"
|
||||
? thumbnail_url
|
||||
: thumbnail_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedGif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedgif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param gif_file_id A valid file identifier for the GIF file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
gifCached(id, gif_file_id, options = {}) {
|
||||
return inputMessage({ type: "gif", id, gif_file_id, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultLocation object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultlocation.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param title Location title
|
||||
* @param latitude Location latitude in degrees
|
||||
* @param longitude Location longitude in degrees
|
||||
* @param options Remaining options
|
||||
*/
|
||||
location(id, title, latitude, longitude, options = {}) {
|
||||
return inputMessage({ type: "location", id, title, latitude, longitude, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultMpeg4Gif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param mpeg4_url A valid URL for the MPEG4 file. File size must not exceed 1MB
|
||||
* @param thumbnail_url URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result
|
||||
* @param options Remaining options
|
||||
*/
|
||||
mpeg4gif(id, mpeg4_url, thumbnail_url, options = {}) {
|
||||
return inputMessage({
|
||||
type: "mpeg4_gif",
|
||||
id,
|
||||
mpeg4_url: typeof mpeg4_url === "string"
|
||||
? mpeg4_url
|
||||
: mpeg4_url.href,
|
||||
thumbnail_url: typeof thumbnail_url === "string"
|
||||
? thumbnail_url
|
||||
: thumbnail_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedMpeg4Gif object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param mpeg4_file_id A valid file identifier for the MPEG4 file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
mpeg4gifCached(id, mpeg4_file_id, options = {}) {
|
||||
return inputMessage({ type: "mpeg4_gif", id, mpeg4_file_id, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultPhoto object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultphoto with the
|
||||
* thumbnail defaulting to the photo itself.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param photo_url A valid URL of the photo. Photo must be in JPEG format. Photo size must not exceed 5MB
|
||||
* @param options Remaining options
|
||||
*/
|
||||
photo(id, photo_url, options = {
|
||||
thumbnail_url: typeof photo_url === "string"
|
||||
? photo_url
|
||||
: photo_url.href,
|
||||
}) {
|
||||
return inputMessage({
|
||||
type: "photo",
|
||||
id,
|
||||
photo_url: typeof photo_url === "string"
|
||||
? photo_url
|
||||
: photo_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedPhoto object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedphoto.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param photo_file_id A valid file identifier of the photo
|
||||
* @param options Remaining options
|
||||
*/
|
||||
photoCached(id, photo_file_id, options = {}) {
|
||||
return inputMessage({ type: "photo", id, photo_file_id, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedSticker object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedsticker.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param sticker_file_id A valid file identifier of the sticker
|
||||
* @param options Remaining options
|
||||
*/
|
||||
stickerCached(id, sticker_file_id, options = {}) {
|
||||
return inputMessage({ type: "sticker", id, sticker_file_id, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultVenue object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvenue.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 Bytes
|
||||
* @param title Title of the venue
|
||||
* @param latitude Latitude of the venue location in degrees
|
||||
* @param longitude Longitude of the venue location in degrees
|
||||
* @param address Address of the venue
|
||||
* @param options Remaining options
|
||||
*/
|
||||
venue(id, title, latitude, longitude, address, options = {}) {
|
||||
return inputMessage({
|
||||
type: "venue",
|
||||
id,
|
||||
title,
|
||||
latitude,
|
||||
longitude,
|
||||
address,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultVideo object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvideo with mime_type
|
||||
* set to "text/html". This will send an embedded video player. Requires you
|
||||
* to specify the actual message content by calling another function on the
|
||||
* object returned from this method.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param video_url A valid URL for the embedded video player
|
||||
* @param thumbnail_url URL of the thumbnail (JPEG only) for the video
|
||||
* @param options Remaining options
|
||||
*/
|
||||
videoHtml(id, title, video_url, thumbnail_url, options = {}) {
|
||||
// require input message content by only returning methods
|
||||
return inputMessageMethods({
|
||||
type: "video",
|
||||
mime_type: "text/html",
|
||||
id,
|
||||
title,
|
||||
video_url: typeof video_url === "string"
|
||||
? video_url
|
||||
: video_url.href,
|
||||
thumbnail_url: typeof thumbnail_url === "string"
|
||||
? thumbnail_url
|
||||
: thumbnail_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultVideo object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvideo with mime_type
|
||||
* set to "video/mp4".
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param video_url A valid URL for the video file
|
||||
* @param thumbnail_url URL of the thumbnail (JPEG only) for the video
|
||||
* @param options Remaining options
|
||||
*/
|
||||
videoMp4(id, title, video_url, thumbnail_url, options = {}) {
|
||||
return inputMessage({
|
||||
type: "video",
|
||||
mime_type: "video/mp4",
|
||||
id,
|
||||
title,
|
||||
video_url: typeof video_url === "string"
|
||||
? video_url
|
||||
: video_url.href,
|
||||
thumbnail_url: typeof thumbnail_url === "string"
|
||||
? thumbnail_url
|
||||
: thumbnail_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedVideo object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedvideo.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Title for the result
|
||||
* @param video_file_id A valid file identifier for the video file
|
||||
* @param options Remaining options
|
||||
*/
|
||||
videoCached(id, title, video_file_id, options = {}) {
|
||||
return inputMessage({ type: "video", id, title, video_file_id, ...options });
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultVoice object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultvoice.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Voice message title
|
||||
* @param voice_url A valid URL for the voice recording
|
||||
* @param options Remaining options
|
||||
*/
|
||||
voice(id, title, voice_url, options = {}) {
|
||||
return inputMessage({
|
||||
type: "voice",
|
||||
id,
|
||||
title,
|
||||
voice_url: typeof voice_url === "string"
|
||||
? voice_url
|
||||
: voice_url.href,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Builds an InlineQueryResultCachedVoice object as specified by
|
||||
* https://core.telegram.org/bots/api#inlinequeryresultcachedvoice.
|
||||
*
|
||||
* @param id Unique identifier for this result, 1-64 bytes
|
||||
* @param title Voice message title
|
||||
* @param voice_file_id A valid file identifier for the voice message
|
||||
* @param options Remaining options
|
||||
*/
|
||||
voiceCached(id, title, voice_file_id, options = {}) {
|
||||
return inputMessage({ type: "voice", id, title, voice_file_id, ...options });
|
||||
},
|
||||
};
|
72
node_modules/grammy/out/convenience/input_media.d.ts
generated
vendored
Normal file
72
node_modules/grammy/out/convenience/input_media.d.ts
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
import { type InputFile, type InputMediaAnimation, type InputMediaAudio, type InputMediaDocument, type InputMediaPhoto, type InputMediaVideo } from "../types.js";
|
||||
type InputMediaOptions<T> = Omit<T, "type" | "media">;
|
||||
/**
|
||||
* Holds a number of helper methods for building `InputMedia*` objects. They are
|
||||
* useful when sending media groups and when editing media messages.
|
||||
*
|
||||
* For example, media groups can be sent like this.
|
||||
*
|
||||
* ```ts
|
||||
* const paths = [
|
||||
* '/tmp/pic0.jpg',
|
||||
* '/tmp/pic1.jpg',
|
||||
* '/tmp/pic2.jpg',
|
||||
* ]
|
||||
* const files = paths.map((path) => new InputFile(path))
|
||||
* const media = files.map((file) => InputMediaBuilder.photo(file))
|
||||
* await bot.api.sendMediaGroup(chatId, media)
|
||||
* ```
|
||||
*
|
||||
* Media can be edited like this.
|
||||
*
|
||||
* ```ts
|
||||
* const file = new InputFile('/tmp/pic0.jpg')
|
||||
* const media = InputMediaBuilder.photo(file, {
|
||||
* caption: 'new caption'
|
||||
* })
|
||||
* await bot.api.editMessageMedia(chatId, messageId, media)
|
||||
* ```
|
||||
*/
|
||||
export declare const InputMediaBuilder: {
|
||||
/**
|
||||
* Creates a new `InputMediaPhoto` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediaphoto.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
photo(media: string | InputFile, options?: InputMediaOptions<InputMediaPhoto>): InputMediaPhoto;
|
||||
/**
|
||||
* Creates a new `InputMediaVideo` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediavideo.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
video(media: string | InputFile, options?: InputMediaOptions<InputMediaVideo>): InputMediaVideo;
|
||||
/**
|
||||
* Creates a new `InputMediaAnimation` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediaanimation.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
animation(media: string | InputFile, options?: InputMediaOptions<InputMediaAnimation>): InputMediaAnimation;
|
||||
/**
|
||||
* Creates a new `InputMediaAudio` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediaaudio.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
audio(media: string | InputFile, options?: InputMediaOptions<InputMediaAudio>): InputMediaAudio;
|
||||
/**
|
||||
* Creates a new `InputMediaDocument` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediadocument.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
document(media: string | InputFile, options?: InputMediaOptions<InputMediaDocument>): InputMediaDocument;
|
||||
};
|
||||
export {};
|
82
node_modules/grammy/out/convenience/input_media.js
generated
vendored
Normal file
82
node_modules/grammy/out/convenience/input_media.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InputMediaBuilder = void 0;
|
||||
/**
|
||||
* Holds a number of helper methods for building `InputMedia*` objects. They are
|
||||
* useful when sending media groups and when editing media messages.
|
||||
*
|
||||
* For example, media groups can be sent like this.
|
||||
*
|
||||
* ```ts
|
||||
* const paths = [
|
||||
* '/tmp/pic0.jpg',
|
||||
* '/tmp/pic1.jpg',
|
||||
* '/tmp/pic2.jpg',
|
||||
* ]
|
||||
* const files = paths.map((path) => new InputFile(path))
|
||||
* const media = files.map((file) => InputMediaBuilder.photo(file))
|
||||
* await bot.api.sendMediaGroup(chatId, media)
|
||||
* ```
|
||||
*
|
||||
* Media can be edited like this.
|
||||
*
|
||||
* ```ts
|
||||
* const file = new InputFile('/tmp/pic0.jpg')
|
||||
* const media = InputMediaBuilder.photo(file, {
|
||||
* caption: 'new caption'
|
||||
* })
|
||||
* await bot.api.editMessageMedia(chatId, messageId, media)
|
||||
* ```
|
||||
*/
|
||||
exports.InputMediaBuilder = {
|
||||
/**
|
||||
* Creates a new `InputMediaPhoto` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediaphoto.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
photo(media, options = {}) {
|
||||
return { type: "photo", media, ...options };
|
||||
},
|
||||
/**
|
||||
* Creates a new `InputMediaVideo` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediavideo.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
video(media, options = {}) {
|
||||
return { type: "video", media, ...options };
|
||||
},
|
||||
/**
|
||||
* Creates a new `InputMediaAnimation` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediaanimation.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
animation(media, options = {}) {
|
||||
return { type: "animation", media, ...options };
|
||||
},
|
||||
/**
|
||||
* Creates a new `InputMediaAudio` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediaaudio.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
audio(media, options = {}) {
|
||||
return { type: "audio", media, ...options };
|
||||
},
|
||||
/**
|
||||
* Creates a new `InputMediaDocument` object as specified by
|
||||
* https://core.telegram.org/bots/api#inputmediadocument.
|
||||
*
|
||||
* @param media An `InputFile` instance or a file identifier
|
||||
* @param options Remaining optional options
|
||||
*/
|
||||
document(media, options = {}) {
|
||||
return { type: "document", media, ...options };
|
||||
},
|
||||
};
|
747
node_modules/grammy/out/convenience/keyboard.d.ts
generated
vendored
Normal file
747
node_modules/grammy/out/convenience/keyboard.d.ts
generated
vendored
Normal file
@@ -0,0 +1,747 @@
|
||||
import { type InlineKeyboardButton, type KeyboardButton, type KeyboardButtonPollType, type KeyboardButtonRequestChat, type KeyboardButtonRequestUser, type LoginUrl, type SwitchInlineQueryChosenChat } from "../types.js";
|
||||
type KeyboardButtonSource = string | KeyboardButton;
|
||||
type KeyboardSource = KeyboardButtonSource[][] | Keyboard;
|
||||
/**
|
||||
* Use this class to simplify building a custom keyboard (something like this:
|
||||
* https://core.telegram.org/bots/features#keyboards).
|
||||
*
|
||||
* ```ts
|
||||
* // Build a custom keyboard:
|
||||
* const keyboard = new Keyboard()
|
||||
* .text('A').text('B').row()
|
||||
* .text('C').text('D')
|
||||
*
|
||||
* // Now you can send it like so:
|
||||
* await ctx.reply('Here is your custom keyboard!', {
|
||||
* reply_markup: keyboard
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* If you already have some source data which you would like to turn into a
|
||||
* keyboard button object, you can use the static equivalents which every button
|
||||
* has. You can use them to create a two-dimensional keyboard button array. The
|
||||
* resulting array can be turned into a keyboard instance.
|
||||
*
|
||||
* ```ts
|
||||
* const button = Keyboard.text('push my buttons')
|
||||
* const array = [[button]]
|
||||
* const keyboard = Keyboard.from(array)
|
||||
* ```
|
||||
*
|
||||
* If you want to create text buttons only, you can directly use a
|
||||
* two-dimensional string array and turn it into a keyboard.
|
||||
*
|
||||
* ```ts
|
||||
* const data = [['A', 'B'], ['C', 'D']]
|
||||
* const keyboard = Keyboard.from(data)
|
||||
* ```
|
||||
*
|
||||
* Be sure to check out the
|
||||
* [documentation](https://grammy.dev/plugins/keyboard.html#custom-keyboards) on
|
||||
* custom keyboards in grammY.
|
||||
*/
|
||||
export declare class Keyboard {
|
||||
readonly keyboard: KeyboardButton[][];
|
||||
/**
|
||||
* Requests clients to always show the keyboard when the regular keyboard is
|
||||
* hidden. Defaults to false, in which case the custom keyboard can be
|
||||
* hidden and opened with a keyboard icon.
|
||||
*/
|
||||
is_persistent?: boolean;
|
||||
/**
|
||||
* Show the current keyboard only to those users that are mentioned in the
|
||||
* text of the message object.
|
||||
*/
|
||||
selective?: boolean;
|
||||
/**
|
||||
* Hide the keyboard after a button is pressed.
|
||||
*/
|
||||
one_time_keyboard?: boolean;
|
||||
/**
|
||||
* Resize the current keyboard according to its buttons. Usually, this will
|
||||
* make the keyboard smaller.
|
||||
*/
|
||||
resize_keyboard?: boolean;
|
||||
/**
|
||||
* Placeholder to be shown in the input field when the keyboard is active.
|
||||
*/
|
||||
input_field_placeholder?: string;
|
||||
/**
|
||||
* Initialize a new `Keyboard` with an optional two-dimensional array of
|
||||
* `KeyboardButton` objects. This is the nested array that holds the custom
|
||||
* keyboard. It will be extended every time you call one of the provided
|
||||
* methods.
|
||||
*
|
||||
* @param keyboard An optional initial two-dimensional button array
|
||||
*/
|
||||
constructor(keyboard?: KeyboardButton[][]);
|
||||
/**
|
||||
* Allows you to add your own `KeyboardButton` objects if you already have
|
||||
* them for some reason. You most likely want to call one of the other
|
||||
* methods.
|
||||
*
|
||||
* @param buttons The buttons to add
|
||||
*/
|
||||
add(...buttons: KeyboardButton[]): this;
|
||||
/**
|
||||
* Adds a 'line break'. Call this method to make sure that the next added
|
||||
* buttons will be on a new row.
|
||||
*
|
||||
* You may pass a number of `KeyboardButton` objects if you already have the
|
||||
* instances for some reason. You most likely don't want to pass any
|
||||
* arguments to `row`.
|
||||
*
|
||||
* @param buttons A number of buttons to add to the next row
|
||||
*/
|
||||
row(...buttons: KeyboardButton[]): this;
|
||||
/**
|
||||
* Adds a new text button. This button will simply send the given text as a
|
||||
* text message back to your bot if a user clicks on it.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
text(text: string): this;
|
||||
/**
|
||||
* Creates a new text button. This button will simply send the given text as
|
||||
* a text message back to your bot if a user clicks on it.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static text(text: string): KeyboardButton.CommonButton;
|
||||
/**
|
||||
* Adds a new request user button. When the user presses the button, a list
|
||||
* of suitable users will be opened. Tapping on any user will send their
|
||||
* identifier to the bot in a “user_shared” service message. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
requestUser(text: string, requestId: number, options?: Omit<KeyboardButtonRequestUser, "request_id">): this;
|
||||
/**
|
||||
* Creates a new request user button. When the user presses the button, a
|
||||
* list of suitable users will be opened. Tapping on any user will send
|
||||
* their identifier to the bot in a “user_shared” service message. Available
|
||||
* in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
static requestUser(text: string, requestId: number, options?: Omit<KeyboardButtonRequestUser, "request_id">): KeyboardButton.RequestUserButton;
|
||||
/**
|
||||
* Adds a new request chat button. When the user presses the button, a list
|
||||
* of suitable users will be opened. Tapping on a chat will send its
|
||||
* identifier to the bot in a “chat_shared” service message. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
requestChat(text: string, requestId: number, options?: Omit<KeyboardButtonRequestChat, "request_id">): this;
|
||||
/**
|
||||
* Creates a new request chat button. When the user presses the button, a
|
||||
* list of suitable users will be opened. Tapping on a chat will send its
|
||||
* identifier to the bot in a “chat_shared” service message. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
static requestChat(text: string, requestId: number, options?: Omit<KeyboardButtonRequestChat, "request_id">): KeyboardButton.RequestChatButton;
|
||||
/**
|
||||
* Adds a new contact request button. The user's phone number will be sent
|
||||
* as a contact when the button is pressed. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
requestContact(text: string): this;
|
||||
/**
|
||||
* Creates a new contact request button. The user's phone number will be
|
||||
* sent as a contact when the button is pressed. Available in private chats
|
||||
* only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static requestContact(text: string): KeyboardButton.RequestContactButton;
|
||||
/**
|
||||
* Adds a new location request button. The user's current location will be
|
||||
* sent when the button is pressed. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
requestLocation(text: string): this;
|
||||
/**
|
||||
* Creates a new location request button. The user's current location will
|
||||
* be sent when the button is pressed. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static requestLocation(text: string): KeyboardButton.RequestLocationButton;
|
||||
/**
|
||||
* Adds a new poll request button. The user will be asked to create a poll
|
||||
* and send it to the bot when the button is pressed. Available in private
|
||||
* chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param type The type of permitted polls to create, omit if the user may
|
||||
* send a poll of any type
|
||||
*/
|
||||
requestPoll(text: string, type?: KeyboardButtonPollType["type"]): this;
|
||||
/**
|
||||
* Creates a new poll request button. The user will be asked to create a
|
||||
* poll and send it to the bot when the button is pressed. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param type The type of permitted polls to create, omit if the user may
|
||||
* send a poll of any type
|
||||
*/
|
||||
static requestPoll(text: string, type?: KeyboardButtonPollType["type"]): KeyboardButton.RequestPollButton;
|
||||
/**
|
||||
* Adds a new web app button. The Web App that will be launched when the
|
||||
* user presses the button. The Web App will be able to send a
|
||||
* “web_app_data” service message. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
webApp(text: string, url: string): this;
|
||||
/**
|
||||
* Creates a new web app button. The Web App that will be launched when the
|
||||
* user presses the button. The Web App will be able to send a
|
||||
* “web_app_data” service message. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
static webApp(text: string, url: string): KeyboardButton.WebAppButton;
|
||||
/**
|
||||
* Make the current keyboard persistent. See
|
||||
* https://grammy.dev/plugins/keyboard.html#persistent-keyboards for more
|
||||
* details.
|
||||
*
|
||||
* Keyboards are not persistent by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to not persist.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should persist, and `false` otherwise
|
||||
*/
|
||||
persistent(isEnabled?: boolean): this;
|
||||
/**
|
||||
* Make the current keyboard selective. See
|
||||
* https://grammy.dev/plugins/keyboard.html#selectively-send-custom-keyboards
|
||||
* for more details.
|
||||
*
|
||||
* Keyboards are non-selective by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to be non-selective.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should be selective, and `false` otherwise
|
||||
*/
|
||||
selected(isEnabled?: boolean): this;
|
||||
/**
|
||||
* Make the current keyboard one-time. See
|
||||
* https://grammy.dev/plugins/keyboard.html#one-time-custom-keyboards for
|
||||
* more details.
|
||||
*
|
||||
* Keyboards are non-one-time by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to be non-one-time.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should be one-time, and `false` otherwise
|
||||
*/
|
||||
oneTime(isEnabled?: boolean): this;
|
||||
/**
|
||||
* Make the current keyboard resized. See
|
||||
* https://grammy.dev/plugins/keyboard.html#resize-custom-keyboard for more
|
||||
* details.
|
||||
*
|
||||
* Keyboards are non-resized by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to be non-resized.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should be resized, and `false` otherwise
|
||||
*/
|
||||
resized(isEnabled?: boolean): this;
|
||||
/**
|
||||
* Set the current keyboard's input field placeholder. See
|
||||
* https://grammy.dev/plugins/keyboard.html#input-field-placeholder for more
|
||||
* details.
|
||||
*
|
||||
* @param value The placeholder text
|
||||
*/
|
||||
placeholder(value: string): this;
|
||||
/**
|
||||
* Creates a new keyboard that contains the transposed grid of buttons of
|
||||
* this keyboard. This means that the resulting keyboard has the rows and
|
||||
* columns flipped.
|
||||
*
|
||||
* Note that buttons can only span multiple columns, but never multiple
|
||||
* rows. This means that if the given arrays have different lengths, some
|
||||
* buttons might flow up in the layout. In these cases, transposing a
|
||||
* keyboard a second time will not undo the first transposition.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original transposed
|
||||
* [ a ] ~> [ a ]
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ]
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a c e]
|
||||
* [ c d ] ~> [ b d ]
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [a c d]
|
||||
* [ c ] ~> [ b e ]
|
||||
* [d e f] [ f ]
|
||||
* ```
|
||||
*/
|
||||
toTransposed(): Keyboard;
|
||||
/**
|
||||
* Creates a new keyboard with the same buttons but reflowed into a given
|
||||
* number of columns as if the buttons were text elements. Optionally, you
|
||||
* can specify if the flow should make sure to fill up the last row.
|
||||
*
|
||||
* This method is idempotent, so calling it a second time will effectively
|
||||
* clone this keyboard without reordering the buttons.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original flowed
|
||||
* [ a ] ~> [ a ] (4 columns)
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ] (1 column)
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a b c]
|
||||
* [ c d ] ~> [ d e ] (3 columns)
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [abcde]
|
||||
* [ c ] ~> [ f ] (5 columns)
|
||||
* [d e f]
|
||||
*
|
||||
* [a b c] [ a ]
|
||||
* [d e f] ~> [b c d] (3 colums, { fillLastRow: true })
|
||||
* [g h i] [e f g]
|
||||
* [ j ] [h i j]
|
||||
* ```
|
||||
*
|
||||
* @param columns Maximum number of buttons per row
|
||||
* @param options Optional flowing behavior
|
||||
*/
|
||||
toFlowed(columns: number, options?: FlowOptions): Keyboard;
|
||||
/**
|
||||
* Creates and returns a deep copy of this keyboard.
|
||||
*
|
||||
* Optionally takes a new grid of buttons to replace the current buttons. If
|
||||
* specified, only the options will be cloned, and the given buttons will be
|
||||
* used instead.
|
||||
*/
|
||||
clone(keyboard?: KeyboardButton[][]): Keyboard;
|
||||
/**
|
||||
* Appends the buttons of the given keyboards to this keyboard. If other
|
||||
* options are specified in these keyboards, they will be ignored.
|
||||
*
|
||||
* @param sources A number of keyboards to append
|
||||
*/
|
||||
append(...sources: KeyboardSource[]): this;
|
||||
/**
|
||||
* Returns the keyboard that was build. Note that it doesn't return
|
||||
* `resize_keyboard` or other options that may be set. You don't usually
|
||||
* need to call this method. It is no longer useful.
|
||||
*/
|
||||
build(): KeyboardButton[][];
|
||||
/**
|
||||
* Turns a two-dimensional keyboard button array into a keyboard instance.
|
||||
* You can use the static button builder methods to create keyboard button
|
||||
* objects.
|
||||
*
|
||||
* @param source A two-dimensional button array
|
||||
*/
|
||||
static from(source: KeyboardSource): Keyboard;
|
||||
}
|
||||
type InlineKeyboardSource = InlineKeyboardButton[][] | InlineKeyboard;
|
||||
/**
|
||||
* Use this class to simplify building an inline keyboard (something like this:
|
||||
* https://core.telegram.org/bots/features#inline-keyboards).
|
||||
*
|
||||
* ```ts
|
||||
* // Build an inline keyboard:
|
||||
* const keyboard = new InlineKeyboard()
|
||||
* .text('A').text('B', 'callback-data').row()
|
||||
* .text('C').text('D').row()
|
||||
* .url('Telegram', 'telegram.org')
|
||||
*
|
||||
* // Send the keyboard:
|
||||
* await ctx.reply('Here is your inline keyboard!', {
|
||||
* reply_markup: keyboard
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* If you already have some source data which you would like to turn into an
|
||||
* inline button object, you can use the static equivalents which every inline
|
||||
* button has. You can use them to create a two-dimensional inline button array.
|
||||
* The resulting array can be turned into a keyboard instance.
|
||||
*
|
||||
* ```ts
|
||||
* const button = InlineKeyboard.text('GO', 'go')
|
||||
* const array = [[button]]
|
||||
* const keyboard = InlineKeyboard.from(array)
|
||||
* ```
|
||||
*
|
||||
* Be sure to to check the
|
||||
* [documentation](https://grammy.dev/plugins/keyboard.html#inline-keyboards) on
|
||||
* inline keyboards in grammY.
|
||||
*/
|
||||
export declare class InlineKeyboard {
|
||||
readonly inline_keyboard: InlineKeyboardButton[][];
|
||||
/**
|
||||
* Initialize a new `InlineKeyboard` with an optional two-dimensional array
|
||||
* of `InlineKeyboardButton` objects. This is the nested array that holds
|
||||
* the inline keyboard. It will be extended every time you call one of the
|
||||
* provided methods.
|
||||
*
|
||||
* @param inline_keyboard An optional initial two-dimensional button array
|
||||
*/
|
||||
constructor(inline_keyboard?: InlineKeyboardButton[][]);
|
||||
/**
|
||||
* Allows you to add your own `InlineKeyboardButton` objects if you already
|
||||
* have them for some reason. You most likely want to call one of the other
|
||||
* methods.
|
||||
*
|
||||
* @param buttons The buttons to add
|
||||
*/
|
||||
add(...buttons: InlineKeyboardButton[]): this;
|
||||
/**
|
||||
* Adds a 'line break'. Call this method to make sure that the next added
|
||||
* buttons will be on a new row.
|
||||
*
|
||||
* You may pass a number of `InlineKeyboardButton` objects if you already
|
||||
* have the instances for some reason. You most likely don't want to pass
|
||||
* any arguments to `row`.
|
||||
*
|
||||
* @param buttons A number of buttons to add to the next row
|
||||
*/
|
||||
row(...buttons: InlineKeyboardButton[]): this;
|
||||
/**
|
||||
* Adds a new URL button. Telegram clients will open the provided URL when
|
||||
* the button is pressed.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
|
||||
*/
|
||||
url(text: string, url: string): this;
|
||||
/**
|
||||
* Creates a new URL button. Telegram clients will open the provided URL
|
||||
* when the button is pressed.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
|
||||
*/
|
||||
static url(text: string, url: string): InlineKeyboardButton.UrlButton;
|
||||
/**
|
||||
* Adds a new callback query button. The button contains a text and a custom
|
||||
* payload. This payload will be sent back to your bot when the button is
|
||||
* pressed. If you omit the payload, the display text will be sent back to
|
||||
* your bot.
|
||||
*
|
||||
* Your bot will receive an update every time a user presses any of the text
|
||||
* buttons. You can listen to these updates like this:
|
||||
* ```ts
|
||||
* // Specific buttons:
|
||||
* bot.callbackQuery('button-data', ctx => { ... })
|
||||
* // Any button of any inline keyboard:
|
||||
* bot.on('callback_query:data', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param data The callback data to send back to your bot (default = text)
|
||||
*/
|
||||
text(text: string, data?: string): this;
|
||||
/**
|
||||
* Creates a new callback query button. The button contains a text and a
|
||||
* custom payload. This payload will be sent back to your bot when the
|
||||
* button is pressed. If you omit the payload, the display text will be sent
|
||||
* back to your bot.
|
||||
*
|
||||
* Your bot will receive an update every time a user presses any of the text
|
||||
* buttons. You can listen to these updates like this:
|
||||
* ```ts
|
||||
* // Specific buttons:
|
||||
* bot.callbackQuery('button-data', ctx => { ... })
|
||||
* // Any button of any inline keyboard:
|
||||
* bot.on('callback_query:data', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param data The callback data to send back to your bot (default = text)
|
||||
*/
|
||||
static text(text: string, data?: string): InlineKeyboardButton.CallbackButton;
|
||||
/**
|
||||
* Adds a new web app button, confer https://core.telegram.org/bots/webapps
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
webApp(text: string, url: string): this;
|
||||
/**
|
||||
* Creates a new web app button, confer https://core.telegram.org/bots/webapps
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
static webApp(text: string, url: string): InlineKeyboardButton.WebAppButton;
|
||||
/**
|
||||
* Adds a new login button. This can be used as a replacement for the
|
||||
* Telegram Login Widget. You must specify an HTTPS URL used to
|
||||
* automatically authorize the user.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param loginUrl The login URL as string or `LoginUrl` object
|
||||
*/
|
||||
login(text: string, loginUrl: string | LoginUrl): this;
|
||||
/**
|
||||
* Creates a new login button. This can be used as a replacement for the
|
||||
* Telegram Login Widget. You must specify an HTTPS URL used to
|
||||
* automatically authorize the user.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param loginUrl The login URL as string or `LoginUrl` object
|
||||
*/
|
||||
static login(text: string, loginUrl: string | LoginUrl): InlineKeyboardButton.LoginButton;
|
||||
/**
|
||||
* Adds a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
switchInline(text: string, query?: string): this;
|
||||
/**
|
||||
* Creates a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
static switchInline(text: string, query?: string): InlineKeyboardButton.SwitchInlineButton;
|
||||
/**
|
||||
* Adds a new inline query button that acts on the current chat. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it. This will start an inline
|
||||
* query.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
switchInlineCurrent(text: string, query?: string): this;
|
||||
/**
|
||||
* Creates a new inline query button that acts on the current chat. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it. This will start an inline
|
||||
* query.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
static switchInlineCurrent(text: string, query?: string): InlineKeyboardButton.SwitchInlineCurrentChatButton;
|
||||
/**
|
||||
* Adds a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The query object describing which chats can be picked
|
||||
*/
|
||||
switchInlineChosen(text: string, query?: SwitchInlineQueryChosenChat): this;
|
||||
/**
|
||||
* Creates a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The query object describing which chats can be picked
|
||||
*/
|
||||
static switchInlineChosen(text: string, query?: SwitchInlineQueryChosenChat): InlineKeyboardButton.SwitchInlineChosenChatButton;
|
||||
/**
|
||||
* Adds a new game query button, confer
|
||||
* https://core.telegram.org/bots/api#games
|
||||
*
|
||||
* This type of button must always be the first button in the first row.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
game(text: string): this;
|
||||
/**
|
||||
* Creates a new game query button, confer
|
||||
* https://core.telegram.org/bots/api#games
|
||||
*
|
||||
* This type of button must always be the first button in the first row.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static game(text: string): InlineKeyboardButton.GameButton;
|
||||
/**
|
||||
* Adds a new payment button, confer
|
||||
* https://core.telegram.org/bots/api#payments
|
||||
*
|
||||
* This type of button must always be the first button in the first row and
|
||||
* can only be used in invoice messages.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
pay(text: string): this;
|
||||
/**
|
||||
* Create a new payment button, confer
|
||||
* https://core.telegram.org/bots/api#payments
|
||||
*
|
||||
* This type of button must always be the first button in the first row and
|
||||
* can only be used in invoice messages.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static pay(text: string): InlineKeyboardButton.PayButton;
|
||||
/**
|
||||
* Creates a new inline keyboard that contains the transposed grid of
|
||||
* buttons of this inline keyboard. This means that the resulting inline
|
||||
* keyboard has the rows and columns flipped.
|
||||
*
|
||||
* Note that inline buttons can only span multiple columns, but never
|
||||
* multiple rows. This means that if the given arrays have different
|
||||
* lengths, some buttons might flow up in the layout. In these cases,
|
||||
* transposing an inline keyboard a second time will not undo the first
|
||||
* transposition.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original transposed
|
||||
* [ a ] ~> [ a ]
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ]
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a c e]
|
||||
* [ c d ] ~> [ b d ]
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [a c d]
|
||||
* [ c ] ~> [ b e ]
|
||||
* [d e f] [ f ]
|
||||
* ```
|
||||
*/
|
||||
toTransposed(): InlineKeyboard;
|
||||
/**
|
||||
* Creates a new inline keyboard with the same buttons but reflowed into a
|
||||
* given number of columns as if the buttons were text elements. Optionally,
|
||||
* you can specify if the flow should make sure to fill up the last row.
|
||||
*
|
||||
* This method is idempotent, so calling it a second time will effectively
|
||||
* clone this inline keyboard without reordering the buttons.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original flowed
|
||||
* [ a ] ~> [ a ] (4 columns)
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ] (1 column)
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a b c]
|
||||
* [ c d ] ~> [ d e ] (3 columns)
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [abcde]
|
||||
* [ c ] ~> [ f ] (5 columns)
|
||||
* [d e f]
|
||||
*
|
||||
* [a b c] [ a ]
|
||||
* [d e f] ~> [b c d] (3 colums, { fillLastRow: true })
|
||||
* [g h i] [e f g]
|
||||
* [ j ] [h i j]
|
||||
* ```
|
||||
*
|
||||
* @param columns Maximum number of buttons per row
|
||||
* @param options Optional flowing behavior
|
||||
*/
|
||||
toFlowed(columns: number, options?: FlowOptions): InlineKeyboard;
|
||||
/**
|
||||
* Creates and returns a deep copy of this inline keyboard.
|
||||
*/
|
||||
clone(): InlineKeyboard;
|
||||
/**
|
||||
* Appends the buttons of the given inline keyboards to this keyboard.
|
||||
*
|
||||
* @param sources A number of inline keyboards to append
|
||||
*/
|
||||
append(...sources: InlineKeyboardSource[]): this;
|
||||
/**
|
||||
* Turns a two-dimensional inline button array into an inline keyboard
|
||||
* instance. You can use the static button builder methods to create inline
|
||||
* button objects.
|
||||
*
|
||||
* @param source A two-dimensional inline button array
|
||||
*/
|
||||
static from(source: InlineKeyboardSource): InlineKeyboard;
|
||||
}
|
||||
interface FlowOptions {
|
||||
/** Set to `true` to completely fill up the last row */
|
||||
fillLastRow?: boolean;
|
||||
}
|
||||
export {};
|
910
node_modules/grammy/out/convenience/keyboard.js
generated
vendored
Normal file
910
node_modules/grammy/out/convenience/keyboard.js
generated
vendored
Normal file
@@ -0,0 +1,910 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InlineKeyboard = exports.Keyboard = void 0;
|
||||
/**
|
||||
* Use this class to simplify building a custom keyboard (something like this:
|
||||
* https://core.telegram.org/bots/features#keyboards).
|
||||
*
|
||||
* ```ts
|
||||
* // Build a custom keyboard:
|
||||
* const keyboard = new Keyboard()
|
||||
* .text('A').text('B').row()
|
||||
* .text('C').text('D')
|
||||
*
|
||||
* // Now you can send it like so:
|
||||
* await ctx.reply('Here is your custom keyboard!', {
|
||||
* reply_markup: keyboard
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* If you already have some source data which you would like to turn into a
|
||||
* keyboard button object, you can use the static equivalents which every button
|
||||
* has. You can use them to create a two-dimensional keyboard button array. The
|
||||
* resulting array can be turned into a keyboard instance.
|
||||
*
|
||||
* ```ts
|
||||
* const button = Keyboard.text('push my buttons')
|
||||
* const array = [[button]]
|
||||
* const keyboard = Keyboard.from(array)
|
||||
* ```
|
||||
*
|
||||
* If you want to create text buttons only, you can directly use a
|
||||
* two-dimensional string array and turn it into a keyboard.
|
||||
*
|
||||
* ```ts
|
||||
* const data = [['A', 'B'], ['C', 'D']]
|
||||
* const keyboard = Keyboard.from(data)
|
||||
* ```
|
||||
*
|
||||
* Be sure to check out the
|
||||
* [documentation](https://grammy.dev/plugins/keyboard.html#custom-keyboards) on
|
||||
* custom keyboards in grammY.
|
||||
*/
|
||||
class Keyboard {
|
||||
/**
|
||||
* Initialize a new `Keyboard` with an optional two-dimensional array of
|
||||
* `KeyboardButton` objects. This is the nested array that holds the custom
|
||||
* keyboard. It will be extended every time you call one of the provided
|
||||
* methods.
|
||||
*
|
||||
* @param keyboard An optional initial two-dimensional button array
|
||||
*/
|
||||
constructor(keyboard = [[]]) {
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
/**
|
||||
* Allows you to add your own `KeyboardButton` objects if you already have
|
||||
* them for some reason. You most likely want to call one of the other
|
||||
* methods.
|
||||
*
|
||||
* @param buttons The buttons to add
|
||||
*/
|
||||
add(...buttons) {
|
||||
var _a;
|
||||
(_a = this.keyboard[this.keyboard.length - 1]) === null || _a === void 0 ? void 0 : _a.push(...buttons);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a 'line break'. Call this method to make sure that the next added
|
||||
* buttons will be on a new row.
|
||||
*
|
||||
* You may pass a number of `KeyboardButton` objects if you already have the
|
||||
* instances for some reason. You most likely don't want to pass any
|
||||
* arguments to `row`.
|
||||
*
|
||||
* @param buttons A number of buttons to add to the next row
|
||||
*/
|
||||
row(...buttons) {
|
||||
this.keyboard.push(buttons);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a new text button. This button will simply send the given text as a
|
||||
* text message back to your bot if a user clicks on it.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
text(text) {
|
||||
return this.add(Keyboard.text(text));
|
||||
}
|
||||
/**
|
||||
* Creates a new text button. This button will simply send the given text as
|
||||
* a text message back to your bot if a user clicks on it.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static text(text) {
|
||||
return { text };
|
||||
}
|
||||
/**
|
||||
* Adds a new request user button. When the user presses the button, a list
|
||||
* of suitable users will be opened. Tapping on any user will send their
|
||||
* identifier to the bot in a “user_shared” service message. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
requestUser(text, requestId, options = {}) {
|
||||
return this.add(Keyboard.requestUser(text, requestId, options));
|
||||
}
|
||||
/**
|
||||
* Creates a new request user button. When the user presses the button, a
|
||||
* list of suitable users will be opened. Tapping on any user will send
|
||||
* their identifier to the bot in a “user_shared” service message. Available
|
||||
* in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
static requestUser(text, requestId, options = {}) {
|
||||
return { text, request_user: { request_id: requestId, ...options } };
|
||||
}
|
||||
/**
|
||||
* Adds a new request chat button. When the user presses the button, a list
|
||||
* of suitable users will be opened. Tapping on a chat will send its
|
||||
* identifier to the bot in a “chat_shared” service message. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
requestChat(text, requestId, options = {
|
||||
chat_is_channel: false,
|
||||
}) {
|
||||
return this.add(Keyboard.requestChat(text, requestId, options));
|
||||
}
|
||||
/**
|
||||
* Creates a new request chat button. When the user presses the button, a
|
||||
* list of suitable users will be opened. Tapping on a chat will send its
|
||||
* identifier to the bot in a “chat_shared” service message. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param requestId A signed 32-bit identifier of the request
|
||||
* @param options Options object for further requirements
|
||||
*/
|
||||
static requestChat(text, requestId, options = {
|
||||
chat_is_channel: false,
|
||||
}) {
|
||||
return { text, request_chat: { request_id: requestId, ...options } };
|
||||
}
|
||||
/**
|
||||
* Adds a new contact request button. The user's phone number will be sent
|
||||
* as a contact when the button is pressed. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
requestContact(text) {
|
||||
return this.add(Keyboard.requestContact(text));
|
||||
}
|
||||
/**
|
||||
* Creates a new contact request button. The user's phone number will be
|
||||
* sent as a contact when the button is pressed. Available in private chats
|
||||
* only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static requestContact(text) {
|
||||
return { text, request_contact: true };
|
||||
}
|
||||
/**
|
||||
* Adds a new location request button. The user's current location will be
|
||||
* sent when the button is pressed. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
requestLocation(text) {
|
||||
return this.add(Keyboard.requestLocation(text));
|
||||
}
|
||||
/**
|
||||
* Creates a new location request button. The user's current location will
|
||||
* be sent when the button is pressed. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static requestLocation(text) {
|
||||
return { text, request_location: true };
|
||||
}
|
||||
/**
|
||||
* Adds a new poll request button. The user will be asked to create a poll
|
||||
* and send it to the bot when the button is pressed. Available in private
|
||||
* chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param type The type of permitted polls to create, omit if the user may
|
||||
* send a poll of any type
|
||||
*/
|
||||
requestPoll(text, type) {
|
||||
return this.add(Keyboard.requestPoll(text, type));
|
||||
}
|
||||
/**
|
||||
* Creates a new poll request button. The user will be asked to create a
|
||||
* poll and send it to the bot when the button is pressed. Available in
|
||||
* private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param type The type of permitted polls to create, omit if the user may
|
||||
* send a poll of any type
|
||||
*/
|
||||
static requestPoll(text, type) {
|
||||
return { text, request_poll: { type } };
|
||||
}
|
||||
/**
|
||||
* Adds a new web app button. The Web App that will be launched when the
|
||||
* user presses the button. The Web App will be able to send a
|
||||
* “web_app_data” service message. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
webApp(text, url) {
|
||||
return this.add(Keyboard.webApp(text, url));
|
||||
}
|
||||
/**
|
||||
* Creates a new web app button. The Web App that will be launched when the
|
||||
* user presses the button. The Web App will be able to send a
|
||||
* “web_app_data” service message. Available in private chats only.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
static webApp(text, url) {
|
||||
return { text, web_app: { url } };
|
||||
}
|
||||
/**
|
||||
* Make the current keyboard persistent. See
|
||||
* https://grammy.dev/plugins/keyboard.html#persistent-keyboards for more
|
||||
* details.
|
||||
*
|
||||
* Keyboards are not persistent by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to not persist.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should persist, and `false` otherwise
|
||||
*/
|
||||
persistent(isEnabled = true) {
|
||||
this.is_persistent = isEnabled;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Make the current keyboard selective. See
|
||||
* https://grammy.dev/plugins/keyboard.html#selectively-send-custom-keyboards
|
||||
* for more details.
|
||||
*
|
||||
* Keyboards are non-selective by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to be non-selective.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should be selective, and `false` otherwise
|
||||
*/
|
||||
selected(isEnabled = true) {
|
||||
this.selective = isEnabled;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Make the current keyboard one-time. See
|
||||
* https://grammy.dev/plugins/keyboard.html#one-time-custom-keyboards for
|
||||
* more details.
|
||||
*
|
||||
* Keyboards are non-one-time by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to be non-one-time.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should be one-time, and `false` otherwise
|
||||
*/
|
||||
oneTime(isEnabled = true) {
|
||||
this.one_time_keyboard = isEnabled;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Make the current keyboard resized. See
|
||||
* https://grammy.dev/plugins/keyboard.html#resize-custom-keyboard for more
|
||||
* details.
|
||||
*
|
||||
* Keyboards are non-resized by default, use this function to enable it
|
||||
* (without any parameters or pass `true`). Pass `false` to force the
|
||||
* keyboard to be non-resized.
|
||||
*
|
||||
* @param isEnabled `true` if the keyboard should be resized, and `false` otherwise
|
||||
*/
|
||||
resized(isEnabled = true) {
|
||||
this.resize_keyboard = isEnabled;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the current keyboard's input field placeholder. See
|
||||
* https://grammy.dev/plugins/keyboard.html#input-field-placeholder for more
|
||||
* details.
|
||||
*
|
||||
* @param value The placeholder text
|
||||
*/
|
||||
placeholder(value) {
|
||||
this.input_field_placeholder = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Creates a new keyboard that contains the transposed grid of buttons of
|
||||
* this keyboard. This means that the resulting keyboard has the rows and
|
||||
* columns flipped.
|
||||
*
|
||||
* Note that buttons can only span multiple columns, but never multiple
|
||||
* rows. This means that if the given arrays have different lengths, some
|
||||
* buttons might flow up in the layout. In these cases, transposing a
|
||||
* keyboard a second time will not undo the first transposition.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original transposed
|
||||
* [ a ] ~> [ a ]
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ]
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a c e]
|
||||
* [ c d ] ~> [ b d ]
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [a c d]
|
||||
* [ c ] ~> [ b e ]
|
||||
* [d e f] [ f ]
|
||||
* ```
|
||||
*/
|
||||
toTransposed() {
|
||||
const original = this.keyboard;
|
||||
const transposed = transpose(original);
|
||||
return this.clone(transposed);
|
||||
}
|
||||
/**
|
||||
* Creates a new keyboard with the same buttons but reflowed into a given
|
||||
* number of columns as if the buttons were text elements. Optionally, you
|
||||
* can specify if the flow should make sure to fill up the last row.
|
||||
*
|
||||
* This method is idempotent, so calling it a second time will effectively
|
||||
* clone this keyboard without reordering the buttons.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original flowed
|
||||
* [ a ] ~> [ a ] (4 columns)
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ] (1 column)
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a b c]
|
||||
* [ c d ] ~> [ d e ] (3 columns)
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [abcde]
|
||||
* [ c ] ~> [ f ] (5 columns)
|
||||
* [d e f]
|
||||
*
|
||||
* [a b c] [ a ]
|
||||
* [d e f] ~> [b c d] (3 colums, { fillLastRow: true })
|
||||
* [g h i] [e f g]
|
||||
* [ j ] [h i j]
|
||||
* ```
|
||||
*
|
||||
* @param columns Maximum number of buttons per row
|
||||
* @param options Optional flowing behavior
|
||||
*/
|
||||
toFlowed(columns, options = {}) {
|
||||
const original = this.keyboard;
|
||||
const flowed = reflow(original, columns, options);
|
||||
return this.clone(flowed);
|
||||
}
|
||||
/**
|
||||
* Creates and returns a deep copy of this keyboard.
|
||||
*
|
||||
* Optionally takes a new grid of buttons to replace the current buttons. If
|
||||
* specified, only the options will be cloned, and the given buttons will be
|
||||
* used instead.
|
||||
*/
|
||||
clone(keyboard = this.keyboard) {
|
||||
const clone = new Keyboard(keyboard.map((row) => row.slice()));
|
||||
clone.is_persistent = this.is_persistent;
|
||||
clone.selective = this.selective;
|
||||
clone.one_time_keyboard = this.one_time_keyboard;
|
||||
clone.resize_keyboard = this.resize_keyboard;
|
||||
clone.input_field_placeholder = this.input_field_placeholder;
|
||||
return clone;
|
||||
}
|
||||
/**
|
||||
* Appends the buttons of the given keyboards to this keyboard. If other
|
||||
* options are specified in these keyboards, they will be ignored.
|
||||
*
|
||||
* @param sources A number of keyboards to append
|
||||
*/
|
||||
append(...sources) {
|
||||
for (const source of sources) {
|
||||
const keyboard = Keyboard.from(source);
|
||||
this.keyboard.push(...keyboard.keyboard.map((row) => row.slice()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Returns the keyboard that was build. Note that it doesn't return
|
||||
* `resize_keyboard` or other options that may be set. You don't usually
|
||||
* need to call this method. It is no longer useful.
|
||||
*/
|
||||
build() {
|
||||
return this.keyboard;
|
||||
}
|
||||
/**
|
||||
* Turns a two-dimensional keyboard button array into a keyboard instance.
|
||||
* You can use the static button builder methods to create keyboard button
|
||||
* objects.
|
||||
*
|
||||
* @param source A two-dimensional button array
|
||||
*/
|
||||
static from(source) {
|
||||
if (source instanceof Keyboard)
|
||||
return source.clone();
|
||||
function toButton(btn) {
|
||||
return typeof btn === "string" ? Keyboard.text(btn) : btn;
|
||||
}
|
||||
return new Keyboard(source.map((row) => row.map(toButton)));
|
||||
}
|
||||
}
|
||||
exports.Keyboard = Keyboard;
|
||||
/**
|
||||
* Use this class to simplify building an inline keyboard (something like this:
|
||||
* https://core.telegram.org/bots/features#inline-keyboards).
|
||||
*
|
||||
* ```ts
|
||||
* // Build an inline keyboard:
|
||||
* const keyboard = new InlineKeyboard()
|
||||
* .text('A').text('B', 'callback-data').row()
|
||||
* .text('C').text('D').row()
|
||||
* .url('Telegram', 'telegram.org')
|
||||
*
|
||||
* // Send the keyboard:
|
||||
* await ctx.reply('Here is your inline keyboard!', {
|
||||
* reply_markup: keyboard
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* If you already have some source data which you would like to turn into an
|
||||
* inline button object, you can use the static equivalents which every inline
|
||||
* button has. You can use them to create a two-dimensional inline button array.
|
||||
* The resulting array can be turned into a keyboard instance.
|
||||
*
|
||||
* ```ts
|
||||
* const button = InlineKeyboard.text('GO', 'go')
|
||||
* const array = [[button]]
|
||||
* const keyboard = InlineKeyboard.from(array)
|
||||
* ```
|
||||
*
|
||||
* Be sure to to check the
|
||||
* [documentation](https://grammy.dev/plugins/keyboard.html#inline-keyboards) on
|
||||
* inline keyboards in grammY.
|
||||
*/
|
||||
class InlineKeyboard {
|
||||
/**
|
||||
* Initialize a new `InlineKeyboard` with an optional two-dimensional array
|
||||
* of `InlineKeyboardButton` objects. This is the nested array that holds
|
||||
* the inline keyboard. It will be extended every time you call one of the
|
||||
* provided methods.
|
||||
*
|
||||
* @param inline_keyboard An optional initial two-dimensional button array
|
||||
*/
|
||||
constructor(inline_keyboard = [[]]) {
|
||||
this.inline_keyboard = inline_keyboard;
|
||||
}
|
||||
/**
|
||||
* Allows you to add your own `InlineKeyboardButton` objects if you already
|
||||
* have them for some reason. You most likely want to call one of the other
|
||||
* methods.
|
||||
*
|
||||
* @param buttons The buttons to add
|
||||
*/
|
||||
add(...buttons) {
|
||||
var _a;
|
||||
(_a = this.inline_keyboard[this.inline_keyboard.length - 1]) === null || _a === void 0 ? void 0 : _a.push(...buttons);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a 'line break'. Call this method to make sure that the next added
|
||||
* buttons will be on a new row.
|
||||
*
|
||||
* You may pass a number of `InlineKeyboardButton` objects if you already
|
||||
* have the instances for some reason. You most likely don't want to pass
|
||||
* any arguments to `row`.
|
||||
*
|
||||
* @param buttons A number of buttons to add to the next row
|
||||
*/
|
||||
row(...buttons) {
|
||||
this.inline_keyboard.push(buttons);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a new URL button. Telegram clients will open the provided URL when
|
||||
* the button is pressed.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
|
||||
*/
|
||||
url(text, url) {
|
||||
return this.add(InlineKeyboard.url(text, url));
|
||||
}
|
||||
/**
|
||||
* Creates a new URL button. Telegram clients will open the provided URL
|
||||
* when the button is pressed.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.
|
||||
*/
|
||||
static url(text, url) {
|
||||
return { text, url };
|
||||
}
|
||||
/**
|
||||
* Adds a new callback query button. The button contains a text and a custom
|
||||
* payload. This payload will be sent back to your bot when the button is
|
||||
* pressed. If you omit the payload, the display text will be sent back to
|
||||
* your bot.
|
||||
*
|
||||
* Your bot will receive an update every time a user presses any of the text
|
||||
* buttons. You can listen to these updates like this:
|
||||
* ```ts
|
||||
* // Specific buttons:
|
||||
* bot.callbackQuery('button-data', ctx => { ... })
|
||||
* // Any button of any inline keyboard:
|
||||
* bot.on('callback_query:data', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param data The callback data to send back to your bot (default = text)
|
||||
*/
|
||||
text(text, data = text) {
|
||||
return this.add(InlineKeyboard.text(text, data));
|
||||
}
|
||||
/**
|
||||
* Creates a new callback query button. The button contains a text and a
|
||||
* custom payload. This payload will be sent back to your bot when the
|
||||
* button is pressed. If you omit the payload, the display text will be sent
|
||||
* back to your bot.
|
||||
*
|
||||
* Your bot will receive an update every time a user presses any of the text
|
||||
* buttons. You can listen to these updates like this:
|
||||
* ```ts
|
||||
* // Specific buttons:
|
||||
* bot.callbackQuery('button-data', ctx => { ... })
|
||||
* // Any button of any inline keyboard:
|
||||
* bot.on('callback_query:data', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param data The callback data to send back to your bot (default = text)
|
||||
*/
|
||||
static text(text, data = text) {
|
||||
return { text, callback_data: data };
|
||||
}
|
||||
/**
|
||||
* Adds a new web app button, confer https://core.telegram.org/bots/webapps
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
webApp(text, url) {
|
||||
return this.add(InlineKeyboard.webApp(text, url));
|
||||
}
|
||||
/**
|
||||
* Creates a new web app button, confer https://core.telegram.org/bots/webapps
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param url An HTTPS URL of a Web App to be opened with additional data
|
||||
*/
|
||||
static webApp(text, url) {
|
||||
return { text, web_app: { url } };
|
||||
}
|
||||
/**
|
||||
* Adds a new login button. This can be used as a replacement for the
|
||||
* Telegram Login Widget. You must specify an HTTPS URL used to
|
||||
* automatically authorize the user.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param loginUrl The login URL as string or `LoginUrl` object
|
||||
*/
|
||||
login(text, loginUrl) {
|
||||
return this.add(InlineKeyboard.login(text, loginUrl));
|
||||
}
|
||||
/**
|
||||
* Creates a new login button. This can be used as a replacement for the
|
||||
* Telegram Login Widget. You must specify an HTTPS URL used to
|
||||
* automatically authorize the user.
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param loginUrl The login URL as string or `LoginUrl` object
|
||||
*/
|
||||
static login(text, loginUrl) {
|
||||
return {
|
||||
text,
|
||||
login_url: typeof loginUrl === "string"
|
||||
? { url: loginUrl }
|
||||
: loginUrl,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Adds a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
switchInline(text, query = "") {
|
||||
return this.add(InlineKeyboard.switchInline(text, query));
|
||||
}
|
||||
/**
|
||||
* Creates a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
static switchInline(text, query = "") {
|
||||
return { text, switch_inline_query: query };
|
||||
}
|
||||
/**
|
||||
* Adds a new inline query button that acts on the current chat. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it. This will start an inline
|
||||
* query.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
switchInlineCurrent(text, query = "") {
|
||||
return this.add(InlineKeyboard.switchInlineCurrent(text, query));
|
||||
}
|
||||
/**
|
||||
* Creates a new inline query button that acts on the current chat. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it. This will start an inline
|
||||
* query.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The (optional) inline query string to prefill
|
||||
*/
|
||||
static switchInlineCurrent(text, query = "") {
|
||||
return { text, switch_inline_query_current_chat: query };
|
||||
}
|
||||
/**
|
||||
* Adds a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The query object describing which chats can be picked
|
||||
*/
|
||||
switchInlineChosen(text, query = {}) {
|
||||
return this.add(InlineKeyboard.switchInlineChosen(text, query));
|
||||
}
|
||||
/**
|
||||
* Creates a new inline query button. Telegram clients will let the user pick a
|
||||
* chat when this button is pressed. This will start an inline query. The
|
||||
* selected chat will be prefilled with the name of your bot. You may
|
||||
* provide a text that is specified along with it.
|
||||
*
|
||||
* Your bot will in turn receive updates for inline queries. You can listen
|
||||
* to inline query updates like this:
|
||||
* ```ts
|
||||
* bot.on('inline_query', ctx => { ... })
|
||||
* ```
|
||||
*
|
||||
* @param text The text to display
|
||||
* @param query The query object describing which chats can be picked
|
||||
*/
|
||||
static switchInlineChosen(text, query = {}) {
|
||||
return { text, switch_inline_query_chosen_chat: query };
|
||||
}
|
||||
/**
|
||||
* Adds a new game query button, confer
|
||||
* https://core.telegram.org/bots/api#games
|
||||
*
|
||||
* This type of button must always be the first button in the first row.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
game(text) {
|
||||
return this.add(InlineKeyboard.game(text));
|
||||
}
|
||||
/**
|
||||
* Creates a new game query button, confer
|
||||
* https://core.telegram.org/bots/api#games
|
||||
*
|
||||
* This type of button must always be the first button in the first row.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static game(text) {
|
||||
return { text, callback_game: {} };
|
||||
}
|
||||
/**
|
||||
* Adds a new payment button, confer
|
||||
* https://core.telegram.org/bots/api#payments
|
||||
*
|
||||
* This type of button must always be the first button in the first row and
|
||||
* can only be used in invoice messages.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
pay(text) {
|
||||
return this.add(InlineKeyboard.pay(text));
|
||||
}
|
||||
/**
|
||||
* Create a new payment button, confer
|
||||
* https://core.telegram.org/bots/api#payments
|
||||
*
|
||||
* This type of button must always be the first button in the first row and
|
||||
* can only be used in invoice messages.
|
||||
*
|
||||
* @param text The text to display
|
||||
*/
|
||||
static pay(text) {
|
||||
return { text, pay: true };
|
||||
}
|
||||
/**
|
||||
* Creates a new inline keyboard that contains the transposed grid of
|
||||
* buttons of this inline keyboard. This means that the resulting inline
|
||||
* keyboard has the rows and columns flipped.
|
||||
*
|
||||
* Note that inline buttons can only span multiple columns, but never
|
||||
* multiple rows. This means that if the given arrays have different
|
||||
* lengths, some buttons might flow up in the layout. In these cases,
|
||||
* transposing an inline keyboard a second time will not undo the first
|
||||
* transposition.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original transposed
|
||||
* [ a ] ~> [ a ]
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ]
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a c e]
|
||||
* [ c d ] ~> [ b d ]
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [a c d]
|
||||
* [ c ] ~> [ b e ]
|
||||
* [d e f] [ f ]
|
||||
* ```
|
||||
*/
|
||||
toTransposed() {
|
||||
const original = this.inline_keyboard;
|
||||
const transposed = transpose(original);
|
||||
return new InlineKeyboard(transposed);
|
||||
}
|
||||
/**
|
||||
* Creates a new inline keyboard with the same buttons but reflowed into a
|
||||
* given number of columns as if the buttons were text elements. Optionally,
|
||||
* you can specify if the flow should make sure to fill up the last row.
|
||||
*
|
||||
* This method is idempotent, so calling it a second time will effectively
|
||||
* clone this inline keyboard without reordering the buttons.
|
||||
*
|
||||
* Here are some examples.
|
||||
*
|
||||
* ```
|
||||
* original flowed
|
||||
* [ a ] ~> [ a ] (4 columns)
|
||||
*
|
||||
* [ a ]
|
||||
* [a b c] ~> [ b ] (1 column)
|
||||
* [ c ]
|
||||
*
|
||||
* [ a b ] [a b c]
|
||||
* [ c d ] ~> [ d e ] (3 columns)
|
||||
* [ e ]
|
||||
*
|
||||
* [ a b ] [abcde]
|
||||
* [ c ] ~> [ f ] (5 columns)
|
||||
* [d e f]
|
||||
*
|
||||
* [a b c] [ a ]
|
||||
* [d e f] ~> [b c d] (3 colums, { fillLastRow: true })
|
||||
* [g h i] [e f g]
|
||||
* [ j ] [h i j]
|
||||
* ```
|
||||
*
|
||||
* @param columns Maximum number of buttons per row
|
||||
* @param options Optional flowing behavior
|
||||
*/
|
||||
toFlowed(columns, options = {}) {
|
||||
const original = this.inline_keyboard;
|
||||
const flowed = reflow(original, columns, options);
|
||||
return new InlineKeyboard(flowed);
|
||||
}
|
||||
/**
|
||||
* Creates and returns a deep copy of this inline keyboard.
|
||||
*/
|
||||
clone() {
|
||||
return new InlineKeyboard(this.inline_keyboard.map((row) => row.slice()));
|
||||
}
|
||||
/**
|
||||
* Appends the buttons of the given inline keyboards to this keyboard.
|
||||
*
|
||||
* @param sources A number of inline keyboards to append
|
||||
*/
|
||||
append(...sources) {
|
||||
for (const source of sources) {
|
||||
const keyboard = InlineKeyboard.from(source);
|
||||
this.inline_keyboard.push(...keyboard.inline_keyboard.map((row) => row.slice()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Turns a two-dimensional inline button array into an inline keyboard
|
||||
* instance. You can use the static button builder methods to create inline
|
||||
* button objects.
|
||||
*
|
||||
* @param source A two-dimensional inline button array
|
||||
*/
|
||||
static from(source) {
|
||||
if (source instanceof InlineKeyboard)
|
||||
return source.clone();
|
||||
return new InlineKeyboard(source.map((row) => row.slice()));
|
||||
}
|
||||
}
|
||||
exports.InlineKeyboard = InlineKeyboard;
|
||||
function transpose(grid) {
|
||||
var _a;
|
||||
const transposed = [];
|
||||
for (let i = 0; i < grid.length; i++) {
|
||||
const row = grid[i];
|
||||
for (let j = 0; j < row.length; j++) {
|
||||
const button = row[j];
|
||||
((_a = transposed[j]) !== null && _a !== void 0 ? _a : (transposed[j] = [])).push(button);
|
||||
}
|
||||
}
|
||||
return transposed;
|
||||
}
|
||||
function reflow(grid, columns, { fillLastRow = false }) {
|
||||
var _a;
|
||||
let first = columns;
|
||||
if (fillLastRow) {
|
||||
const buttonCount = grid
|
||||
.map((row) => row.length)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
first = buttonCount % columns;
|
||||
}
|
||||
const reflowed = [];
|
||||
for (const row of grid) {
|
||||
for (const button of row) {
|
||||
const at = Math.max(0, reflowed.length - 1);
|
||||
const max = at === 0 ? first : columns;
|
||||
let next = ((_a = reflowed[at]) !== null && _a !== void 0 ? _a : (reflowed[at] = []));
|
||||
if (next.length === max) {
|
||||
next = [];
|
||||
reflowed.push(next);
|
||||
}
|
||||
next.push(button);
|
||||
}
|
||||
}
|
||||
return reflowed;
|
||||
}
|
338
node_modules/grammy/out/convenience/session.d.ts
generated
vendored
Normal file
338
node_modules/grammy/out/convenience/session.d.ts
generated
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
import { type MiddlewareFn } from "../composer.js";
|
||||
import { type Context } from "../context.js";
|
||||
type MaybePromise<T> = Promise<T> | T;
|
||||
/**
|
||||
* A session flavor is a context flavor that holds session data under
|
||||
* `ctx.session`.
|
||||
*
|
||||
* Session middleware will load the session data of a specific chat from your
|
||||
* storage solution, and make it available to you on the context object. Check
|
||||
* out the
|
||||
* [documentation](https://doc.deno.land/https://deno.land/x/grammy/mod.ts/~/session)
|
||||
* on session middleware to know more, and read the section about sessions on
|
||||
* the [website](https://grammy.dev/plugins/session.html).
|
||||
*/
|
||||
export interface SessionFlavor<S> {
|
||||
/**
|
||||
* Session data on the context object.
|
||||
*
|
||||
* **WARNING:** You have to make sure that your session data is not
|
||||
* undefined by _providing an initial value to the session middleware_, or by
|
||||
* making sure that `ctx.session` is assigned if it is empty! The type
|
||||
* system does not include `| undefined` because this is really annoying to
|
||||
* work with.
|
||||
*
|
||||
* Accessing `ctx.session` by reading or writing will throw if
|
||||
* `getSessionKey(ctx) === undefined` for the respective context object
|
||||
* `ctx`.
|
||||
*/
|
||||
get session(): S;
|
||||
set session(session: S | null | undefined);
|
||||
}
|
||||
/**
|
||||
* A lazy session flavor is a context flavor that holds a promise of some
|
||||
* session data under `ctx.session`.
|
||||
*
|
||||
* Lazy session middleware will provide this promise lazily on the context
|
||||
* object. Once you access `ctx.session`, the storage will be queried and the
|
||||
* session data becomes available. If you access `ctx.session` again for the
|
||||
* same context object, the cached value will be used. Check out the
|
||||
* [documentation](https://doc.deno.land/https://deno.land/x/grammy/mod.ts/~/lazySession)
|
||||
* on lazy session middleware to know more, and read the section about lazy
|
||||
* sessions on the
|
||||
* [website](https://grammy.dev/plugins/session.html#lazy-sessions).
|
||||
*/
|
||||
export interface LazySessionFlavor<S> {
|
||||
/**
|
||||
* Session data on the context object, potentially a promise.
|
||||
*
|
||||
* **WARNING:** You have to make sure that your session data is not
|
||||
* undefined by _providing a default value to the session middleware_, or by
|
||||
* making sure that `ctx.session` is assigned if it is empty! The type
|
||||
* system does not include `| undefined` because this is really annoying to
|
||||
* work with.
|
||||
*
|
||||
* Accessing `ctx.session` by reading or writing will throw iff
|
||||
* `getSessionKey(ctx) === undefined` holds for the respective context
|
||||
* object `ctx`.
|
||||
*/
|
||||
get session(): MaybePromise<S>;
|
||||
set session(session: MaybePromise<S | null | undefined>);
|
||||
}
|
||||
/**
|
||||
* A storage adapter is an abstraction that provides read, write, and delete
|
||||
* access to a storage solution of any kind. Storage adapters are used to keep
|
||||
* session middleware independent of your database provider, and they allow you
|
||||
* to pass your own storage solution.
|
||||
*/
|
||||
export interface StorageAdapter<T> {
|
||||
/**
|
||||
* Reads a value for the given key from the storage. May return the value or
|
||||
* undefined, or a promise of either.
|
||||
*/
|
||||
read: (key: string) => MaybePromise<T | undefined>;
|
||||
/**
|
||||
* Writes a value for the given key to the storage.
|
||||
*/
|
||||
write: (key: string, value: T) => MaybePromise<void>;
|
||||
/**
|
||||
* Deletes a value for the given key from the storage.
|
||||
*/
|
||||
delete: (key: string) => MaybePromise<void>;
|
||||
/**
|
||||
* Checks whether a key exists in the storage.
|
||||
*/
|
||||
has?: (key: string) => MaybePromise<boolean>;
|
||||
/**
|
||||
* Lists all keys.
|
||||
*/
|
||||
readAllKeys?: () => Iterable<string> | AsyncIterable<string>;
|
||||
/**
|
||||
* Lists all values.
|
||||
*/
|
||||
readAllValues?: () => Iterable<T> | AsyncIterable<T>;
|
||||
/**
|
||||
* Lists all keys with their values.
|
||||
*/
|
||||
readAllEntries?: () => Iterable<[key: string, value: T]> | AsyncIterable<[key: string, value: T]>;
|
||||
}
|
||||
/**
|
||||
* Options for session middleware.
|
||||
*/
|
||||
export interface SessionOptions<S, C extends Context = Context> {
|
||||
type?: "single";
|
||||
/**
|
||||
* **Recommended to use.**
|
||||
*
|
||||
* A function that produces an initial value for `ctx.session`. This
|
||||
* function will be called every time the storage solution returns undefined
|
||||
* for a given session key. Make sure to create a new value every time, such
|
||||
* that different context objects do that accidentally share the same
|
||||
* session data.
|
||||
*/
|
||||
initial?: () => S;
|
||||
/**
|
||||
* This option lets you generate your own session keys per context object.
|
||||
* The session key determines how to map the different session objects to
|
||||
* your chats and users. Check out the
|
||||
* [documentation](https://grammy.dev/plugins/session.html#how-to-use-sessions)
|
||||
* on the website about how to use session middleware to know how session
|
||||
* keys are used.
|
||||
*
|
||||
* The default implementation will store sessions per chat, as determined by
|
||||
* `ctx.chat?.id`.
|
||||
*/
|
||||
getSessionKey?: (ctx: Omit<C, "session">) => MaybePromise<string | undefined>;
|
||||
/**
|
||||
* A storage adapter to your storage solution. Provides read, write, and
|
||||
* delete access to the session middleware.
|
||||
*
|
||||
* Consider using a [known storage
|
||||
* adapter](https://grammy.dev/plugins/session.html#known-storage-adapters)
|
||||
* instead of rolling your own implementation of this.
|
||||
*
|
||||
* The default implementation will store session in memory. The data will be
|
||||
* lost whenever your bot restarts.
|
||||
*/
|
||||
storage?: StorageAdapter<S>;
|
||||
}
|
||||
/**
|
||||
* Options for session middleware if multi sessions are used. Specify `"type":
|
||||
* "multi"` in the options to use multi sessions.
|
||||
*/
|
||||
export type MultiSessionOptions<S, C extends Context> = S extends Record<string, any> ? {
|
||||
type: "multi";
|
||||
} & MultiSessionOptionsRecord<S, C> : never;
|
||||
type MultiSessionOptionsRecord<S extends Record<string, unknown>, C extends Context> = {
|
||||
[K in keyof S]: SessionOptions<S[K], C>;
|
||||
};
|
||||
/**
|
||||
* Session middleware provides a persistent data storage for your bot. You can
|
||||
* use it to let your bot remember any data you want, for example the messages
|
||||
* it sent or received in the past. This is done by attaching _session data_ to
|
||||
* every chat. The stored data is then provided on the context object under
|
||||
* `ctx.session`.
|
||||
*
|
||||
* > **What is a session?** Simply put, the session of a chat is a little
|
||||
* > persistent storage that is attached to it. As an example, your bot can send
|
||||
* > a message to a chat and store the ID of that message in the corresponding
|
||||
* > session. The next time your bot receives an update from that chat, the
|
||||
* > session will still contain that ID.
|
||||
* >
|
||||
* > Session data can be stored in a database, in a file, or simply in memory.
|
||||
* > grammY only supports memory sessions out of the box, but you can use
|
||||
* > third-party session middleware to connect to other storage solutions. Note
|
||||
* > that memory sessions will be lost when you stop your bot and the process
|
||||
* > exits, so they are usually not useful in production.
|
||||
*
|
||||
* Whenever your bot receives an update, the first thing the session middleware
|
||||
* will do is to load the correct session from your storage solution. This
|
||||
* object is then provided on `ctx.session` while your other middleware is
|
||||
* running. As soon as your bot is done handling the update, the middleware
|
||||
* takes over again and writes back the session object to your storage. This
|
||||
* allows you to modify the session object arbitrarily in your middleware, and
|
||||
* to stop worrying about the database.
|
||||
*
|
||||
* ```ts
|
||||
* bot.use(session())
|
||||
*
|
||||
* bot.on('message', ctx => {
|
||||
* // The session object is persisted across updates!
|
||||
* const session = ctx.session
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* It is recommended to make use of the `initial` option in the configuration
|
||||
* object, which correctly initializes session objects for new chats.
|
||||
*
|
||||
* You can delete the session data by setting `ctx.session` to `null` or
|
||||
* `undefined`.
|
||||
*
|
||||
* Check out the [documentation](https://grammy.dev/plugins/session.html) on the
|
||||
* website to know more about how sessions work in grammY.
|
||||
*
|
||||
* @param options Optional configuration to pass to the session middleware
|
||||
*/
|
||||
export declare function session<S, C extends Context>(options?: SessionOptions<S, C> | MultiSessionOptions<S, C>): MiddlewareFn<C & SessionFlavor<S>>;
|
||||
/**
|
||||
* > This is an advanced function of grammY.
|
||||
*
|
||||
* Generally speaking, lazy sessions work just like normal sessions—just they
|
||||
* are loaded on demand. Except for a few `async`s and `await`s here and there,
|
||||
* their usage looks 100 % identical.
|
||||
*
|
||||
* Instead of directly querying the storage every time an update arrives, lazy
|
||||
* sessions quickly do this _once you access_ `ctx.session`. This can
|
||||
* significantly reduce the database traffic (especially when your bot is added
|
||||
* to group chats), because it skips a read and a wrote operation for all
|
||||
* updates that the bot does not react to.
|
||||
*
|
||||
* ```ts
|
||||
* // The options are identical
|
||||
* bot.use(lazySession({ storage: ... }))
|
||||
*
|
||||
* bot.on('message', async ctx => {
|
||||
* // The session object is persisted across updates!
|
||||
* const session = await ctx.session
|
||||
* // ^
|
||||
* // |
|
||||
* // This plain property access (no function call) will trigger the database query!
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* Check out the
|
||||
* [documentation](https://grammy.dev/plugins/session.html#lazy-sessions) on the
|
||||
* website to know more about how lazy sessions work in grammY.
|
||||
*
|
||||
* @param options Optional configuration to pass to the session middleware
|
||||
*/
|
||||
export declare function lazySession<S, C extends Context>(options?: SessionOptions<S, C>): MiddlewareFn<C & LazySessionFlavor<S>>;
|
||||
/**
|
||||
* When enhancing a storage adapter, it needs to be able to store additional
|
||||
* information. It does this by wrapping the actual data inside an object, and
|
||||
* adding more properties to this wrapper.
|
||||
*
|
||||
* This interface defines the additional properties that need to be stored by a
|
||||
* storage adapter that supports enhanced sessions.
|
||||
*/
|
||||
export interface Enhance<T> {
|
||||
/** Version */
|
||||
v?: number;
|
||||
/** Data */
|
||||
__d: T;
|
||||
/** Expiry date */
|
||||
e?: number;
|
||||
}
|
||||
/** Options for enhanced sessions */
|
||||
export interface MigrationOptions<T> {
|
||||
/** The original storage adapter that will be enhanced */
|
||||
storage: StorageAdapter<Enhance<T>>;
|
||||
/**
|
||||
* A set of session migrations, defined as an object mapping from version
|
||||
* numbers to migration functions that transform data to the respective
|
||||
* version.
|
||||
*/
|
||||
migrations?: Migrations;
|
||||
/**
|
||||
* Number of milliseconds after the last write operation until the session
|
||||
* data expires.
|
||||
*/
|
||||
millisecondsToLive?: number;
|
||||
}
|
||||
/**
|
||||
* A mapping from version numbers to session migration functions. Each entry in
|
||||
* this object has a version number as a key, and a function as a value.
|
||||
*
|
||||
* For a key `n`, the respective value should be a function that takes the
|
||||
* previous session data and migrates it to conform with the data that is used
|
||||
* by version `n`. The previous session data is defined by the next key less
|
||||
* than `n`, such as `n-1`. Versions don't have to be integers, nor do all
|
||||
* versions have to be adjacent. For example, you can use `[1, 1.5, 4]` as
|
||||
* versions. If `n` is the lowest value in the set of keys, the function stored
|
||||
* for `n` can be used to migrate session data that was stored before migrations
|
||||
* were used.
|
||||
*/
|
||||
export interface Migrations {
|
||||
[version: number]: (old: any) => any;
|
||||
}
|
||||
/**
|
||||
* You can use this function to transform an existing storage adapter, and add
|
||||
* more features to it. Currently, you can add session migrations and expiry
|
||||
* dates.
|
||||
*
|
||||
* You can use this function like so:
|
||||
* ```ts
|
||||
* const storage = ... // define your storage adapter
|
||||
* const enhanced = enhanceStorage({ storage, millisecondsToLive: 500 })
|
||||
* bot.use(session({ storage: enhanced }))
|
||||
* ```
|
||||
*
|
||||
* @param options Session enhancing options
|
||||
* @returns The enhanced storage adapter
|
||||
*/
|
||||
export declare function enhanceStorage<T>(options: MigrationOptions<T>): StorageAdapter<T>;
|
||||
/**
|
||||
* The memory session storage is a built-in storage adapter that saves your
|
||||
* session data in RAM using a regular JavaScript `Map` object. If you use this
|
||||
* storage adapter, all sessions will be lost when your process terminates or
|
||||
* restarts. Hence, you should only use it for short-lived data that is not
|
||||
* important to persist.
|
||||
*
|
||||
* This class is used as default if you do not provide a storage adapter, e.g.
|
||||
* to your database.
|
||||
*
|
||||
* This storage adapter features expiring sessions. When instantiating this class
|
||||
* yourself, you can pass a time to live in milliseconds that will be used for
|
||||
* each session object. If a session for a user expired, the session data will
|
||||
* be discarded on its first read, and a fresh session object as returned by the
|
||||
* `initial` option (or undefined) will be put into place.
|
||||
*/
|
||||
export declare class MemorySessionStorage<S> implements StorageAdapter<S> {
|
||||
private readonly timeToLive?;
|
||||
/**
|
||||
* Internally used `Map` instance that stores the session data
|
||||
*/
|
||||
protected readonly storage: Map<string, {
|
||||
session: S;
|
||||
expires?: number | undefined;
|
||||
}>;
|
||||
/**
|
||||
* Constructs a new memory session storage with the given time to live. Note
|
||||
* that this storage adapter will not store your data permanently.
|
||||
*
|
||||
* @param timeToLive TTL in milliseconds, default is `Infinity`
|
||||
*/
|
||||
constructor(timeToLive?: number | undefined);
|
||||
read(key: string): S | undefined;
|
||||
/**
|
||||
* @deprecated Use {@link readAllValues} instead
|
||||
*/
|
||||
readAll(): S[];
|
||||
readAllKeys(): string[];
|
||||
readAllValues(): S[];
|
||||
readAllEntries(): [string, S][];
|
||||
has(key: string): boolean;
|
||||
write(key: string, value: S): void;
|
||||
delete(key: string): void;
|
||||
}
|
||||
export {};
|
447
node_modules/grammy/out/convenience/session.js
generated
vendored
Normal file
447
node_modules/grammy/out/convenience/session.js
generated
vendored
Normal file
@@ -0,0 +1,447 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MemorySessionStorage = exports.enhanceStorage = exports.lazySession = exports.session = void 0;
|
||||
const platform_node_js_1 = require("../platform.node.js");
|
||||
const debug = (0, platform_node_js_1.debug)("grammy:session");
|
||||
/**
|
||||
* Session middleware provides a persistent data storage for your bot. You can
|
||||
* use it to let your bot remember any data you want, for example the messages
|
||||
* it sent or received in the past. This is done by attaching _session data_ to
|
||||
* every chat. The stored data is then provided on the context object under
|
||||
* `ctx.session`.
|
||||
*
|
||||
* > **What is a session?** Simply put, the session of a chat is a little
|
||||
* > persistent storage that is attached to it. As an example, your bot can send
|
||||
* > a message to a chat and store the ID of that message in the corresponding
|
||||
* > session. The next time your bot receives an update from that chat, the
|
||||
* > session will still contain that ID.
|
||||
* >
|
||||
* > Session data can be stored in a database, in a file, or simply in memory.
|
||||
* > grammY only supports memory sessions out of the box, but you can use
|
||||
* > third-party session middleware to connect to other storage solutions. Note
|
||||
* > that memory sessions will be lost when you stop your bot and the process
|
||||
* > exits, so they are usually not useful in production.
|
||||
*
|
||||
* Whenever your bot receives an update, the first thing the session middleware
|
||||
* will do is to load the correct session from your storage solution. This
|
||||
* object is then provided on `ctx.session` while your other middleware is
|
||||
* running. As soon as your bot is done handling the update, the middleware
|
||||
* takes over again and writes back the session object to your storage. This
|
||||
* allows you to modify the session object arbitrarily in your middleware, and
|
||||
* to stop worrying about the database.
|
||||
*
|
||||
* ```ts
|
||||
* bot.use(session())
|
||||
*
|
||||
* bot.on('message', ctx => {
|
||||
* // The session object is persisted across updates!
|
||||
* const session = ctx.session
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* It is recommended to make use of the `initial` option in the configuration
|
||||
* object, which correctly initializes session objects for new chats.
|
||||
*
|
||||
* You can delete the session data by setting `ctx.session` to `null` or
|
||||
* `undefined`.
|
||||
*
|
||||
* Check out the [documentation](https://grammy.dev/plugins/session.html) on the
|
||||
* website to know more about how sessions work in grammY.
|
||||
*
|
||||
* @param options Optional configuration to pass to the session middleware
|
||||
*/
|
||||
function session(options = {}) {
|
||||
return options.type === "multi"
|
||||
? strictMultiSession(options)
|
||||
: strictSingleSession(options);
|
||||
}
|
||||
exports.session = session;
|
||||
function strictSingleSession(options) {
|
||||
const { initial, storage, getSessionKey, custom } = fillDefaults(options);
|
||||
return async (ctx, next) => {
|
||||
const propSession = new PropertySession(storage, ctx, "session", initial);
|
||||
const key = await getSessionKey(ctx);
|
||||
await propSession.init(key, { custom, lazy: false });
|
||||
await next(); // no catch: do not write back if middleware throws
|
||||
await propSession.finish();
|
||||
};
|
||||
}
|
||||
function strictMultiSession(options) {
|
||||
const props = Object.keys(options).filter((k) => k !== "type");
|
||||
const defaults = Object.fromEntries(props.map((prop) => [prop, fillDefaults(options[prop])]));
|
||||
return async (ctx, next) => {
|
||||
ctx.session = {};
|
||||
const propSessions = await Promise.all(props.map(async (prop) => {
|
||||
const { initial, storage, getSessionKey, custom } = defaults[prop];
|
||||
const s = new PropertySession(
|
||||
// @ts-ignore cannot express that the storage works for a concrete prop
|
||||
storage, ctx.session, prop, initial);
|
||||
const key = await getSessionKey(ctx);
|
||||
await s.init(key, { custom, lazy: false });
|
||||
return s;
|
||||
}));
|
||||
await next(); // no catch: do not write back if middleware throws
|
||||
if (ctx.session == null)
|
||||
propSessions.forEach((s) => s.delete());
|
||||
await Promise.all(propSessions.map((s) => s.finish()));
|
||||
};
|
||||
}
|
||||
/**
|
||||
* > This is an advanced function of grammY.
|
||||
*
|
||||
* Generally speaking, lazy sessions work just like normal sessions—just they
|
||||
* are loaded on demand. Except for a few `async`s and `await`s here and there,
|
||||
* their usage looks 100 % identical.
|
||||
*
|
||||
* Instead of directly querying the storage every time an update arrives, lazy
|
||||
* sessions quickly do this _once you access_ `ctx.session`. This can
|
||||
* significantly reduce the database traffic (especially when your bot is added
|
||||
* to group chats), because it skips a read and a wrote operation for all
|
||||
* updates that the bot does not react to.
|
||||
*
|
||||
* ```ts
|
||||
* // The options are identical
|
||||
* bot.use(lazySession({ storage: ... }))
|
||||
*
|
||||
* bot.on('message', async ctx => {
|
||||
* // The session object is persisted across updates!
|
||||
* const session = await ctx.session
|
||||
* // ^
|
||||
* // |
|
||||
* // This plain property access (no function call) will trigger the database query!
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* Check out the
|
||||
* [documentation](https://grammy.dev/plugins/session.html#lazy-sessions) on the
|
||||
* website to know more about how lazy sessions work in grammY.
|
||||
*
|
||||
* @param options Optional configuration to pass to the session middleware
|
||||
*/
|
||||
function lazySession(options = {}) {
|
||||
if (options.type !== undefined && options.type !== "single") {
|
||||
throw new Error("Cannot use lazy multi sessions!");
|
||||
}
|
||||
const { initial, storage, getSessionKey, custom } = fillDefaults(options);
|
||||
return async (ctx, next) => {
|
||||
const propSession = new PropertySession(
|
||||
// @ts-ignore suppress promise nature of values
|
||||
storage, ctx, "session", initial);
|
||||
const key = await getSessionKey(ctx);
|
||||
await propSession.init(key, { custom, lazy: true });
|
||||
await next(); // no catch: do not write back if middleware throws
|
||||
await propSession.finish();
|
||||
};
|
||||
}
|
||||
exports.lazySession = lazySession;
|
||||
/**
|
||||
* Internal class that manages a single property on the session. Can be used
|
||||
* both in a strict and a lazy way. Works by using `Object.defineProperty` to
|
||||
* install `O[P]`.
|
||||
*/
|
||||
// deno-lint-ignore ban-types
|
||||
class PropertySession {
|
||||
constructor(storage, obj, prop, initial) {
|
||||
this.storage = storage;
|
||||
this.obj = obj;
|
||||
this.prop = prop;
|
||||
this.initial = initial;
|
||||
this.fetching = false;
|
||||
this.read = false;
|
||||
this.wrote = false;
|
||||
}
|
||||
/** Performs a read op and stores the result in `this.value` */
|
||||
load() {
|
||||
if (this.key === undefined) {
|
||||
// No session key provided, cannot load
|
||||
return;
|
||||
}
|
||||
if (this.wrote) {
|
||||
// Value was set, no need to load
|
||||
return;
|
||||
}
|
||||
// Perform read op if not cached
|
||||
if (this.promise === undefined) {
|
||||
this.fetching = true;
|
||||
this.promise = Promise.resolve(this.storage.read(this.key))
|
||||
.then((val) => {
|
||||
var _a;
|
||||
this.fetching = false;
|
||||
// Check for write op in the meantime
|
||||
if (this.wrote) {
|
||||
// Discard read op
|
||||
return this.value;
|
||||
}
|
||||
// Store received value in `this.value`
|
||||
if (val !== undefined) {
|
||||
this.value = val;
|
||||
return val;
|
||||
}
|
||||
// No value, need to initialize
|
||||
val = (_a = this.initial) === null || _a === void 0 ? void 0 : _a.call(this);
|
||||
if (val !== undefined) {
|
||||
// Wrote initial value
|
||||
this.wrote = true;
|
||||
this.value = val;
|
||||
}
|
||||
return val;
|
||||
});
|
||||
}
|
||||
return this.promise;
|
||||
}
|
||||
async init(key, opts) {
|
||||
this.key = key;
|
||||
if (!opts.lazy)
|
||||
await this.load();
|
||||
Object.defineProperty(this.obj, this.prop, {
|
||||
enumerable: true,
|
||||
get: () => {
|
||||
if (key === undefined) {
|
||||
const msg = undef("access", opts);
|
||||
throw new Error(msg);
|
||||
}
|
||||
this.read = true;
|
||||
if (!opts.lazy || this.wrote)
|
||||
return this.value;
|
||||
this.load();
|
||||
return this.fetching ? this.promise : this.value;
|
||||
},
|
||||
set: (v) => {
|
||||
if (key === undefined) {
|
||||
const msg = undef("assign", opts);
|
||||
throw new Error(msg);
|
||||
}
|
||||
this.wrote = true;
|
||||
this.fetching = false;
|
||||
this.value = v;
|
||||
},
|
||||
});
|
||||
}
|
||||
delete() {
|
||||
Object.assign(this.obj, { [this.prop]: undefined });
|
||||
}
|
||||
async finish() {
|
||||
if (this.key !== undefined) {
|
||||
if (this.read)
|
||||
await this.load();
|
||||
if (this.read || this.wrote) {
|
||||
const value = await this.value;
|
||||
if (value == null)
|
||||
await this.storage.delete(this.key);
|
||||
else
|
||||
await this.storage.write(this.key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function fillDefaults(opts = {}) {
|
||||
let { getSessionKey = defaultGetSessionKey, initial, storage } = opts;
|
||||
if (storage == null) {
|
||||
debug("Storing session data in memory, all data will be lost when the bot restarts.");
|
||||
storage = new MemorySessionStorage();
|
||||
}
|
||||
const custom = getSessionKey !== defaultGetSessionKey;
|
||||
return { initial, storage, getSessionKey, custom };
|
||||
}
|
||||
/** Stores session data per chat by default */
|
||||
function defaultGetSessionKey(ctx) {
|
||||
var _a;
|
||||
return (_a = ctx.chat) === null || _a === void 0 ? void 0 : _a.id.toString();
|
||||
}
|
||||
/** Returns a useful error message for when the session key is undefined */
|
||||
function undef(op, opts) {
|
||||
const { lazy = false, custom } = opts;
|
||||
const reason = custom
|
||||
? "the custom `getSessionKey` function returned undefined for this update"
|
||||
: "this update does not belong to a chat, so the session key is undefined";
|
||||
return `Cannot ${op} ${lazy ? "lazy " : ""}session data because ${reason}!`;
|
||||
}
|
||||
function isEnhance(value) {
|
||||
return value === undefined ||
|
||||
typeof value === "object" && value !== null && "__d" in value;
|
||||
}
|
||||
/**
|
||||
* You can use this function to transform an existing storage adapter, and add
|
||||
* more features to it. Currently, you can add session migrations and expiry
|
||||
* dates.
|
||||
*
|
||||
* You can use this function like so:
|
||||
* ```ts
|
||||
* const storage = ... // define your storage adapter
|
||||
* const enhanced = enhanceStorage({ storage, millisecondsToLive: 500 })
|
||||
* bot.use(session({ storage: enhanced }))
|
||||
* ```
|
||||
*
|
||||
* @param options Session enhancing options
|
||||
* @returns The enhanced storage adapter
|
||||
*/
|
||||
function enhanceStorage(options) {
|
||||
let { storage, millisecondsToLive, migrations } = options;
|
||||
storage = compatStorage(storage);
|
||||
if (millisecondsToLive !== undefined) {
|
||||
storage = timeoutStorage(storage, millisecondsToLive);
|
||||
}
|
||||
if (migrations !== undefined) {
|
||||
storage = migrationStorage(storage, migrations);
|
||||
}
|
||||
return wrapStorage(storage);
|
||||
}
|
||||
exports.enhanceStorage = enhanceStorage;
|
||||
function compatStorage(storage) {
|
||||
return {
|
||||
read: async (k) => {
|
||||
const v = await storage.read(k);
|
||||
return isEnhance(v) ? v : { __d: v };
|
||||
},
|
||||
write: (k, v) => storage.write(k, v),
|
||||
delete: (k) => storage.delete(k),
|
||||
};
|
||||
}
|
||||
function timeoutStorage(storage, millisecondsToLive) {
|
||||
const ttlStorage = {
|
||||
read: async (k) => {
|
||||
const value = await storage.read(k);
|
||||
if (value === undefined)
|
||||
return undefined;
|
||||
if (value.e === undefined) {
|
||||
await ttlStorage.write(k, value);
|
||||
return value;
|
||||
}
|
||||
if (value.e < Date.now()) {
|
||||
await ttlStorage.delete(k);
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
write: async (k, v) => {
|
||||
v.e = addExpiryDate(v, millisecondsToLive).expires;
|
||||
await storage.write(k, v);
|
||||
},
|
||||
delete: (k) => storage.delete(k),
|
||||
};
|
||||
return ttlStorage;
|
||||
}
|
||||
function migrationStorage(storage, migrations) {
|
||||
const versions = Object.keys(migrations)
|
||||
.map((v) => parseInt(v))
|
||||
.sort((a, b) => a - b);
|
||||
const count = versions.length;
|
||||
if (count === 0)
|
||||
throw new Error("No migrations given!");
|
||||
const earliest = versions[0];
|
||||
const last = count - 1;
|
||||
const latest = versions[last];
|
||||
const index = new Map();
|
||||
versions.forEach((v, i) => index.set(v, i)); // inverse array lookup
|
||||
function nextAfter(current) {
|
||||
// TODO: use `findLastIndex` with Node 18
|
||||
let i = last;
|
||||
while (current <= versions[i])
|
||||
i--;
|
||||
return i;
|
||||
// return versions.findLastIndex((v) => v < current)
|
||||
}
|
||||
return {
|
||||
read: async (k) => {
|
||||
var _a;
|
||||
const val = await storage.read(k);
|
||||
if (val === undefined)
|
||||
return val;
|
||||
let { __d: value, v: current = earliest - 1 } = val;
|
||||
let i = 1 + ((_a = index.get(current)) !== null && _a !== void 0 ? _a : nextAfter(current));
|
||||
for (; i < count; i++)
|
||||
value = migrations[versions[i]](value);
|
||||
return { ...val, v: latest, __d: value };
|
||||
},
|
||||
write: (k, v) => storage.write(k, { v: latest, ...v }),
|
||||
delete: (k) => storage.delete(k),
|
||||
};
|
||||
}
|
||||
function wrapStorage(storage) {
|
||||
return {
|
||||
read: (k) => Promise.resolve(storage.read(k)).then((v) => v === null || v === void 0 ? void 0 : v.__d),
|
||||
write: (k, v) => storage.write(k, { __d: v }),
|
||||
delete: (k) => storage.delete(k),
|
||||
};
|
||||
}
|
||||
// === Memory storage adapter
|
||||
/**
|
||||
* The memory session storage is a built-in storage adapter that saves your
|
||||
* session data in RAM using a regular JavaScript `Map` object. If you use this
|
||||
* storage adapter, all sessions will be lost when your process terminates or
|
||||
* restarts. Hence, you should only use it for short-lived data that is not
|
||||
* important to persist.
|
||||
*
|
||||
* This class is used as default if you do not provide a storage adapter, e.g.
|
||||
* to your database.
|
||||
*
|
||||
* This storage adapter features expiring sessions. When instantiating this class
|
||||
* yourself, you can pass a time to live in milliseconds that will be used for
|
||||
* each session object. If a session for a user expired, the session data will
|
||||
* be discarded on its first read, and a fresh session object as returned by the
|
||||
* `initial` option (or undefined) will be put into place.
|
||||
*/
|
||||
class MemorySessionStorage {
|
||||
/**
|
||||
* Constructs a new memory session storage with the given time to live. Note
|
||||
* that this storage adapter will not store your data permanently.
|
||||
*
|
||||
* @param timeToLive TTL in milliseconds, default is `Infinity`
|
||||
*/
|
||||
constructor(timeToLive) {
|
||||
this.timeToLive = timeToLive;
|
||||
/**
|
||||
* Internally used `Map` instance that stores the session data
|
||||
*/
|
||||
this.storage = new Map();
|
||||
}
|
||||
read(key) {
|
||||
const value = this.storage.get(key);
|
||||
if (value === undefined)
|
||||
return undefined;
|
||||
if (value.expires !== undefined && value.expires < Date.now()) {
|
||||
this.delete(key);
|
||||
return undefined;
|
||||
}
|
||||
return value.session;
|
||||
}
|
||||
/**
|
||||
* @deprecated Use {@link readAllValues} instead
|
||||
*/
|
||||
readAll() {
|
||||
return this.readAllValues();
|
||||
}
|
||||
readAllKeys() {
|
||||
return Array.from(this.storage.keys());
|
||||
}
|
||||
readAllValues() {
|
||||
return Array
|
||||
.from(this.storage.keys())
|
||||
.map((key) => this.read(key))
|
||||
.filter((value) => value !== undefined);
|
||||
}
|
||||
readAllEntries() {
|
||||
return Array.from(this.storage.keys())
|
||||
.map((key) => [key, this.read(key)])
|
||||
.filter((pair) => pair[1] !== undefined);
|
||||
}
|
||||
has(key) {
|
||||
return this.storage.has(key);
|
||||
}
|
||||
write(key, value) {
|
||||
this.storage.set(key, addExpiryDate(value, this.timeToLive));
|
||||
}
|
||||
delete(key) {
|
||||
this.storage.delete(key);
|
||||
}
|
||||
}
|
||||
exports.MemorySessionStorage = MemorySessionStorage;
|
||||
function addExpiryDate(value, ttl) {
|
||||
if (ttl !== undefined && ttl < Infinity) {
|
||||
const now = Date.now();
|
||||
return { session: value, expires: now + ttl };
|
||||
}
|
||||
else {
|
||||
return { session: value };
|
||||
}
|
||||
}
|
32
node_modules/grammy/out/convenience/webhook.d.ts
generated
vendored
Normal file
32
node_modules/grammy/out/convenience/webhook.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { type Bot } from "../bot.js";
|
||||
import { type Context } from "../context.js";
|
||||
import { type FrameworkAdapter, type SupportedFrameworks } from "./frameworks.js";
|
||||
export interface WebhookOptions {
|
||||
/** An optional strategy to handle timeouts (default: 'throw') */
|
||||
onTimeout?: "throw" | "return" | ((...args: any[]) => unknown);
|
||||
/** An optional number of timeout milliseconds (default: 10_000) */
|
||||
timeoutMilliseconds?: number;
|
||||
/** An optional string to compare to X-Telegram-Bot-Api-Secret-Token */
|
||||
secretToken?: string;
|
||||
}
|
||||
/**
|
||||
* Creates a callback function that you can pass to a web framework (such as
|
||||
* express) if you want to run your bot via webhooks. Use it like this:
|
||||
* ```ts
|
||||
* const app = express() // or whatever you're using
|
||||
* const bot = new Bot('<token>')
|
||||
*
|
||||
* app.use(webhookCallback(bot, 'express'))
|
||||
* ```
|
||||
*
|
||||
* Confer the grammY
|
||||
* [documentation](https://grammy.dev/guide/deployment-types.html) to read more
|
||||
* about how to run your bot with webhooks.
|
||||
*
|
||||
* @param bot The bot for which to create a callback
|
||||
* @param adapter An optional string identifying the framework (default: 'express')
|
||||
* @param onTimeout An optional strategy to handle timeouts (default: 'throw')
|
||||
* @param timeoutMilliseconds An optional number of timeout milliseconds (default: 10_000)
|
||||
*/
|
||||
export declare function webhookCallback<C extends Context = Context>(bot: Bot<C>, adapter?: SupportedFrameworks | FrameworkAdapter, onTimeout?: WebhookOptions["onTimeout"], timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"], secretToken?: WebhookOptions["secretToken"]): (...args: any[]) => any;
|
||||
export declare function webhookCallback<C extends Context = Context>(bot: Bot<C>, adapter?: SupportedFrameworks | FrameworkAdapter, webhookOptions?: WebhookOptions): (...args: any[]) => any;
|
72
node_modules/grammy/out/convenience/webhook.js
generated
vendored
Normal file
72
node_modules/grammy/out/convenience/webhook.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.webhookCallback = void 0;
|
||||
const platform_node_js_1 = require("../platform.node.js");
|
||||
const frameworks_js_1 = require("./frameworks.js");
|
||||
const debugErr = (0, platform_node_js_1.debug)("grammy:error");
|
||||
const callbackAdapter = (update, callback, header, unauthorized = () => callback('"unauthorized"')) => ({
|
||||
update: Promise.resolve(update),
|
||||
respond: callback,
|
||||
header,
|
||||
unauthorized,
|
||||
});
|
||||
const adapters = { ...frameworks_js_1.adapters, callback: callbackAdapter };
|
||||
function webhookCallback(bot, adapter = platform_node_js_1.defaultAdapter, onTimeout = "throw", timeoutMilliseconds = 10000, secretToken) {
|
||||
const { onTimeout: timeout = "throw", timeoutMilliseconds: ms = 10000, secretToken: token, } = typeof onTimeout === "object"
|
||||
? onTimeout
|
||||
: { onTimeout, timeoutMilliseconds, secretToken };
|
||||
let initialized = false;
|
||||
const server = typeof adapter === "string"
|
||||
? adapters[adapter]
|
||||
: adapter;
|
||||
return async (...args) => {
|
||||
const { update, respond, unauthorized, end, handlerReturn, header } = server(...args);
|
||||
if (!initialized) {
|
||||
// Will dedupe concurrently incoming calls from several updates
|
||||
await bot.init();
|
||||
initialized = true;
|
||||
}
|
||||
if (header !== token) {
|
||||
await unauthorized();
|
||||
// TODO: investigate deno bug that happens when this console logging is removed
|
||||
console.log(handlerReturn);
|
||||
return handlerReturn;
|
||||
}
|
||||
let usedWebhookReply = false;
|
||||
const webhookReplyEnvelope = {
|
||||
async send(json) {
|
||||
usedWebhookReply = true;
|
||||
await respond(json);
|
||||
},
|
||||
};
|
||||
await timeoutIfNecessary(bot.handleUpdate(await update, webhookReplyEnvelope), typeof timeout === "function" ? () => timeout(...args) : timeout, ms);
|
||||
if (!usedWebhookReply)
|
||||
end === null || end === void 0 ? void 0 : end();
|
||||
return handlerReturn;
|
||||
};
|
||||
}
|
||||
exports.webhookCallback = webhookCallback;
|
||||
function timeoutIfNecessary(task, onTimeout, timeout) {
|
||||
if (timeout === Infinity)
|
||||
return task;
|
||||
return new Promise((resolve, reject) => {
|
||||
const handle = setTimeout(() => {
|
||||
if (onTimeout === "throw") {
|
||||
reject(new Error(`Request timed out after ${timeout} ms`));
|
||||
}
|
||||
else {
|
||||
if (typeof onTimeout === "function")
|
||||
onTimeout();
|
||||
resolve();
|
||||
}
|
||||
const now = Date.now();
|
||||
task.finally(() => {
|
||||
const diff = Date.now() - now;
|
||||
debugErr(`Request completed ${diff} ms after timeout!`);
|
||||
});
|
||||
}, timeout);
|
||||
task.then(resolve)
|
||||
.catch(reject)
|
||||
.finally(() => clearTimeout(handle));
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user