@@ -23,7 +23,7 @@ export type SendMenuToChatFunction<Context> = (chatId: string | number, context:
23
23
* Method which is able to edit a message in a chat into a menu.
24
24
* Generated via `generateEditMessageIntoMenuFunction`.
25
25
*/
26
- export type EditMessageIntoMenuFunction < Context > = ( chatId : number | string , messageId : number , context : Context , extra ?: Readonly < ExtraEditMessageText | ExtraEditMessageMedia > ) => Promise < Message | boolean >
26
+ export type EditMessageIntoMenuFunction < Context > = ( chatId : number | string , messageId : number , context : Context , extra ?: Readonly < ExtraEditMessageText | ExtraEditMessageMedia > ) => Promise < Message | true >
27
27
28
28
/**
29
29
* Reply a menu to a context as a new message
@@ -46,15 +46,14 @@ export async function replyMenuToContext<Context extends TelegrafContext>(menu:
46
46
* @param path path of the menu
47
47
* @param extra optional additional Telegraf Extra options
48
48
*/
49
- export async function editMenuOnContext < Context extends TelegrafContext > ( menu : MenuLike < Context > , context : Context , path : string , extra : Readonly < ExtraEditMessageText | ExtraEditMessageMedia > = { } ) : Promise < void > {
49
+ export async function editMenuOnContext < Context extends TelegrafContext > ( menu : MenuLike < Context > , context : Context , path : string , extra : Readonly < ExtraEditMessageText | ExtraEditMessageMedia > = { } ) : Promise < Message | boolean > {
50
50
ensurePathMenu ( path )
51
51
const body = await menu . renderBody ( context , path )
52
52
const keyboard = await menu . renderKeyboard ( context , path )
53
53
54
54
const message = context . callbackQuery ?. message
55
55
if ( ! message ) {
56
- await replyRenderedMenuPartsToContext ( body , keyboard , context , extra )
57
- return
56
+ return replyRenderedMenuPartsToContext ( body , keyboard , context , extra )
58
57
}
59
58
60
59
if ( isMediaBody ( body ) ) {
@@ -66,28 +65,27 @@ export async function editMenuOnContext<Context extends TelegrafContext>(menu: M
66
65
parse_mode : body . parse_mode
67
66
}
68
67
69
- await context . editMessageMedia ( media , createEditMediaExtra ( keyboard , extra ) )
68
+ return context . editMessageMedia ( media , createEditMediaExtra ( keyboard , extra ) )
70
69
. catch ( catchMessageNotModified )
71
- return
72
70
}
73
71
} else if ( isLocationBody ( body ) || isVenueBody ( body ) ) {
74
72
// Dont edit the message, just recreate it.
75
73
} else if ( isTextBody ( body ) ) {
76
74
const text = getBodyText ( body )
77
75
if ( 'text' in message ) {
78
- await context . editMessageText ( text , createTextExtra ( body , keyboard , extra ) )
76
+ return context . editMessageText ( text , createTextExtra ( body , keyboard , extra ) )
79
77
. catch ( catchMessageNotModified )
80
- return
81
78
}
82
79
} else {
83
80
throw new TypeError ( 'The body has to be a string or an object containing text or media. Check the telegraf-inline-menu Documentation.' )
84
81
}
85
82
86
83
// The current menu is incompatible: delete and reply new one
87
- await Promise . all ( [
84
+ const [ repliedMessage ] = await Promise . all ( [
88
85
replyRenderedMenuPartsToContext ( body , keyboard , context , extra ) ,
89
86
deleteMenuFromContext ( context )
90
87
] )
88
+ return repliedMessage
91
89
}
92
90
93
91
/**
@@ -118,10 +116,10 @@ export async function resendMenuToContext<Context extends TelegrafContext>(menu:
118
116
return menuMessage
119
117
}
120
118
121
- function catchMessageNotModified ( error : unknown ) : void {
119
+ function catchMessageNotModified ( error : unknown ) : false {
122
120
if ( error instanceof Error && error . message . includes ( 'message is not modified' ) ) {
123
121
// ignore
124
- return
122
+ return false
125
123
}
126
124
127
125
throw error
0 commit comments