1+ import { Update as TelegramUpdate , InlineQueryResult as TelegramInlineQueryResult , ParseMode } from '@grammyjs/types' ;
12import TelegramApi from './telegram_api.js' ;
23import TelegramBot from './telegram_bot.js' ;
3- import TelegramInlineQueryResultArticle from './types/TelegramInlineQueryResultArticle.js' ;
4- import TelegramInlineQueryResultPhoto from './types/TelegramInlineQueryResultPhoto.js' ;
5- import TelegramUpdate from './types/TelegramUpdate.js' ;
6- import TelegramInlineQueryResultVideo from './types/TelegramInlineQueryResultVideo.js' ;
7- import TelegramInlineQueryResultVoice from './types/TelegramInlineQueryResultVoice.js' ;
8- import TelegramInlineQueryResult from './types/TelegramInlineQueryResult.js' ;
4+
5+
6+
7+
8+
9+
910
1011/** Class representing the context of execution */
1112export default class TelegramExecutionContext {
@@ -54,7 +55,7 @@ export default class TelegramExecutionContext {
5455 * @returns The user ID or undefined if not available
5556 */
5657 get userId ( ) : number | undefined {
57- return this . update . message ?. from . id ?? this . update . business_message ?. from . id ?? this . update . guest_message ?. from . id ;
58+ return this . update . message ?. from ? .id ?? this . update . business_message ?. from ? .id ?? this . update . guest_message ?. from ? .id ;
5859 }
5960
6061 /**
@@ -163,7 +164,7 @@ export default class TelegramExecutionContext {
163164 ...options ,
164165 chat_id : this . getChatId ( ) ,
165166 message_thread_id : this . getThreadId ( ) ,
166- business_connection_id : this . update . business_message ?. business_connection_id . toString ( ) ?? '' ,
167+ business_connection_id : this . update . business_message ?. business_connection_id ? .toString ( ) ?? '' ,
167168 video,
168169 } ) ;
169170 case 'guest_message' :
@@ -172,7 +173,7 @@ export default class TelegramExecutionContext {
172173 return await this . api . answerInline ( this . bot . api . toString ( ) , {
173174 ...options ,
174175 inline_query_id : this . update . inline_query ?. id . toString ( ) ?? '' ,
175- results : [ new TelegramInlineQueryResultVideo ( { video } ) ] ,
176+ results : [ { type : 'video' , id : crypto . randomUUID ( ) , video_url : video , mime_type : 'video/mp4' , thumbnail_url : video , title : 'Video' } ] ,
176177 } ) ;
177178
178179 default :
@@ -214,7 +215,7 @@ export default class TelegramExecutionContext {
214215 ...options ,
215216 chat_id : this . getChatId ( ) ,
216217 message_thread_id : this . getThreadId ( ) ,
217- business_connection_id : this . update . business_message ?. business_connection_id . toString ( ) ?? '' ,
218+ business_connection_id : this . update . business_message ?. business_connection_id ? .toString ( ) ?? '' ,
218219 photo,
219220 caption,
220221 } ) ;
@@ -223,7 +224,7 @@ export default class TelegramExecutionContext {
223224 case 'inline' :
224225 return await this . api . answerInline ( this . bot . api . toString ( ) , {
225226 inline_query_id : this . update . inline_query ?. id . toString ( ) ?? '' ,
226- results : [ new TelegramInlineQueryResultPhoto ( { photo } ) ] ,
227+ results : [ { type : 'photo' , id : crypto . randomUUID ( ) , photo_url : photo , thumbnail_url : photo } ] ,
227228 } ) ;
228229
229230 default :
@@ -255,7 +256,7 @@ export default class TelegramExecutionContext {
255256 ...options ,
256257 chat_id : this . getChatId ( ) ,
257258 message_thread_id : this . getThreadId ( ) ,
258- business_connection_id : this . update . business_message ?. business_connection_id . toString ( ) ?? '' ,
259+ business_connection_id : this . update . business_message ?. business_connection_id ? .toString ( ) ?? '' ,
259260 voice,
260261 caption,
261262 } ) ;
@@ -283,7 +284,7 @@ export default class TelegramExecutionContext {
283284 } ) ;
284285 case 'business_message' :
285286 return await this . api . sendChatAction ( this . bot . api . toString ( ) , {
286- business_connection_id : this . update . business_message ?. business_connection_id . toString ( ) ?? '' ,
287+ business_connection_id : this . update . business_message ?. business_connection_id ? .toString ( ) ?? '' ,
287288 chat_id : this . getChatId ( ) ,
288289 message_thread_id : this . getThreadId ( ) ,
289290 action : 'typing' ,
@@ -304,7 +305,7 @@ export default class TelegramExecutionContext {
304305 if ( this . update_type === 'inline' ) {
305306 return await this . api . answerInline ( this . bot . api . toString ( ) , {
306307 inline_query_id : this . update . inline_query ?. id . toString ( ) ?? '' ,
307- results : [ new TelegramInlineQueryResultArticle ( { content : message , title , parse_mode } ) ] ,
308+ results : [ { type : 'article' , id : crypto . randomUUID ( ) , title : title ?? '' , input_message_content : { message_text : message , parse_mode : parse_mode as ParseMode } } ] ,
308309 } ) ;
309310 }
310311 return null ;
@@ -329,7 +330,7 @@ export default class TelegramExecutionContext {
329330 * @returns Promise with the API response
330331 */
331332 async answerGuestQueryText ( message : string , parse_mode = '' ) {
332- return await this . answerGuestQuery ( new TelegramInlineQueryResultArticle ( { content : message , title : 'Response' , parse_mode } ) ) ;
333+ return await this . answerGuestQuery ( { type : 'article' , id : crypto . randomUUID ( ) , title : 'Response' , input_message_content : { message_text : message , parse_mode : parse_mode as ParseMode } } ) ;
333334 }
334335
335336 /**
@@ -340,7 +341,7 @@ export default class TelegramExecutionContext {
340341 * @returns Promise with the API response
341342 */
342343 async answerGuestQueryPhoto ( photo : string , caption = '' , parse_mode = '' ) {
343- return await this . answerGuestQuery ( new TelegramInlineQueryResultPhoto ( { photo, caption, parse_mode } ) ) ;
344+ return await this . answerGuestQuery ( { type : 'photo' , id : crypto . randomUUID ( ) , photo_url : photo , thumbnail_url : photo , caption, parse_mode : parse_mode as ParseMode } ) ;
344345 }
345346
346347 /**
@@ -351,7 +352,7 @@ export default class TelegramExecutionContext {
351352 * @returns Promise with the API response
352353 */
353354 async answerGuestQueryVideo ( video : string , caption = '' , parse_mode = '' ) {
354- return await this . answerGuestQuery ( new TelegramInlineQueryResultVideo ( { video, caption, parse_mode } ) ) ;
355+ return await this . answerGuestQuery ( { type : 'video' , id : crypto . randomUUID ( ) , video_url : video , mime_type : 'video/mp4' , thumbnail_url : video , title : 'Video' , caption, parse_mode : parse_mode as ParseMode } ) ;
355356 }
356357
357358 /**
@@ -362,7 +363,7 @@ export default class TelegramExecutionContext {
362363 * @returns Promise with the API response
363364 */
364365 async answerGuestQueryVoice ( voice : string , caption = '' , parse_mode = '' ) {
365- return await this . answerGuestQuery ( new TelegramInlineQueryResultVoice ( { voice, caption, parse_mode } ) ) ;
366+ return await this . answerGuestQuery ( { type : 'voice' , id : crypto . randomUUID ( ) , voice_url : voice , title : 'Voice' , caption, parse_mode : parse_mode as ParseMode } ) ;
366367 }
367368
368369
@@ -384,7 +385,7 @@ export default class TelegramExecutionContext {
384385 options : Record < string , number | string | boolean | object > = { } ,
385386 ) {
386387 const message_id = this . drafts . get ( draft_id ) ;
387- const business_connection_id = this . update . business_message ?. business_connection_id . toString ( ) ;
388+ const business_connection_id = this . update . business_message ?. business_connection_id ? .toString ( ) ;
388389
389390 if ( message_id ) {
390391 return await this . api . editMessageText ( this . bot . api . toString ( ) , {
@@ -466,11 +467,11 @@ export default class TelegramExecutionContext {
466467 chat_id : this . getChatId ( ) ,
467468 message_thread_id : this . getThreadId ( ) ,
468469 text : message ,
469- business_connection_id : this . update . business_message ?. business_connection_id . toString ( ) ?? '' ,
470+ business_connection_id : this . update . business_message ?. business_connection_id ? .toString ( ) ?? '' ,
470471 parse_mode,
471472 } ) ;
472473 case 'callback' :
473- if ( this . update . callback_query ?. message . chat . id ) {
474+ if ( this . update . callback_query ?. message ? .chat . id ) {
474475 return await this . api . sendMessage ( this . bot . api . toString ( ) , {
475476 ...options ,
476477 chat_id : this . update . callback_query . message . chat . id . toString ( ) ,
@@ -499,7 +500,7 @@ export default class TelegramExecutionContext {
499500 return await this . api . sendInvoice ( this . bot . api . toString ( ) , {
500501 chat_id : this . getChatId ( ) ,
501502 message_thread_id : this . getThreadId ( ) ,
502- business_connection_id : this . update . business_message ?. business_connection_id . toString ( ) ,
503+ business_connection_id : this . update . business_message ?. business_connection_id ? .toString ( ) ,
503504 title,
504505 description,
505506 payload,
0 commit comments