1
+ var debug = require ( 'debug' ) ( 'monkey-patches:node-telegram-bot-api' ) ;
2
+
3
+ function patchStopPolling ( TelegramBot ) {
4
+ TelegramBot . prototype . stopPolling = function ( ) {
5
+ if ( this . _polling ) {
6
+ this . _polling . abort = true ;
7
+ this . _polling . lastRequest . cancel ( 'Stop polling' ) ;
8
+ }
9
+ this . _polling = null ;
10
+ }
11
+ }
12
+
13
+ function patchEmitUpdate ( TelegramBot ) {
14
+ var _processUpdate = TelegramBot . prototype . _processUpdate ;
15
+ TelegramBot . prototype . _processUpdate = function ( update ) {
16
+ debug ( 'Process Update %j' , update ) ;
17
+ this . emit ( 'update' , update ) ;
18
+ _processUpdate . call ( this , update ) ;
19
+ }
20
+ }
21
+
22
+ function patchEmitCallbackQuery ( TelegramBot ) {
23
+ var _processUpdate = TelegramBot . prototype . _processUpdate ;
24
+ TelegramBot . prototype . _processUpdate = function ( update ) {
25
+ _processUpdate . call ( this , update ) ;
26
+ var callbackQuery = update . callback_query ;
27
+ if ( callbackQuery ) {
28
+ debug ( 'Process Update callback_query %j' , callbackQuery ) ;
29
+ this . emit ( 'callback_query' , callbackQuery ) ;
30
+ }
31
+
32
+ }
33
+ }
34
+
35
+
36
+ module . exports = function ( TelegramBot , options ) {
37
+ options = options || { } ;
38
+ if ( options . stopPolling ) {
39
+ patchStopPolling ( TelegramBot ) ;
40
+ }
41
+ if ( options . emitUpdate ) {
42
+ patchEmitUpdate ( TelegramBot ) ;
43
+ }
44
+ if ( options . emitCallbackQuery ) {
45
+ patchEmitCallbackQuery ( TelegramBot ) ;
46
+ }
47
+ } ;
0 commit comments