developer

Automating UPI Payments in WhatsApp and Telegram Bots

Learn how to integrate dynamic UPI payment links and QR codes into your Telegram and WhatsApp bots to monetize digital services and digital products.

VD VyaparGateway Developer Relations API Integration Specialists 7 min read
Automating UPI Payments in WhatsApp and Telegram Bots guide
WhatsApp Bot Payments Telegram Bot Payment Gateway UPI API Integration Conversational Commerce

Conversational commerce is exploding. Developers are building incredibly useful Telegram bots that provide AI image generation, premium trading signals, and automated research. Similarly, local businesses are using WhatsApp bots to take orders, share product catalogs, and book appointments.

But building a great bot is only half the battle. The real challenge is monetization. How do you present a payment option inside a chat without forcing the user out of the conversation into a clunky, multi-step checkout process?

Here is a practical guide to integrating UPI payment links and QR codes into WhatsApp and Telegram bots in 2026 — in a way that is clean, developer-friendly, and legally sound.

Compliance Disclaimer: Automated payment collection via bots may require compliance with RBI Payment Aggregator guidelines. If your bot receives money from customers and holds or pools those funds before disbursing to a merchant, that constitutes payment aggregation and requires an RBI Payment Aggregator (PA) license. The integration pattern described in this article routes payments directly from the customer to the merchant’s own bank account — no funds are held or pooled by VyaparGateway or the bot. Ensure your specific use case does not constitute payment aggregation without a license.

The Rise of Conversational Commerce

Users suffer from app fatigue. They do not want to download a dedicated app just to buy a niche digital product or access a premium service. They want to message a bot, get the service, pay instantly, and move on.

If you introduce friction — like asking them to manually copy a UPI ID, make the payment, take a screenshot, and upload the screenshot back to the chat for manual verification — you will lose a significant share of potential sales to abandonment.

The better approach is to generate a dynamic UPI intent link or a QR code from your server, send it directly into the chat, and confirm the payment via webhook as soon as the credit hits the merchant’s bank account. The user never leaves the chat experience in a meaningful way, and you never handle or hold their money.

How Payments Must Flow: Merchant-Direct Architecture

This is the most important concept to understand before writing a single line of code.

The bot is a customer-facing interface — it displays the UPI QR code or payment link, nothing more. When the customer scans the QR or taps the link, the UPI payment goes directly to the merchant’s registered bank account (via the merchant’s own VPA/UPI ID). The bot does not receive the money, hold it, or redistribute it.

Customer → taps UPI link in Telegram/WhatsApp
         → opens Google Pay / PhonePe / BHIM on their phone
         → pays merchant's UPI VPA directly
         → funds credited to merchant's bank account
         → gateway webhook fires to bot backend
         → bot delivers the product/service

This direct-to-merchant flow is what makes the integration legally clean for a merchant building their own bot. Your bot is simply a presentation layer for your own UPI payment address.

The Problem with Bot Monetization

Integrating a traditional Payment Aggregator into a bot is notoriously difficult for two reasons:

  1. The KYC Wall: Most payment aggregators require a live, fully-functional website with extensive legal policies to approve your account. If your entire customer-facing surface is a Telegram bot, you will likely be rejected or face a very long review process.
  2. Complexity overhead: Aggregator SDKs are built around redirect-based checkout pages — a model that does not map well to chat-native flows.

VyaparGateway solves both problems by connecting to your existing registered merchant UPI account (such as a PhonePe Business or Paytm for Business VPA) and generating dynamic links and QR codes against it, with no redirect page required.

The Webhook-Driven Payment Flow

