Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    ‘There was a conversation’: Vita Coco rides out TikTok U.S. uncertainty with its safety nets built

    From vibes to data: Why some brands use predictive tech to vet creators

    In Graphic Detail: Why TikTok still faces an uphill battle in the U.S.

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      AI, crypto and Trump super PACs stash millions to spend on the midterms

      February 2, 2026

      To avoid accusations of AI cheating, college students are turning to AI

      January 29, 2026

      ChatGPT can embrace authoritarian ideas after just one prompt, researchers say

      January 24, 2026

      Ashley St. Clair, the mother of one of Elon Musk’s children, sues xAI over Grok sexual images

      January 17, 2026

      Anthropic joins OpenAI’s push into health care with new Claude tools

      January 12, 2026
    • Business

      New VoidLink malware framework targets Linux cloud servers

      January 14, 2026

      Nvidia Rubin’s rack-scale encryption signals a turning point for enterprise AI security

      January 13, 2026

      How KPMG is redefining the future of SAP consulting on a global scale

      January 10, 2026

      Top 10 cloud computing stories of 2025

      December 22, 2025

      Saudia Arabia’s STC commits to five-year network upgrade programme with Ericsson

      December 18, 2025
    • Crypto

      Ethereum Price Is 10% From Falling Below $2,000, but There’s a Silver Lining to it

      February 2, 2026

      Not Tom Lee’s BitMine: This Firm Faces Potential $1.33 Billion ETH Liquidation Amid 26% Price Drop

      February 2, 2026

      ZOOMEX Introduces February XAUT Initiative Aimed at Simplifying Platform Access

      February 2, 2026

      Tether Dominance Signals the Market May Not Have Found a Bottom Yet

      February 2, 2026

      Ripple Releases 1 Billion XRP as Price Weakness Extends Into February

      February 2, 2026
    • Technology

      ‘There was a conversation’: Vita Coco rides out TikTok U.S. uncertainty with its safety nets built

      February 2, 2026

      From vibes to data: Why some brands use predictive tech to vet creators

      February 2, 2026

      In Graphic Detail: Why TikTok still faces an uphill battle in the U.S.

      February 2, 2026

      Media Buying Briefing: Marketers are wary of civil unrest at this year’s World Cup

      February 2, 2026

      P&G bets big on retail integration as CPGs question incrementality

      February 2, 2026
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Building a Telegram Bot with Cloudflare Workers, Durable Objects and Grammy
    Technology

    Building a Telegram Bot with Cloudflare Workers, Durable Objects and Grammy

    TechAiVerseBy TechAiVerseFebruary 2, 2026No Comments5 Mins Read2 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Building a Telegram Bot with Cloudflare Workers, Durable Objects and Grammy
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Building a Telegram Bot with Cloudflare Workers, Durable Objects and Grammy

    1. Background
    2. Has to be a new tech stack and low friction to use
    3. Some more new things
    4. Things I learned
      1. Setting webhook URL
      2. Bot not responding to messages
      3. Commands can be registered dynamically
      4. Not everything has to be AI
    5. Conclusion

    Background

    Last month I visited my friend for a week or so who mentioned I drink way less water and he showed me the reading on his water purifier. On average, I drank like 1L of water.

    I then started keeping track of how much water I drank, but then I used to miss a couple of days. So I thought, why not create an app to track this and also remind myself to drink water.

    I present to you Drinky which does just that. If you’re interested, the GitHub repo is here. This blog post will go into why I went via the bot route, the tech stack I chose and the things I learned.

    Has to be a new tech stack and low friction to use

    I didn’t want to develop another web app in which I had to log in to. I thought of creating an Android app and to store the data locally but it would have been overkill and it would also be a hassle if I wanted to share it with somebody. I had already built a Telegram bot to notify when your Blender render is completed (Render Notifier) and I knew the Telegram API was also pretty nice to work with. This would also allow me to share the bot with anyone. So there it was. Telegram bot.

    I was tired of using D1 due to its cold start time and drizzle not supporting its sessions API. Since I wanted to deploy everything to Cloudflare, I thought why not use Durable Objects? I had used it a while back to write a blog post, but not in a product as such and each user gets their own DB and since there won’t be any external DB calls as such, the latency between data fetching, updating, etc would be close to 0ms. So I chose DO for my database.

    The last remaining part was which TS library to use to interact with Telegram API. I had read about telegraf.js somewhere so I checked it out, but it was not actively maintained. After searching for a bit, I went with grammY due to extensive documentation and it being actively maintained.

    Some more new things

    Some more new libs which I have used are:

    • oxc – for linting and formatting
    • Vitest – for testing
    • AGENTS.md – for Gemini CLI
    • drizzle (beta version) – for ORM

    Things I learned

    Setting webhook URL

    Seemed pretty basic in hindsight, but no matter what, I was unable to listen to the messages sent to the bot. Added to the fact that I was using wrangler to develop locally (since I would be deploying to Cloudflare Workers), I was not sure what I was doing wrong. I eventually found out I had to set the webhook like so https://api.telegram.org/bot/setWebhook?url=. This would tell the bot to forward the messages to the webhook URL. To expose my localhost to the public internet, I used Cloudflare Tunnel.

    Bot not responding to messages

    I was now able to see the messages, but I was not able to respond to them. I regrettably had to ask Cursor to fix this to which it spat out below code.

    app.post("/webhook", async (c) => {
        const update = await c.req.json();
    
        const bot = await setupBot({
            token: c.env.BOT_TOKEN,
            env: c.env,
            commands,
            callbacks,
        });
    
        await bot.handleUpdate(update);
    
        return c.json({ ok: true });
    });

    await bot.handleUpdate(update); is used to pass the updates to the bot instance. Apparently, this is needed in a serverless env where everything is stateless. Adding this fixed the issue

    Commands can be registered dynamically

    Initially I was under the impression that BotFather has to be used to update any commands which the bot can show to the user. But turns out you can set them via the API as well.

    app.post("/webhook", async (c) => {
        const update = await c.req.json();
    
        const bot = await setupBot({
          token: c.env.BOT_TOKEN,
          env: c.env,
          commands,
          callbacks,
        });
    
        await bot.api.setMyCommands(
          commands.map((command) => ({
            command: command.name,
            description: command.description,
          })),
        );
    
        // This is required for grammy to work in Cloudflare Workers. Also, this has to go after the commands are registered.
        await bot.handleUpdate(update);
    
        return c.json({ ok: true });
    });

    As you can see, the handleUpdate method needs to be called after the commands are set. Otherwise, the data is not passed along.

    Not everything has to be AI

    There came a point where I had to have timezone identification in the bot. My first thought was to ask user where they’re located, send it to an LLM and then get the timezone in IANA format. Instead, I now ask the user for their location via Telegram’s API, send their lat and long to tz-lookup and get the timezone. I’m glad I did not go via the AI route and I’m ashamed I did not think of the tz-lookup solution first.

    Conclusion

    All in all, it was a lot of fun building this bot. I learned a lot and also solved my problem rather elegantly if I say so myself.

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleEthereum Price Is 10% From Falling Below $2,000, but There’s a Silver Lining to it
    Next Article Apple’s MacBook Pro DFU port documentation is wrong
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    ‘There was a conversation’: Vita Coco rides out TikTok U.S. uncertainty with its safety nets built

    February 2, 2026

    From vibes to data: Why some brands use predictive tech to vet creators

    February 2, 2026

    In Graphic Detail: Why TikTok still faces an uphill battle in the U.S.

    February 2, 2026
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025648 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025242 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 2025144 Views

    6 Best MagSafe Phone Grips (2025), Tested and Reviewed

    April 6, 2025111 Views
    Don't Miss
    Technology February 2, 2026

    ‘There was a conversation’: Vita Coco rides out TikTok U.S. uncertainty with its safety nets built

    ‘There was a conversation’: Vita Coco rides out TikTok U.S. uncertainty with its safety nets…

    From vibes to data: Why some brands use predictive tech to vet creators

    In Graphic Detail: Why TikTok still faces an uphill battle in the U.S.

    Media Buying Briefing: Marketers are wary of civil unrest at this year’s World Cup

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    ‘There was a conversation’: Vita Coco rides out TikTok U.S. uncertainty with its safety nets built

    February 2, 20262 Views

    From vibes to data: Why some brands use predictive tech to vet creators

    February 2, 20263 Views

    In Graphic Detail: Why TikTok still faces an uphill battle in the U.S.

    February 2, 20264 Views
    Most Popular

    A Team of Female Founders Is Launching Cloud Security Tech That Could Overhaul AI Protection

    March 12, 20250 Views

    7 Best Kids Bikes (2025): Mountain, Balance, Pedal, Coaster

    March 13, 20250 Views

    VTOMAN FlashSpeed 1500: Plenty Of Power For All Your Gear

    March 13, 20250 Views
    © 2026 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.