-
Notifications
You must be signed in to change notification settings - Fork 18
6. Testing And Deployment
Now that we have made index.js and start_cmd.js, and also set up wrangler.toml with correct credentials, it's time to test the bot locally for any error or bugs! We'll need wrangler CLI and ngrok (https://ngrok.io) in this step, so make sure you have everything installed!
NOTE:
Wrangler CLIandNgrokare a must! you can check the Prerequisites Page for Installation.
Moving up...
- Let's startup a local tunnel using
ngrokfirst: - On the cmd/shell/ps, use
ngrok http http://127.0.0.1:8787/, On successful tunnel we'll get the following message:
ngrok
Session Status online
Account xxxxxx@gmail.com (Plan: Free)
Version 3.9.0
Region xxxx (in)
Latency 42ms
Web Interface http://127.0.0.1:4040
Forwarding https://12f3-12-12-12-123.ngrok-free.app -> http://127.0.0.1:8787/
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00 - Now copy the
Forwardingaka our newly made Webhook URL, which in my case is,https://12f3-12-12-12-123.ngrok-free.app - Now paste the URL in
wrangler.toml, in theWEBHOOK_URLenv variable with the endpoint as/bot. That would behttps://12f3-12-12-12-123.ngrok-free.app/botand save the file.
- We will use
wrangler devcommand to spin up the local dev server on127.0.0.1:8787 - Upon using
wrangler devwe will see the following message on our console as a successful local run!
⛅️ wrangler 3.30.1 (update available 3.53.1)
-------------------------------------------------------
▲ [WARNING] The entrypoint src\index.js ....
Your worker has access to the following bindings:
- Vars:
- REPO_VERSION: "1.0.0"
- BOT_TOKEN: "6292xxxxxxxx:AAH-cxKixvJOnzxxxxxxx..."
- WEBHOOK_URL: "https://12f3-12-12-12-123.ngrok-fr..."
- SECRET_TOKEN: "npnsqBxxxxxxxxxxxxxxxxxxDR0sRgR..."
- DROP_PENDING_UPDATES: "True"
⎔ Starting local server...
[wrangler:inf] Ready on http://127.0.0.1:8787Now that we have our local tunnel and local dev server up and running! It's time to set the Webhook URL at the telegram. For this just send a POST request through Postman or thunder client (vs code) to the URL https://12f3-12-12-12-123.ngrok-free.app/set-webhook. And the server would return,
Webhook was set
After everything's Done! time to message our brand new bot!

Seems to be working fine! 😄