grammy-edit-or-reply
Version:
Exports utilities for grammy to edit a message or reply to a message based on the context
115 lines (114 loc) • 4.58 kB
TypeScript
import { Api } from 'grammy';
import { Animation, Audio, Document, InlineKeyboardButton, InputFile, LinkPreviewOptions, MessageEntity, ParseMode, PhotoSize, ReplyParameters, Video, InlineQueryResultArticle, InlineQueryResultCachedDocument, InlineQueryResultCachedPhoto, InlineQueryResultCachedVideo, InlineQueryResultCachedGif } from 'grammy/types';
export type Other = {
keyboard?: InlineKeyboardButton[][];
parse_mode?: ParseMode;
entities?: MessageEntity[];
link_preview_options?: LinkPreviewOptions;
disable_notification?: boolean;
protect_content?: boolean;
message_thread_id?: number;
business_connection_id?: string;
has_spoiler?: boolean;
reply_parameters?: ReplyParameters;
message_effect_id?: string;
show_caption_above_media?: boolean;
allow_paid_broadcast?: boolean;
};
export type TelegramOther = {
reply_markup?: {
inline_keyboard: InlineKeyboardButton[][];
};
parse_mode?: ParseMode;
entities?: MessageEntity[];
link_preview_options?: LinkPreviewOptions;
disable_notification?: boolean;
protect_content?: boolean;
message_thread_id?: number;
business_connection_id?: string;
has_spoiler?: boolean;
reply_parameters?: ReplyParameters;
message_effect_id?: string;
show_caption_above_media?: boolean;
allow_paid_broadcast?: boolean;
caption?: string;
caption_entities?: MessageEntity[];
};
export type MessageMediaInfo = {
type: 'photo';
media: PhotoSize;
sizes: PhotoSize[];
fileId: string;
} | {
type: 'animation';
media: Animation;
fileId: string;
} | {
type: 'audio';
media: Audio;
fileId: string;
} | {
type: 'document';
media: Document;
fileId: string;
} | {
type: 'video';
media: Video;
fileId: string;
};
export type MediaType = MessageMediaInfo['type'];
export type MessageDataMedia = {
text?: string;
media: {
type: MediaType;
media: InputFile | string;
};
} & Other;
export type MessageDataText = {
text: string;
} & Other;
export type MessageData = MessageDataMedia | MessageDataText;
export declare function messageDataHasMedia(messageData: MessageData): messageData is MessageDataMedia;
/**
* Checks that the message data has no input file.
* This is required for `makeInlineResult`.
*/
export declare function messageDataHasNoInputFile(messageData: MessageData): messageData is MessageDataText | (MessageDataMedia & {
media: {
media: string;
};
});
export type OldMessageInfoChatMessage = {
hasMedia: boolean;
chatId: number;
messageId: number;
};
export type OldMessageInfoChat = {
chatId: number;
};
export type OldMessageInfoInline = {
hasMedia: boolean;
inlineMessageId: string;
};
export type OldMessageInfo = OldMessageInfoChat | OldMessageInfoInline | OldMessageInfoChatMessage;
export declare function oldMessageIsInline(oldMessageInfo: OldMessageInfo): oldMessageInfo is OldMessageInfoInline;
export declare function oldMessageIsChatMessage(oldMessageInfo: OldMessageInfo): oldMessageInfo is OldMessageInfoChatMessage;
export declare function oldMessageIsChat(oldMessageInfo: OldMessageInfo): oldMessageInfo is OldMessageInfoChat;
export type SendMediaResult = Awaited<ReturnType<Api['sendPhoto' | 'sendAnimation' | 'sendAudio' | 'sendDocument' | 'sendVideo']>>;
export type EditOrReplyResult = SendMediaResult | Awaited<ReturnType<Api['editMessageMediaInline' | 'editMessageCaptionInline' | 'editMessageTextInline' | 'editMessageMedia' | 'editMessageText' | 'sendMessage']>>;
type DistributiveOmit<T, K extends string | number | symbol> = T extends unknown ? Omit<T, K> : never;
export type MakeInlineResultReturn = DistributiveOmit<InlineQueryResultArticle | InlineQueryResultCachedDocument | InlineQueryResultCachedPhoto | InlineQueryResultCachedVideo | InlineQueryResultCachedGif, 'id' | 'title'>;
export type EditOrReplyFlavor = {
/**
* Edits or sends a message to the current chat. The data of the current
* message is obtained through `getMessageInfo`. If the message is inaccessible
* or the update is a callback on an inline message it will make an
* optimistic guess that the edit will succeed (i.e. the old message has a
* media if the new one also does, same for the converse).
*
* You can pass the oldMessageInfo if you have it.
*/
editOrReply: (messageData: MessageData, oldMessageInfo?: OldMessageInfo) => Promise<EditOrReplyResult>;
getMessageInfo: (guessedHasMedia?: boolean) => OldMessageInfo;
};
export {};