The end-to-end flow from the user’s perspective looks like this:

  1. The user types /buy premium in the Telegram chat or sends a keyword in WhatsApp.
  2. Your bot backend calls the VyaparGateway API to create an order and receives a payment_url and optionally a QR code image.
  3. The bot sends the payment link as an inline button (Telegram) or as a message with a URL (WhatsApp), along with the exact amount and product description.
  4. The user taps the button on their phone. It opens Google Pay, PhonePe, or any UPI app with the amount and your merchant name pre-filled.
  5. The user authenticates with their UPI PIN. The payment goes directly to your merchant bank account.
  6. Within seconds, VyaparGateway detects the credit and fires a POST request to your webhook URL.
  7. Your server receives the webhook, verifies the signature, and instructs the bot to send the fulfillment message (download link, access code, confirmation, etc.) to the user.

Telegram Bot Payment Integration: Step-by-Step

Step 1: Set Up Your Bot Backend

Create a simple server (Node.js or Python) that handles both incoming Telegram webhook events and the outgoing VyaparGateway order creation.

// Node.js example using node-telegram-bot-api
const TelegramBot = require('node-telegram-bot-api');
const axios = require('axios');

const bot = new TelegramBot(process.env.TELEGRAM_TOKEN, { polling: true });

bot.onText(/\/buy (.+)/, async (msg, match) => {
  const chatId = msg.chat.id;
  const product = match[1];

  // Create an order via VyaparGateway
  const { data } = await axios.post('https://api.vyapargateway.com/api/v1/create_order', {
    key: process.env.VG_API_KEY,
    client_txn_id: `tg_${chatId}_${Date.now()}`,
    amount: 199,
    p_info: `Premium Bot Access - ${product}`,
    customer_name: msg.from.first_name,
    callback_url: 'https://your-server.com/webhook/vg',
  });

  if (data.status) {
    bot.sendMessage(chatId, `Pay ₹199 for *${product}*:`, {
      parse_mode: 'Markdown',
      reply_markup: {
        inline_keyboard: [[
          { text: '💳 Pay via UPI', url: data.data.payment_url }
        ]]
      }
    });
  }
});

Step 2: Send a QR Code for Desktop Users

For users who are on the Telegram desktop app and cannot tap a UPI deep link, generate and send a QR code image instead:

const QRCode = require('qrcode');

const qrBuffer = await QRCode.toBuffer(data.data.payment_url);
bot.sendPhoto(chatId, qrBuffer, {
  caption: 'Scan this QR with any UPI app to pay ₹199'
});

Step 3: Webhook Listener and Verification

const express = require('express');
const crypto = require('crypto');
const app = express();
app.use(express.json());

app.post('/webhook/vg', (req, res) => {
  const payload = req.body;

  // Verify the signature to ensure the request is from VyaparGateway
  const expectedSig = crypto
    .createHmac('sha256', process.env.VG_WEBHOOK_SECRET)
    .update(JSON.stringify(payload))
    .digest('hex');

  if (req.headers['x-vg-signature'] !== expectedSig) {
    return res.status(401).send('Invalid signature');
  }

  if (payload.status === 'success') {
    const txnId = payload.client_txn_id; // e.g. "tg_123456789_1720000000000"
    const chatId = txnId.split('_')[1];

    // Fulfill the order
    bot.sendMessage(chatId, '✅ Payment confirmed! Here is your premium access:\nhttps://your-service.com/access/...');
  }

  res.sendStatus(200);
});

WhatsApp Business API Payment Integration

WhatsApp does not support UPI deep links as tappable buttons in the same way Telegram does, but you can still build an effective flow using the WhatsApp Business API (Meta’s Cloud API or a BSP like Twilio, WATI, or Interakt).

Flow for WhatsApp

  1. The customer messages your WhatsApp number with a keyword (e.g., “Buy Plan A”).
  2. Your webhook receives the inbound message from the WhatsApp Business API.
  3. Your server calls VyaparGateway to create an order and gets back a payment_url.
  4. You send a reply message containing the UPI link as plain text or a clickable URL button using an interactive message template.
  5. Optionally, send the QR code as an image attachment for users on desktop WhatsApp or WhatsApp Web.
# Python example — sending a reply via Meta's WhatsApp Cloud API
import requests, os

