File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,11 @@ import { isSome } from '../types/option';
77export default async ( ctx : MContext , next : Next ) => {
88 let id : number ;
99 switch ( ctx . updateType ) {
10- case 'message' :
11- id = ctx . message . chat . id ;
12- break ;
1310 case 'callback_query' :
1411 id = ctx . callbackQuery . from . id ;
1512 break ;
13+ default :
14+ id = ctx . chat . id ;
1615 }
1716 const user = await getUserById ( id ) ;
1817 if ( isSome ( user ) ) ctx . state . lang = user . value . lang ;
Original file line number Diff line number Diff line change 1- export const messageCtx = {
1+ const messageCtx : any = {
22 state : { } , // wait for data
33 updateType : 'message' ,
44 updateSubTypes : [ 'text' ] ,
@@ -48,3 +48,20 @@ export const messageCtx = {
4848 text : 'Processing, please wait for a while'
4949 } )
5050} ;
51+
52+ // https://github.com/telegraf/telegraf/blob/master/context.js#L123
53+ Object . defineProperty ( messageCtx , 'chat' , {
54+ get ( ) : any {
55+ return (
56+ ( messageCtx . message && messageCtx . message . chat ) ||
57+ ( messageCtx . editedMessage && messageCtx . editedMessage . chat ) ||
58+ ( messageCtx . callbackQuery &&
59+ messageCtx . callbackQuery . message &&
60+ messageCtx . callbackQuery . message . chat ) ||
61+ ( messageCtx . channelPost && messageCtx . channelPost . chat ) ||
62+ ( messageCtx . editedChannelPost && messageCtx . editedChannelPost . chat )
63+ ) ;
64+ }
65+ } ) ;
66+
67+ export { messageCtx } ;
You can’t perform that action at this time.
0 commit comments