Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit b3881d5

Browse files
author
zill
committed
Merge tag '1.1.8' into develop
v1.1.8-beta 1.1.8
2 parents 3e27880 + 43178e7 commit b3881d5

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ v2-xBot is multi panel, serverless (cloudflare worker) bot to order management &
2121

2222
# Get Started
2323
0) Create a cloudflare worker, KV namespace & bind to `db` variable
24-
1) Download [Latest Version](https://github.com/javadib/v2-xbot/releases/latest/download/dist.zip)
25-
2) Extract `dist.zip` and open `index.js` with suitable editor.
26-
3) Edit `bot section` with your variables (search `config.js` in file):
27-
- Replace `YOUR_BOT_NAME` with your bot name (Optional).
28-
- Replace `11111111` with your Telegram Admin ID.
29-
- Replace `@YOUR_SUPPORT_USERNAME` with your support Telegram username (Remember put `@` at the first).
30-
- Replace `YOUR_BOT_TOKEN` with your Telegram bot token.
31-
4) Replace whole codes with default cloudflare worker code.
24+
1) Got to worker settings, variable section, and add following variables:
25+
- `adminId` : your Telegram Admin ID (get from [MyIdInfoBot](https://t.me/Myidinfobot)).
26+
- `botToken` : your Telegram bot token.
27+
- `tlgSupport` : your support Telegram username (Remember put `@` at the first).
28+
3) Download [Latest Version](https://github.com/javadib/v2-xbot/releases/latest/download/dist.zip)
29+
4) Extract `dist.zip` and replace whole `index.js` codes with default cloudflare worker code.
30+
4) Open `YOUR_WORKER.worker.dev/check` to check all variables are `✅ OK`.
3231
5) Save and deploy worker and send a `GET ` request to `/registerWebhook` path to register webhook of your bot. make sure you see `ok` in response.
3332
#
3433
![1](./docs/images/register-result.png)
@@ -40,13 +39,6 @@ v2-xBot is multi panel, serverless (cloudflare worker) bot to order management &
4039

4140

4241

43-
# Custom Edition
44-
Under Development ...
45-
#
46-
47-
48-
49-
5042

5143
#
5244

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const config = {
77
},
88
bot: {
99
name: "V2xBot",
10-
adminId: adminId,
10+
adminId: Number(adminId),
1111
tlgSupport: tlgSupport,
1212
token: botToken,
1313
webHook: '/endpoint',

src/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const WEBHOOK = Config.bot.webHook
2323
const SECRET = Config.bot.secret;
2424

2525
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;
2728
const Logger = !enableLog || env === 'production' ? console : TlgBot;
2829

2930

@@ -76,7 +77,7 @@ addEventListener('fetch', async event => {
7677
case WEBHOOK:
7778
event.respondWith(handleWebhook(event))
7879
break;
79-
case '/registerWebhook':
80+
case '/webhook':
8081
event.respondWith(registerWebhook(event, url, WEBHOOK, SECRET))
8182
break;
8283
case '/unRegisterWebhook':
@@ -139,7 +140,7 @@ async function onUpdate(update) {
139140
}
140141

141142
async function check(event) {
142-
let vars = `YOUR VARIABLES:
143+
let vars = `CHECKING YOUR VARIABLES...
143144
144145
adminId: ${typeof adminId !== 'undefined' && adminId ? '✅ OK' : '❌ NOT OK'},
145146
tlgSupport: ${typeof tlgSupport !== 'undefined' && tlgSupport ? '✅ OK' : '❌ NOT OK'},
@@ -158,6 +159,7 @@ async function registerWebhook(event, requestUrl, suffix, secret) {
158159
// https://core.telegram.org/bots/api#setwebhook
159160
const webhookUrl = `${requestUrl.protocol}//${requestUrl.hostname}${suffix}`
160161
const r = await (await fetch(TlgBot.apiUrl('setWebhook', {url: webhookUrl, secret_token: secret}))).json()
162+
161163
return new Response('ok' in r && r.ok ? 'Ok' : JSON.stringify(r, null, 2))
162164
}
163165

@@ -167,6 +169,7 @@ async function registerWebhook(event, requestUrl, suffix, secret) {
167169
*/
168170
async function unRegisterWebhook(event) {
169171
const r = await (await fetch(TlgBot.apiUrl('setWebhook', {url: ''}))).json()
172+
170173
return new Response('ok' in r && r.ok ? 'Ok' : JSON.stringify(r, null, 2))
171174
}
172175

0 commit comments

Comments
 (0)