def send_payment_link(to_number, payment_url, amount):
    payload = {
        "messaging_product": "whatsapp",
        "to": to_number,
        "type": "interactive",
        "interactive": {
            "type": "button",
            "body": {"text": f"Pay ₹{amount} via UPI to complete your order."},
            "action": {
                "buttons": [{
                    "type": "reply",
                    "reply": {"id": "pay_now", "title": "Open UPI Link"}
                }]
            }
        }
    }
    # Note: WhatsApp interactive buttons can't carry external URLs directly in some BSPs.
    # Send the URL as a separate text message or use a BSP that supports URL buttons.
    requests.post(
        f"https://graph.facebook.com/v19.0/{os.environ['WABA_PHONE_ID']}/messages",
        headers={"Authorization": f"Bearer {os.environ['META_TOKEN']}"},
        json=payload
    )

For BSPs that support external URL buttons (like WATI or Interakt), you can pass the payment_url directly as a CTA button, making the experience seamless.

Error Handling Patterns

Robust bots need to handle failure cases gracefully:

  • Payment timeout: Store the client_txn_id with a TTL (e.g., 15 minutes). If the webhook does not arrive within that window, send the user a follow-up: “Your payment link has expired. Type /buy again to get a new link.”
  • Duplicate webhook delivery: Webhooks can occasionally be delivered more than once. Always check if the client_txn_id has already been fulfilled before sending the product again.
  • Network errors on webhook receipt: Return HTTP 200 immediately upon receiving the webhook, then process asynchronously. Never let your fulfillment logic delay the HTTP response — the gateway may retry if it does not receive a 200.
  • User pays wrong amount: If you are using a static UPI QR (not a dynamic link), there is a risk of the user paying a different amount. Always prefer dynamic links generated per-order so the amount is locked in by the UPI app.

Implementing Bot Payments with VyaparGateway

To summarize the full technical blueprint:

Step 1: Create the Order

POST /api/v1/create_order
{
  "key": "your_vyapargateway_api_key",
  "client_txn_id": "tg_user_12345_order_9",
  "amount": 199,
  "p_info": "Premium Bot Access",
  "customer_name": "Rahul",
  "callback_url": "https://your-bot-backend.com/webhook"
}

Step 2: Send the Payment URL or QR to the Chat

VyaparGateway responds with a payment_url. Your bot sends this as an inline button (Telegram) or a message link (WhatsApp). For desktop users, render it as a QR code image.

Step 3: Receive and Verify the Webhook

Your /webhook endpoint receives a POST when the payment clears to your merchant bank account. Verify the signature, mark the order as fulfilled, and trigger the delivery message.

Step 4: Deliver and Log

Send the product, access link, or confirmation to the user. Log the transaction in your own database for reconciliation and support purposes.

Because VyaparGateway routes payments directly to your own connected merchant UPI account, no funds are intermediated, held, or pooled through the gateway or your bot. You connect your existing merchant VPA (PhonePe Business, Paytm for Business, etc.) during onboarding, and all payments credit directly to that account.

Start building your payment-enabled Telegram or WhatsApp bot today by integrating direct-to-merchant UPI payment links with VyaparGateway.

Direct answers

Frequently asked questions

Can I accept UPI payments directly inside a Telegram bot?
Yes. By calling a payment gateway API to generate a dynamic UPI link, you can send the link as an inline button in Telegram. When the user pays, a webhook confirms the payment and your bot can deliver the digital product.
Do I need a website to use a payment gateway for my bot?
Traditional aggregators usually require a live website for KYC approval. However, direct-to-bank UPI APIs like VyaparGateway allow you to connect your existing merchant QR and monetize bots without a complex website.
How does the bot know the user has paid?
You provide a webhook URL when creating the order. Once the payment hits your bank account, the gateway sends a POST request to your webhook URL, triggering your bot to fulfill the order.

Build your payment flow

Explore the API and browser-only merchant tools.

Create UPI checkout orders, verify signed events, or test the free calculators and generators without exposing credentials.