@@ -23,7 +23,8 @@ const WEBHOOK = Config.bot.webHook
23
23
const SECRET = Config . bot . secret ;
24
24
25
25
const TlgBot = new Telegram ( Config . bot . token ) ;
26
- const env = typeof env !== 'undefined' && env ? env : "development" ;
26
+ const env = typeof env !== 'undefined' && env ? env : "production" ;
27
+ const enableLog = typeof enableLog !== 'undefined' ? enableLog : false ;
27
28
const Logger = ! enableLog || env === 'production' ? console : TlgBot ;
28
29
29
30
@@ -76,7 +77,7 @@ addEventListener('fetch', async event => {
76
77
case WEBHOOK :
77
78
event . respondWith ( handleWebhook ( event ) )
78
79
break ;
79
- case '/registerWebhook ' :
80
+ case '/webhook ' :
80
81
event . respondWith ( registerWebhook ( event , url , WEBHOOK , SECRET ) )
81
82
break ;
82
83
case '/unRegisterWebhook' :
@@ -139,7 +140,7 @@ async function onUpdate(update) {
139
140
}
140
141
141
142
async function check ( event ) {
142
- let vars = `YOUR VARIABLES:
143
+ let vars = `CHECKING YOUR VARIABLES...
143
144
144
145
adminId: ${ typeof adminId !== 'undefined' && adminId ? '✅ OK' : '❌ NOT OK' } ,
145
146
tlgSupport: ${ typeof tlgSupport !== 'undefined' && tlgSupport ? '✅ OK' : '❌ NOT OK' } ,
@@ -158,6 +159,7 @@ async function registerWebhook(event, requestUrl, suffix, secret) {
158
159
// https://core.telegram.org/bots/api#setwebhook
159
160
const webhookUrl = `${ requestUrl . protocol } //${ requestUrl . hostname } ${ suffix } `
160
161
const r = await ( await fetch ( TlgBot . apiUrl ( 'setWebhook' , { url : webhookUrl , secret_token : secret } ) ) ) . json ( )
162
+
161
163
return new Response ( 'ok' in r && r . ok ? 'Ok' : JSON . stringify ( r , null , 2 ) )
162
164
}
163
165
@@ -167,6 +169,7 @@ async function registerWebhook(event, requestUrl, suffix, secret) {
167
169
*/
168
170
async function unRegisterWebhook ( event ) {
169
171
const r = await ( await fetch ( TlgBot . apiUrl ( 'setWebhook' , { url : '' } ) ) ) . json ( )
172
+
170
173
return new Response ( 'ok' in r && r . ok ? 'Ok' : JSON . stringify ( r , null , 2 ) )
171
174
}
172
175
0 commit comments