-
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:8787We can ignore the warnings above.
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!

Seems to be working fine! 😄
We can now close the ngrok tunnel and the wrangler dev server, let's start deploying our bot on cloudflare workers! 😄
⚠️ Make sure you have a Cloudflare account before proceeding further.
-
Logging in with wrangler CLI:
wrangler loginFollow the login steps to login into your Cloudflare account.
-
Rename the
namevar inwrangler.tomlatline 1to your preferred worker's name. Here I renamed it tosamplebot -
Deploy / Publish the worker:
wrangler deploy- Here is the message after deployment was successful:
Your worker has access to the following bindings: - Vars: - REPO_VERSION: "1.0.0" - BOT_TOKEN: "629xxxxxxx:AAH-c9Kxxxxxxxxxxxx..." - WEBHOOK_URL: "https://28f0xx-xx-xxx-xxx.ngrok-free...." - SECRET_TOKEN: "npnsqxxxxxxxxxxxxxxxxxxxRgR..." - DROP_PENDING_UPDATES: "True" Total Upload: 15.13 KiB / gzip: 2.65 KiB Uploaded samplebot (2.74 sec) Published samplebot (8.30 sec) https://samplebot.subdomain.workers.dev Current Deployment ID: 99xxxxxx0a-41xxx4-4xxd-axxd-92xxxxx60
- Here is the message after deployment was successful:
-
Updating the
WEBHOOK_URLthrough Cloudflare Dashboard:- Goto your CF (Cloudflare) Dashboard and go to
Workers & Pages / Overview / samplebot. - Now open your worker and goto the
Settingstab, and click on theTriggerstab, and underRoutescategory you'll see your workers address, copy that. - Now, on the
Settingstab, and click on theVariablestab to access the ENV Variables. - Click on
Edit Variables, and replace theWEBHOOK_URLwith the workers address that you just copied, with the endpoint as/bot, that'd behttps://samplebot.yoursubdomain.workers.dev/bot
⚠️ The/botendpoint is necessary on theWEBHOOK_URLvar.- Now again, send a
POSTrequest to the/set-webhookendpoint of the workers address, that'd behttps://samplebot.yoursubdomain.workers.dev/set-webhook
- Goto your CF (Cloudflare) Dashboard and go to
AND ....... 👍🏻 All Done!!!
You've successfully deployed your first serverless bot on Cloudflare workers written with flaregram!
Have a nice day ahead! 😄