TDL Tutorial: Code a Send WhatsApp Button in TallyPrime

In brief

To code a Send WhatsApp button in TallyPrime, modify the voucher form with [#Form: Sales Color], add a button bound to Alt+J, export the voucher with EXPORT REPORT, then call an external program with Exec COM Interface. This walkthrough uses real code from the TallyWhatsApp TDL, plus the traps it hit.

TallyPrime sales voucher showing the J: Send WhatsApp and W: Send To buttons produced by the TDL code in this tutorial
The result of the code below: J: Send WhatsApp and W: Send To on the sales voucher button bar.

This is a code walkthrough for developers and Tally partners who already know what a TDL file is. Every snippet is trimmed from the shipping TallyWhatsApp TDL, so the syntax is proven in TallyPrime. If TDL is new to you, read our TallyPrime TDL basics guide first.

How does a Send WhatsApp button work in TDL?

The design has four parts. A COM Interface definition is a TDL declaration that names an external Windows class and its parameters, so TDL can call it. A form modification adds the button, a function gathers voucher data and exports the PDF, and one action hands everything to the external program.

Tally introduced the COM Interface definition and the Exec COM Interface action to let TDL act as a COM client, as described on its COM DLL support in TDL page. The external class does the WhatsApp work, because TDL itself cannot hold a network session.

Step 1: How do you declare the COM interface?

The declaration names the registered project and class, the method to call, and each parameter with its type and direction. TallyWhatsApp passes five strings: recipients, file path, message data, voucher type and a stable voucher GUID.

[COM Interface:TallyWASend]
    Project   : TallyWhatsappsender
    Class     : WhatsAppSender
    Interface : SendVoucher
    Parameter : p1 : String : In
    Parameter : p2 : String : In
    Parameter : p3 : String : In
    Parameter : p4 : String : In
    Parameter : p5 : String : In
    Return    : String

The class behind Project and Class must be registered on the PC; TallyWhatsApp registers a .NET Framework class with regasm. The GUID parameter acts as an idempotency key. An idempotency key is a value that lets the receiving service can recognise the same voucher and avoid queuing it twice. Microsoft's COM overview explains the registration model.

Step 2: How do you add the button to the sales voucher?

A form is the TDL definition of a whole screen's layout, and the # prefix modifies an existing Tally definition instead of creating a new one. Here the sales voucher form, Sales Color, gains two buttons and a save-time event.

[#Form: Sales Color]
    Add : Button : Send Sales WA Btn
    Add : Button : Send Sales WA To Btn
    On  : Form Accept : Yes : CALL : TallyWAOnSaveSales
    On  : Form Accept : Yes : Form Accept

[Button: Send Sales WA Btn]
    Key      : Alt + J
    Title    : Send WhatsApp
    Action   : Call : TallyWASendSales
    Inactive : @@TWASalesOff

Note the second On : Form Accept line. Once you attach your own Form Accept event, you must also re-add Tally's own accept action, or the voucher will not save. The Inactive formula greys the button out when the user has switched this voucher type off in the add-on settings.

The same pattern repeats on other forms such as Receipt Color and Credit Note Color. For example, TallyWhatsApp binds Alt+S rather than Alt+J on receipt, payment and journal forms, to avoid clashing with keys already used there.

Step 3: How does the function collect data and export the PDF?

The function finds the party, reads its mobile number, builds the message data, and exports the current voucher. These lines are trimmed from TallyWASendSales.

03 : SET : ActualParty : $PartyLedgerName
05 : SET : VchGuid     : $Guid
...
24 : Query Box : @SalesPromptStr + @MobileDisplay : Yes : No
...
42 : SET : PrintFileName : @@TWACompanyExportPrefix + "Sales_" + @SafeVchNo
43 : SET : SVExportFormat : @FormatStr
44 : SET : SVPrintFileName : $$MakeExportName:##PrintFileName:##SVExportFormat
45 : SET : SVOpenFileAfterExport : No
46 : CALL : TWAPreparePrintExport
48 : EXPORT REPORT : . : Yes
50 : CALL : TWARestorePrintExport
51 : SET : Exportedfilepath : $$GetFileFullPath:##SVPrintFileName

The mobile number comes from the ledger with $LedgerMobile:Ledger:##ActualParty, and the code prefixes 91 when only 10 digits are stored. Before exporting, the shipping code also checks the voucher's $IRN field, because an e-invoice is only final once the system described on the GST e-invoice portal has issued its IRN and QR code. The two helper calls around EXPORT REPORT save the user's print settings, force a single copy for the export, and then restore exactly what they changed.

Step 4: How do you hand the file to the external program?

Guard the call with $$IsCOMInterfaceInvokable, so the user sees a clear message instead of a TDL error when the component is missing.

52 : If : $$IsCOMInterfaceInvokable:TallyWASend
54 :    Exec COM Interface : TallyWASend : ##Contacts : ##Exportedfilepath : ##MsgBody : "sale" : ##VchGuid
58 :    Msg Box : "WhatsApp" : $$LastResult
60 : Else
62 :    Msg Box : "TallyWhatsApp" : "TallyWhatsApp connector is missing or outdated. Repair or update TallyWhatsApp, then restart Tally."
64 : End If

$$LastResult holds the string the COM method returned, which is a simple way to show success or failure. The shipping TDL calls a company-aware variant with two extra parameters, the company GUID and name, so the service can route each company to the right WhatsApp profile.

Which TDL traps should you avoid?

TrapWhat goes wrongFix
Forgetting to re-add Form AcceptYour event runs but the voucher never savesKeep On : Form Accept : Yes : Form Accept on every hooked form
Hooking the Printed Invoice report with EXPORT REPORTTally can crash with a Memory Access Violation (0xC0000005)Export from the voucher form, wrapped in print prepare and restore helpers
Guessing object or method namesFields return blank and the button silently does nothingInspect the real object first, for example over Tally's XML port, before writing expressions
Free text in the middle of a delimited stringA "[" typed in a narration corrupts every field parsed after itPut free-text fields such as Narration last
Key clashesYour button never fires on some screensTest each form; use a different key where Tally already uses one

The Memory Access Violation case is the same error that Tally's FAQ suggests isolating by disabling add-ons, which makes it a high-cost mistake on a live billing PC.

How do you load and test your TDL?

  1. Save the file as plain text with a .tdl extension.
  2. Load it under F1, TDLs and Add-Ons, then F4, as shown in Tally's TDL configuration help, or add User TDL = Yes and a TDL = line to tally.ini.
  3. Restart Tally after every change, because user TDL is read at start-up.
  4. Test on a backup company with a ledger that carries your own number.
  5. Check both paths: the button and the save event, with and without a mobile number.
TallyWhatsApp tray dashboard showing pending, sent, sending and failed counters, the WhatsApp QR pairing panel and licence status
The other half of the design: the TallyWhatsApp service and dashboard that receive what the COM call sends.

Should you build this yourself or use a ready-made TDL?

The TDL side is under a hundred lines per voucher type; the hard part is the external program. It needs a WhatsApp session, a queue that survives restarts, retries, safety pacing, and message templates, and WhatsApp's responsible use guidelines apply to whatever it sends.

If you want the finished result instead, the WhatsApp TDL free download installs all of it, and our explainer on how TDL-based WhatsApp automation works describes the service layer in more detail.

Frequently asked questions

Do I need TallyPrime Developer to write this?

No. A .tdl file is plain text and can be written in any editor. TallyPrime Developer helps with compiling to .tcp and debugging.

Which COM language should the bridge use?

Any language that can register a COM class works. TallyWhatsApp uses a C# .NET Framework class registered with regasm.

Why does my button not appear?

Check the form name exactly matches Tally's form, the TDL is loaded under F1 > TDLs & Add-Ons, and the key is not already used on that screen.

Can I copy the TallyWhatsApp TDL?

The snippets here are for learning. The full TDL depends on the TallyWhatsApp COM bridge and service, which are licensed software.

Prefer a ready-made, tested TDL?

Try TallyWhatsApp free for 14 days on your Windows PC, with every feature unlocked, including Gold multi-PC mode. No card needed.

Download 14-Day Free Trial TDL Product Page

Related guides