@grammyjs/hydrate
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -1,5 +0,6 @@ | ||
import { CallbackQuery, RawApi } from '../deps.node.js'; | ||
import { Other, Ret } from '../plugin.js'; | ||
import { MessageX } from './message.js'; | ||
export interface CallbackQueryX { | ||
import { CallbackQuery, RawApi } from "../deps.node.js"; | ||
import { Other, Ret } from "../plugin.js"; | ||
import { InlineMessageXFragment } from "./inline-message.js"; | ||
import { MessageX } from "./message.js"; | ||
interface CallbackQueryXFragment { | ||
message?: MessageX; | ||
@@ -16,5 +17,7 @@ /** | ||
*/ | ||
answer(other?: Other<'answerCallbackQuery', 'callback_query_id'>, signal?: AbortSignal): Ret<'answerCallbackQuery'>; | ||
answer(other?: Other<"answerCallbackQuery", "callback_query_id">, signal?: AbortSignal): Ret<"answerCallbackQuery">; | ||
} | ||
export declare type CallbackQueryX = CallbackQueryXFragment & Partial<InlineMessageXFragment> & CallbackQuery; | ||
export declare function installCallbackQueryMethods(api: RawApi, callbackQuery: CallbackQuery): void; | ||
import { AbortSignal } from "../shim.node.js"; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.installCallbackQueryMethods = void 0; | ||
const inline_message_js_1 = require("./inline-message.js"); | ||
const message_js_1 = require("./message.js"); | ||
function installCallbackQueryMethods(api, callbackQuery) { | ||
if (callbackQuery.message !== undefined) | ||
message_js_1.installMessageMethods(api, callbackQuery.message); | ||
if (callbackQuery.message !== undefined) { | ||
(0, message_js_1.installMessageMethods)(api, callbackQuery.message); | ||
} | ||
else if (callbackQuery.inline_message_id !== undefined) { | ||
(0, inline_message_js_1.installInlineMessageMethods)(api, { | ||
inline_message_id: callbackQuery.inline_message_id, | ||
}); | ||
} | ||
const methods = { | ||
@@ -9,0 +16,0 @@ answer: (other, signal) => api.answerCallbackQuery({ callback_query_id: callbackQuery.id, ...other }, signal), |
@@ -1,4 +0,4 @@ | ||
import { InlineQuery, InlineQueryResult, RawApi } from '../deps.node.js'; | ||
import { Other, Ret } from '../plugin.js'; | ||
export interface InlineQueryX { | ||
import { InlineQuery, InlineQueryResult, RawApi } from "../deps.node.js"; | ||
import { Other, Ret } from "../plugin.js"; | ||
interface InlineQueryXFragment { | ||
/** | ||
@@ -8,3 +8,3 @@ * Inline query-aware alias for `api.answerInlineQuery`. Use this method to send answers to an inline query. On success, True is returned. | ||
* | ||
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities. | ||
* Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an OAuth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities. | ||
* | ||
@@ -18,5 +18,7 @@ * @param inline_query_id Unique identifier for the answered query | ||
*/ | ||
answer(results: readonly InlineQueryResult[], other?: Other<'answerInlineQuery', 'inline_query_id' | 'results'>, signal?: AbortSignal): Ret<'answerInlineQuery'>; | ||
answer(results: readonly InlineQueryResult[], other?: Other<"answerInlineQuery", "inline_query_id" | "results">, signal?: AbortSignal): Ret<"answerInlineQuery">; | ||
} | ||
export declare type InlineQueryX = InlineQueryXFragment & InlineQuery; | ||
export declare function installInlineQueryMethods(api: RawApi, inlineQuery: InlineQuery): void; | ||
import { AbortSignal } from "../shim.node.js"; | ||
export {}; |
@@ -1,5 +0,6 @@ | ||
import { InlineKeyboardMarkup, InputFile, InputFileProxy, Message, RawApi } from '../deps.node.js'; | ||
import { Other as O, Ret } from '../plugin.js'; | ||
declare type Other<M extends keyof RawApi, K extends string = never> = O<M, K | 'chat_id' | 'message_id'>; | ||
export interface MessageX { | ||
import { Message, RawApi } from "../deps.node.js"; | ||
import { InlineMessageXFragment } from "./inline-message.js"; | ||
import { Other as O, Ret } from "../plugin.js"; | ||
declare type Other<M extends keyof RawApi, K extends string = never> = O<M, K | "chat_id" | "message_id">; | ||
interface MessageXFragment extends InlineMessageXFragment { | ||
/** | ||
@@ -14,3 +15,3 @@ * Message-aware alias for `api.forwardMessage`. Use this method to forward messages of any kind. Service messages can't be forwarded. On success, the sent Message is returned. | ||
*/ | ||
forward(chat_id: number | string, other?: Other<'forwardMessage', 'from_chat_id'>, signal?: AbortSignal): Ret<'forwardMessage'>; | ||
forward(chat_id: number | string, other?: Other<"forwardMessage", "from_chat_id">, signal?: AbortSignal): Ret<"forwardMessage">; | ||
/** | ||
@@ -25,3 +26,3 @@ * Message-aware alias for `api.copyMessage`. Use this method to copy messages of any kind. Service messages and invoice messages can't be copied. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. | ||
*/ | ||
copy(chat_id: number | string, other?: Other<'copyMessage', 'from_chat_id'>, signal?: AbortSignal): Ret<'copyMessage'>; | ||
copy(chat_id: number | string, other?: Other<"copyMessage", "from_chat_id">, signal?: AbortSignal): Ret<"copyMessage">; | ||
/** | ||
@@ -42,65 +43,7 @@ * Message-aware alias for `api.deleteMessage`. Use this method to delete a message, including service messages, with the following limitations: | ||
*/ | ||
delete(signal?: AbortSignal): Ret<'deleteMessage'>; | ||
/** | ||
* Message-aware alias for `api.editMessageReplyMarkup`. Use this method to edit only the reply markup of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. | ||
* | ||
* @param reply_markup An object for an inline keyboard. | ||
* @param signal Optional `AbortSignal` to cancel the request | ||
* | ||
* **Official reference:** https://core.telegram.org/bots/api#editmessagereplymarkup | ||
*/ | ||
editReplyMarkup(reply_markup?: InlineKeyboardMarkup, signal?: AbortSignal): Ret<'editMessageReplyMarkup'>; | ||
/** | ||
* Message-aware alias for `api.editMessageText`. Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. | ||
* | ||
* @param text New text of the message, 1-4096 characters after entities parsing | ||
* @param other Optional remaining parameters, confer the official reference below | ||
* @param signal Optional `AbortSignal` to cancel the request | ||
* | ||
* **Official reference:** https://core.telegram.org/bots/api#editmessagetext | ||
*/ | ||
editText(text: string, other?: Other<'editMessageText', 'text'>, signal?: AbortSignal): Ret<'editMessageText'>; | ||
/** | ||
* Message-aware alias for `api.editMessageLiveLocation`. Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. | ||
* | ||
* @param latitude Latitude of new location | ||
* @param longitude Longitude of new location | ||
* @param other Optional remaining parameters, confer the official reference below | ||
* @param signal Optional `AbortSignal` to cancel the request | ||
* | ||
* **Official reference:** https://core.telegram.org/bots/api#editmessagelivelocation | ||
*/ | ||
editLiveLocation(latitude: number, longitude: number, other?: Other<'editMessageLiveLocation', 'inline_message_id' | 'latitude' | 'longitude'>, signal?: AbortSignal): Ret<'editMessageLiveLocation'>; | ||
/** | ||
* Message-aware alias for `api.stopMessageLiveLocation`. Use this method to stop updating a live location message before live_period expires. On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. | ||
* | ||
* @param other Optional remaining parameters, confer the official reference below | ||
* @param signal Optional `AbortSignal` to cancel the request | ||
* | ||
* **Official reference:** https://core.telegram.org/bots/api#stopmessagelivelocation | ||
*/ | ||
stopLiveLocation(other?: Other<'stopMessageLiveLocation', 'inline_message_id'>, signal?: AbortSignal): Ret<'stopMessageLiveLocation'>; | ||
/** | ||
* Message-aware alias for `api.editMessageCaption`. Use this method to edit captions of messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. | ||
* | ||
* @param caption New caption of the message, 0-1024 characters after entities parsing | ||
* @param other Optional remaining parameters, confer the official reference below | ||
* @param signal Optional `AbortSignal` to cancel the request | ||
* | ||
* **Official reference:** https://core.telegram.org/bots/api#editmessagecaption | ||
*/ | ||
editCaption(caption?: string, other?: Other<'editMessageCaption', 'inline_message_id' | 'caption'>, signal?: AbortSignal): Ret<'editMessageCaption'>; | ||
/** | ||
* Message-aware alias for `api.editMessageMedia`. Use this method to edit animation, audio, document, photo, or video messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. | ||
* | ||
* @param media An object for a new media content of the message | ||
* @param other Optional remaining parameters, confer the official reference below | ||
* @param signal Optional `AbortSignal` to cancel the request | ||
* | ||
* **Official reference:** https://core.telegram.org/bots/api#editmessagemedia | ||
*/ | ||
editMedia(media: InputFileProxy<InputFile>['InputMedia'], other?: Other<'editMessageMedia', 'inline_message_id' | 'media'>, signal?: AbortSignal): Ret<'editMessageMedia'>; | ||
delete(signal?: AbortSignal): Ret<"deleteMessage">; | ||
} | ||
export declare type MessageX = MessageXFragment & Message; | ||
export declare function installMessageMethods(api: RawApi, message: Message): void; | ||
import { AbortSignal } from "../shim.node.js"; | ||
export {}; |
@@ -18,3 +18,3 @@ "use strict"; | ||
}, signal), | ||
delete: signal => api.deleteMessage({ | ||
delete: (signal) => api.deleteMessage({ | ||
chat_id: message.chat.id, | ||
@@ -21,0 +21,0 @@ message_id: message.message_id, |
@@ -1,4 +0,4 @@ | ||
import { PreCheckoutQuery, RawApi } from '../deps.node.js'; | ||
import { Other, Ret } from '../plugin.js'; | ||
export interface PreCheckoutQueryX { | ||
import { PreCheckoutQuery, RawApi } from "../deps.node.js"; | ||
import { Other, Ret } from "../plugin.js"; | ||
interface PreCheckoutQueryXFragment { | ||
/** | ||
@@ -13,5 +13,7 @@ * Pre-checkout query-aware alias for `api.answerPreCheckoutQuery`. Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned. Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. | ||
*/ | ||
answer(ok: boolean, other?: Other<'answerPreCheckoutQuery', 'pre_checkout_query_id'>, signal?: AbortSignal): Ret<'answerPreCheckoutQuery'>; | ||
answer(ok: boolean, other?: Other<"answerPreCheckoutQuery", "pre_checkout_query_id">, signal?: AbortSignal): Ret<"answerPreCheckoutQuery">; | ||
} | ||
export declare type PreCheckoutQueryX = PreCheckoutQueryXFragment & PreCheckoutQuery; | ||
export declare function installPreCheckoutQueryMethods(api: RawApi, preCheckoutQuery: PreCheckoutQuery): void; | ||
import { AbortSignal } from "../shim.node.js"; | ||
export {}; |
@@ -1,4 +0,4 @@ | ||
import { ShippingQuery, RawApi } from '../deps.node.js'; | ||
import { Other, Ret } from '../plugin.js'; | ||
export interface ShippingQueryX { | ||
import { RawApi, ShippingQuery } from "../deps.node.js"; | ||
import { Other, Ret } from "../plugin.js"; | ||
interface ShippingQueryXFragment { | ||
/** | ||
@@ -13,5 +13,7 @@ * Shipping query-aware alias for `api.answerShippingQuery`. If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned. | ||
*/ | ||
answer(ok: boolean, other?: Other<'answerShippingQuery', 'shipping_query_id' | 'ok'>, signal?: AbortSignal): Ret<'answerShippingQuery'>; | ||
answer(ok: boolean, other?: Other<"answerShippingQuery", "shipping_query_id" | "ok">, signal?: AbortSignal): Ret<"answerShippingQuery">; | ||
} | ||
export declare type ShippingQueryX = ShippingQueryXFragment & ShippingQuery; | ||
export declare function installShippingQueryMethods(api: RawApi, shippingQuery: ShippingQuery): void; | ||
import { AbortSignal } from "../shim.node.js"; | ||
export {}; |
@@ -1,2 +0,19 @@ | ||
import { RawApi, Update } from '../deps.node.js'; | ||
import { RawApi, Update } from "../deps.node.js"; | ||
import { CallbackQueryX } from "./callback-query.js"; | ||
import { InlineQueryX } from "./inline-query.js"; | ||
import { PreCheckoutQueryX } from "./pre-checkout-query.js"; | ||
import { ShippingQueryX } from "./shipping-query.js"; | ||
import { MessageX } from "./message.js"; | ||
import { ChosenInlineResultX } from "./chosen-inline-result.js"; | ||
export interface UpdateX extends Update { | ||
message: MessageX | undefined; | ||
edited_message: MessageX | undefined; | ||
channel_post: MessageX | undefined; | ||
edited_channel_post: MessageX | undefined; | ||
inline_query: InlineQueryX | undefined; | ||
callback_query: CallbackQueryX | undefined; | ||
shipping_query: ShippingQueryX | undefined; | ||
pre_checkout_query: PreCheckoutQueryX | undefined; | ||
chosen_inline_result: ChosenInlineResultX | undefined; | ||
} | ||
export declare function installUpdateMethods(api: RawApi, update: Update): void; |
@@ -9,20 +9,32 @@ "use strict"; | ||
const message_js_1 = require("./message.js"); | ||
const chosen_inline_result_js_1 = require("./chosen-inline-result.js"); | ||
function installUpdateMethods(api, update) { | ||
if (update.message !== undefined) | ||
message_js_1.installMessageMethods(api, update.message); | ||
else if (update.channel_post !== undefined) | ||
message_js_1.installMessageMethods(api, update.channel_post); | ||
else if (update.edited_message !== undefined) | ||
message_js_1.installMessageMethods(api, update.edited_message); | ||
else if (update.edited_channel_post !== undefined) | ||
message_js_1.installMessageMethods(api, update.edited_channel_post); | ||
else if (update.inline_query !== undefined) | ||
inline_query_js_1.installInlineQueryMethods(api, update.inline_query); | ||
else if (update.callback_query !== undefined) | ||
callback_query_js_1.installCallbackQueryMethods(api, update.callback_query); | ||
else if (update.shipping_query !== undefined) | ||
shipping_query_js_1.installShippingQueryMethods(api, update.shipping_query); | ||
else if (update.pre_checkout_query !== undefined) | ||
pre_checkout_query_js_1.installPreCheckoutQueryMethods(api, update.pre_checkout_query); | ||
if (update.message !== undefined) { | ||
(0, message_js_1.installMessageMethods)(api, update.message); | ||
} | ||
else if (update.channel_post !== undefined) { | ||
(0, message_js_1.installMessageMethods)(api, update.channel_post); | ||
} | ||
else if (update.edited_message !== undefined) { | ||
(0, message_js_1.installMessageMethods)(api, update.edited_message); | ||
} | ||
else if (update.edited_channel_post !== undefined) { | ||
(0, message_js_1.installMessageMethods)(api, update.edited_channel_post); | ||
} | ||
else if (update.inline_query !== undefined) { | ||
(0, inline_query_js_1.installInlineQueryMethods)(api, update.inline_query); | ||
} | ||
else if (update.callback_query !== undefined) { | ||
(0, callback_query_js_1.installCallbackQueryMethods)(api, update.callback_query); | ||
} | ||
else if (update.shipping_query !== undefined) { | ||
(0, shipping_query_js_1.installShippingQueryMethods)(api, update.shipping_query); | ||
} | ||
else if (update.pre_checkout_query !== undefined) { | ||
(0, pre_checkout_query_js_1.installPreCheckoutQueryMethods)(api, update.pre_checkout_query); | ||
} | ||
else if (update.chosen_inline_result !== undefined) { | ||
(0, chosen_inline_result_js_1.installChosenInlineResultMethods)(api, update.chosen_inline_result); | ||
} | ||
} | ||
exports.installUpdateMethods = installUpdateMethods; |
@@ -1,2 +0,2 @@ | ||
export { Api, Context, InputFile, Transformer, RawApi, ApiCallFn } from 'grammy'; | ||
export * from '@grammyjs/types'; | ||
export { Api, ApiCallFn, Context, InputFile, RawApi, Transformer, } from "grammy"; | ||
export * from "@grammyjs/types"; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,1 +0,1 @@ | ||
export * from './plugin.js'; | ||
export * from "./plugin.js"; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,7 +0,8 @@ | ||
import { Context, Api, RawApi, Transformer, InputFileProxy, InputFile } from './deps.node.js'; | ||
import { MessageX } from './data/message.js'; | ||
import { CallbackQueryX } from './data/callback-query.js'; | ||
import { InlineQueryX } from './data/inline-query.js'; | ||
import { ShippingQueryX } from './data/shipping-query.js'; | ||
import { PreCheckoutQueryX } from './data/pre-checkout-query.js'; | ||
import { Api, Context, InputFile, InputFileProxy, RawApi, Transformer } from "./deps.node.js"; | ||
import { UpdateX } from "./data/update.js"; | ||
import { MessageX } from "./data/message.js"; | ||
import { CallbackQueryX } from "./data/callback-query.js"; | ||
import { InlineQueryX } from "./data/inline-query.js"; | ||
import { ShippingQueryX } from "./data/shipping-query.js"; | ||
import { PreCheckoutQueryX } from "./data/pre-checkout-query.js"; | ||
/** | ||
@@ -13,4 +14,4 @@ * Transformative API Flavor that adds file handling utilities to the supplied | ||
*/ | ||
export declare type HydrateFlavor<C extends Context> = ContextX<C> & C; | ||
export declare type HydrateApiFlavor<A extends Api> = ApiX<A> & A; | ||
export declare type HydrateFlavor<C extends Context> = ObjectAssign<C, ContextX<C>>; | ||
export declare type HydrateApiFlavor<A extends Api> = ApiX<A>; | ||
/** | ||
@@ -65,38 +66,32 @@ * Mapping table from method names to API call result extensions. | ||
export declare type Other<M extends keyof RawApi, K extends string = never> = Omit<Opts<M>, K>; | ||
export declare type Opts<M extends keyof RawApi> = InputFileProxy<InputFile>['Opts'][M]; | ||
export declare type Opts<M extends keyof RawApi> = InputFileProxy<InputFile>["Opts"][M]; | ||
export declare type Ret<M extends keyof RawApi> = ReturnType<RawApi[M]>; | ||
declare type ObjectAssign<DestType, SourceType> = { | ||
[Key in keyof (DestType & SourceType)]: Key extends keyof SourceType ? SourceType[Key] : Key extends keyof DestType ? DestType[Key] : never; | ||
}; | ||
interface ContextX<C extends Context> { | ||
api: ApiX<C['api']>; | ||
reply: Extend<C['reply'], X['sendMessage']>; | ||
forwardMessage: Extend<C['forwardMessage'], X['forwardMessage']>; | ||
replyWithPhoto: Extend<C['replyWithPhoto'], X['sendPhoto']>; | ||
replyWithAudio: Extend<C['replyWithAudio'], X['sendAudio']>; | ||
replyWithDocument: Extend<C['replyWithDocument'], X['sendDocument']>; | ||
replyWithVideo: Extend<C['replyWithVideo'], X['sendVideo']>; | ||
replyWithAnimation: Extend<C['replyWithAnimation'], X['sendAnimation']>; | ||
replyWithVoice: Extend<C['replyWithVoice'], X['sendVoice']>; | ||
replyWithVideoNote: Extend<C['replyWithVideoNote'], X['sendVideoNote']>; | ||
editMessageLiveLocation: Extend<C['editMessageLiveLocation'], X['editMessageLiveLocation']>; | ||
stopMessageLiveLocation: Extend<C['stopMessageLiveLocation'], X['stopMessageLiveLocation']>; | ||
replyWithVenue: Extend<C['replyWithVenue'], X['sendVenue']>; | ||
replyWithContact: Extend<C['replyWithContact'], X['sendContact']>; | ||
replyWithPoll: Extend<C['replyWithPoll'], X['sendPoll']>; | ||
replyWithDice: Extend<C['replyWithDice'], X['sendDice']>; | ||
editMessageText: Extend<C['editMessageText'], X['editMessageText']>; | ||
editMessageCaption: Extend<C['editMessageCaption'], X['editMessageCaption']>; | ||
editMessageMedia: Extend<C['editMessageMedia'], X['editMessageMedia']>; | ||
editMessageReplyMarkup: Extend<C['editMessageReplyMarkup'], X['editMessageReplyMarkup']>; | ||
replyWithSticker: Extend<C['replyWithSticker'], X['sendSticker']>; | ||
replyWithInvoice: Extend<C['replyWithInvoice'], X['sendInvoice']>; | ||
replyWithGame: Extend<C['replyWithGame'], X['sendGame']>; | ||
update: { | ||
message: MessageX | undefined; | ||
edited_message: MessageX | undefined; | ||
channelPost: MessageX | undefined; | ||
edited_channel_post: MessageX | undefined; | ||
inline_query: InlineQueryX | undefined; | ||
callback_query: CallbackQueryX | undefined; | ||
shipping_query: ShippingQueryX | undefined; | ||
pre_checkout_query: PreCheckoutQueryX | undefined; | ||
}; | ||
api: ApiX<C["api"]>; | ||
reply: Extend<C["reply"], X["sendMessage"]>; | ||
forwardMessage: Extend<C["forwardMessage"], X["forwardMessage"]>; | ||
replyWithPhoto: Extend<C["replyWithPhoto"], X["sendPhoto"]>; | ||
replyWithAudio: Extend<C["replyWithAudio"], X["sendAudio"]>; | ||
replyWithDocument: Extend<C["replyWithDocument"], X["sendDocument"]>; | ||
replyWithVideo: Extend<C["replyWithVideo"], X["sendVideo"]>; | ||
replyWithAnimation: Extend<C["replyWithAnimation"], X["sendAnimation"]>; | ||
replyWithVoice: Extend<C["replyWithVoice"], X["sendVoice"]>; | ||
replyWithVideoNote: Extend<C["replyWithVideoNote"], X["sendVideoNote"]>; | ||
editMessageLiveLocation: Extend<C["editMessageLiveLocation"], X["editMessageLiveLocation"]>; | ||
stopMessageLiveLocation: Extend<C["stopMessageLiveLocation"], X["stopMessageLiveLocation"]>; | ||
replyWithVenue: Extend<C["replyWithVenue"], X["sendVenue"]>; | ||
replyWithContact: Extend<C["replyWithContact"], X["sendContact"]>; | ||
replyWithPoll: Extend<C["replyWithPoll"], X["sendPoll"]>; | ||
replyWithDice: Extend<C["replyWithDice"], X["sendDice"]>; | ||
editMessageText: Extend<C["editMessageText"], X["editMessageText"]>; | ||
editMessageCaption: Extend<C["editMessageCaption"], X["editMessageCaption"]>; | ||
editMessageMedia: Extend<C["editMessageMedia"], X["editMessageMedia"]>; | ||
editMessageReplyMarkup: Extend<C["editMessageReplyMarkup"], X["editMessageReplyMarkup"]>; | ||
replyWithSticker: Extend<C["replyWithSticker"], X["sendSticker"]>; | ||
replyWithInvoice: Extend<C["replyWithInvoice"], X["sendInvoice"]>; | ||
replyWithGame: Extend<C["replyWithGame"], X["sendGame"]>; | ||
update: UpdateX; | ||
message: MessageX | undefined; | ||
@@ -113,7 +108,7 @@ editedMessage: MessageX | undefined; | ||
declare type ApiX<A extends Api> = AddX<A> & { | ||
raw: RawApiX<A['raw']>; | ||
raw: RawApiX<A["raw"]>; | ||
}; | ||
declare type RawApiX<R extends RawApi> = AddX<R>; | ||
declare type AddX<Q extends Record<keyof X, (...args: any[]) => any>> = { | ||
[K in keyof X]: Extend<Q[K], X[K]>; | ||
[K in keyof Q]: K extends keyof X ? Extend<Q[K], X[K]> : Q[K]; | ||
}; | ||
@@ -120,0 +115,0 @@ declare type Extend<F extends (...args: any[]) => any, X> = (...args: Parameters<F>) => Promise<Await<ReturnType<F>> & X>; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const message_js_1 = require("./data/message.js"); | ||
const inline_message_js_1 = require("./data/inline-message.js"); | ||
/** | ||
@@ -23,3 +24,3 @@ * Plugin that hydrates the context object and API call results, and equips the | ||
ctx.api.config.use(hydrator); | ||
update_js_1.installUpdateMethods(ctx.api.raw, ctx.update); | ||
(0, update_js_1.installUpdateMethods)(ctx.api.raw, ctx.update); | ||
return next(); | ||
@@ -31,3 +32,3 @@ }; | ||
return (ctx, next) => { | ||
update_js_1.installUpdateMethods(ctx.api.raw, ctx.update); | ||
(0, update_js_1.installUpdateMethods)(ctx.api.raw, ctx.update); | ||
return next(); | ||
@@ -41,4 +42,8 @@ }; | ||
if (res.ok) { | ||
if (isMessage(res.result)) | ||
message_js_1.installMessageMethods(toApi(prev), res.result); | ||
if (isMessage(res.result)) { | ||
(0, message_js_1.installMessageMethods)(toApi(prev), res.result); | ||
} | ||
else if (isInlineMessage(res.result)) { | ||
(0, inline_message_js_1.installInlineMessageMethods)(toApi(prev), res.result); | ||
} | ||
// TODO: hydrate other method call results | ||
@@ -52,7 +57,12 @@ } | ||
function isMessage(obj) { | ||
return (typeof obj === 'object' && | ||
return (typeof obj === "object" && | ||
obj !== null && | ||
'message_id' in obj && | ||
'chat' in obj); | ||
"message_id" in obj && | ||
"chat" in obj); | ||
} | ||
function isInlineMessage(obj) { | ||
return (typeof obj === "object" && | ||
obj !== null && | ||
"inline_message_id" in obj); | ||
} | ||
// TODO: add support for the following methods of these objects | ||
@@ -72,2 +82,3 @@ // === USERS | ||
// - get admins | ||
// - get private chat, get group chat, etc with narrowed return types | ||
// - etc | ||
@@ -74,0 +85,0 @@ // - all send message methods? |
@@ -1,1 +0,1 @@ | ||
export type { AbortSignal } from 'abort-controller'; | ||
export type { AbortSignal } from "abort-controller"; |
{ | ||
"name": "@grammyjs/hydrate", | ||
"description": "Hydration plugin for grammY", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"author": "KnorpelSenf", | ||
@@ -19,3 +19,5 @@ "license": "MIT", | ||
"scripts": { | ||
"build": "deno2node tsconfig.json" | ||
"build": "deno2node tsconfig.json", | ||
"format": "deno fmt --config deno.json", | ||
"lint": "deno lint --config deno.json" | ||
}, | ||
@@ -29,5 +31,5 @@ "dependencies": { | ||
"devDependencies": { | ||
"@grammyjs/types": "^2.2.6", | ||
"@types/node": "^16.6.1", | ||
"deno2node": "0.8.0" | ||
"@grammyjs/types": "^2.7.0", | ||
"@types/node": "^17.0.24", | ||
"deno2node": "1.3.0" | ||
}, | ||
@@ -34,0 +36,0 @@ "files": [ |
@@ -16,10 +16,10 @@ # Hydration plugin for grammY | ||
```ts | ||
bot.on(':photo', async ctx => { | ||
const statusMessage = await ctx.reply('Processing your image, please wait') | ||
await doWork() // some long image processing | ||
await ctx.api.deleteMessage(statusMessage.message_id) | ||
}) | ||
bot.on('callback_query', async ctx => { | ||
await ctx.answerCallbackQuery() | ||
}) | ||
bot.on(":photo", async (ctx) => { | ||
const statusMessage = await ctx.reply("Processing your image, please wait"); | ||
await doWork(); // some long image processing | ||
await ctx.api.deleteMessage(statusMessage.message_id); | ||
}); | ||
bot.on("callback_query", async (ctx) => { | ||
await ctx.answerCallbackQuery(); | ||
}); | ||
``` | ||
@@ -30,10 +30,10 @@ | ||
```ts | ||
bot.on(':photo', async ctx => { | ||
const statusMessage = await ctx.reply('Processing your image, please wait') | ||
await doWork() // some long image processing | ||
await statusMessage.delete() // so easy! | ||
}) | ||
bot.on('callback_query', async ctx => { | ||
await ctx.callbackQuery.answer() // this works now, too | ||
}) | ||
bot.on(":photo", async (ctx) => { | ||
const statusMessage = await ctx.reply("Processing your image, please wait"); | ||
await doWork(); // some long image processing | ||
await statusMessage.delete(); // so easy! | ||
}); | ||
bot.on("callback_query", async (ctx) => { | ||
await ctx.callbackQuery.answer(); // this works now, too | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
40682
29
730