Skip to content

6. Testing And Deployment

Aditya Sharma edited this page May 7, 2024 · 3 revisions

🧪 Testing the Bot (locally):

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 CLI and Ngrok are a must! you can check the Prerequisites Page for Installation.

Moving up...

🕸️ Spinning up the local tunnel:

  • Let's startup a local tunnel using ngrok first:
  • 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 Forwarding aka 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 the WEBHOOK_URL env variable with the endpoint as /bot. That would be https://12f3-12-12-12-123.ngrok-free.app/bot and save the file.

✈ Starting up the local development server:

  • We will use wrangler dev command to spin up the local dev server on 127.0.0.1:8787
  • Upon using wrangler dev we 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:8787

🔧 Setting up the Webhook:

Now 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!

image

Seems to be working fine! 😄

Clone this wiki locally