UNPKG

vvlad1973-telegram-framework

Version:
206 lines (142 loc) 5.93 kB
'use strict' export class CallbackQuery { constructor(data, botInstance) { if (data?.id) { this.sender = botInstance; Object.assign(this, data); } else return undefined; } answer(options) { return this.sender.answerCallbackQuery(this.id, options); } answerMessage(text, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendMessage(chatId, text, options); } replyMessage(text, options = {}) { this.sender.answerCallbackQuery(this.id); options['reply_to_message_id'] = this.message.message_id; let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendMessage(chatId, text, options); } answerPhoto(photo, caption, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendPhoto(this.chatId, photo, caption, options = {}); } answerDice(options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendDice(chatId, options); } delete() { return this.sender.deleteMessage(this.message.chat.id, this.message.message_id); } pin(options) { this.sender.answerCallbackQuery(this.id); return this.sender.pinChatMessage(this.message.chat.id, this.message.message_id, options); } unpin() { this.sender.answerCallbackQuery(this.id); return this.sender.unpinChatMessage(this.message.chat.id, this.message.message_id); } unpinAllChatMessages() { this.sender.answerCallbackQuery(this.id); return this.sender.unpinAllChatMessages(this.message.chat.id); } editText(text, options = {}) { this.sender.answerCallbackQuery(this.id); options['chat_id'] = this.message.chat.id; options['message_id'] = this.message.message_id; if (options.preserve_reply_markup) { if (this.message?.reply_markup) options['reply_markup'] = this.message.reply_markup; delete options.preserve_reply_markup; } if (this.message?.text && this.message?.text !== text) { if (options.caption_entity) { options['entity'] = options['caption_entity']; delete options['caption_entity']; } return this.sender.editMessageText(text, options); } else if (this.message?.caption && this.message?.caption !== text) { if (options.entity) { options['caption_entity'] = options['entity']; delete options['entity']; } return this.sender.editMessageCaption(text, options); } else return Promise.resolve(false); } editReplyMarkup(options = {}) { this.sender.answerCallbackQuery(this.id); options['chat_id'] = this.message.chat.id; options['message_id'] = this.message.message_id; if (options['reply_markup'] !== this.message.reply_markup) return this.sender.editMessageReplyMarkup(options) else return false; } editMedia(media, options = {}) { this.sender.answerCallbackQuery(this.id); if ( this.message?.audio || this.message?.video || this.message?.photo || this.message?.document ) { options['chat_id'] = this.message.chat.id; options['message_id'] = this.message.message_id; if (options.preserve_reply_markup) { if (this.message?.reply_markup) options['reply_markup'] = this.message.reply_markup; delete options.preserve_reply_markup; } return this.sender.editMessageMedia(media, options); } else return Promise.resolve(false); } answerVideo(video, caption, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendVideo(chatId, video, caption, options); } answerContact(phoneNumber, firstName, lastName, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendContact( chatId, phoneNumber, firstName, lastName, options ); } answerAudio(audio, caption, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendAudio(chatId, audio, caption, options); } answerVoice(voice, caption, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendVoice(chatId, voice, caption, options); } answerDocument(document, caption, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendDocument(chatId, document, caption, options); } answerAnimation(animation, caption, options) { this.sender.answerCallbackQuery(this.id); let chatId = options?.private ? this.from.id : this.message.chat.id; return this.sender.sendAnimation(chatId, animation, caption, options); } answerChatAction(action) { this.sender.answerCallbackQuery(this.id); return this.sender.sendChatAction(this.message.chat.id, action); } forward(chatId, options) { this.sender.answerCallbackQuery(this.id); return this.sender.forwardMessage(chatId, this.message.chat.id, this.message.message_id, options); } copy(chatId, options) { this.sender.answerCallbackQuery(this.id); return this.sender.copyMessage(chatId, this.message.chat.id, this.message.message_id, options); } } export default CallbackQuery;