October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Menlo Park desk4 min

How to Build WhatsApp Click-to-Chat Links (wa.me) in JavaScript and Python

Use a normalized international number and encode only the message component to create a WhatsApp click-to-chat link in JavaScript or Python.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a WhatsApp click-to-chat link with https://wa.me/<number>, using the recipient’s full international-format number without a leading plus sign or formatting marks. To prefill a message, add ?text= followed by the URL-encoded message. The link opens a chat with the text ready; the user still has to send it.

WhatsApp link format

WhatsApp’s documented click-to-chat format is https://wa.me/<number>. Put the recipient’s complete international-format number in the path, omitting the plus sign, leading zeroes as applicable to that international representation, spaces, brackets, and dashes. Do not blindly remove digits from a locally formatted number: first establish the correct international-format number for that recipient. See WhatsApp’s click-to-chat instructions and its iOS linking guidance.

As an Amazon Associate I earn from qualifying purchases.

For example, the number supplied in the examples below is already normalized as 15551234567. A locally formatted number such as +1 (555) 123-4567 should not be copied directly into the URL path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add a pre-filled message

Append a text query parameter: https://wa.me/<number>?text=<encoded-message>. WhatsApp places the text in the chat’s message field; it is not sent automatically. The user reviews it and chooses whether to send.

If the user should choose the recipient, omit the number and use the message-only form https://wa.me/?text=<encoded-message>. WhatsApp says this opens a recipient-selection flow.

Build the link in JavaScript

Use encodeURIComponent() for the message value only. It encodes dynamic text as a URI component, including reserved characters and non-ASCII text that could otherwise interfere with URL parsing. The protocol, host, path separator, and query syntax stay literal.

function makeWhatsAppLink(phoneNumber, message) {
  // Supply phoneNumber in international format, with formatting removed.
  const base = `https://wa.me/${phoneNumber}`;
  if (message === undefined || message === null || message === "") {
    return base;
  }
  return `${base}?text=${encodeURIComponent(message)}`;
}

console.log(makeWhatsAppLink("15551234567", "Hello! Is this still available?"));

To make a link that lets the user pick the recipient, keep the same component-encoding rule:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const message = "Hello! Is this still available?";
const link = `https://wa.me/?text=${encodeURIComponent(message)}`;

Do not apply encodeURIComponent() to the complete URL: doing so would encode structural characters such as :, /, ?, and =, rather than leaving a usable URL around the encoded message.

Build the link in Python

Use urllib.parse.quote(message, safe='') to percent-encode the message component. Python’s quote uses UTF-8 by default; quote_plus is intended for form-value encoding and represents spaces as plus signs, so quote is the explicit choice here for component construction. See the Python 3.12.15 urllib.parse documentation.

from urllib.parse import quote

def make_whatsapp_link(phone_number: str, message: str | None = None) -> str:
    # Supply phone_number in international format, with formatting removed.
    base = f"https://wa.me/{phone_number}"
    if not message:
        return base
    return f"{base}?text={quote(message, safe='')}"

print(make_whatsapp_link("15551234567", "Hello! Is this still available?"))

For Python versions before 3.10, replace str | None with Optional[str] after importing Optional from typing, or omit the annotation. This typing syntax does not affect URL construction.

For a recipient-selection link, encode the message in the same way:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from urllib.parse import quote

message = "Hello! Is this still available?"
link = f"https://wa.me/?text={quote(message, safe='')}

JavaScript and Python encoding compared

Implementation Encoder Role and handling
JavaScript encodeURIComponent(message) Encodes the dynamic message component, including reserved characters; keep fixed URL syntax outside the encoded value.
Python quote(message, safe='') Percent-encodes the dynamic message component using UTF-8 by default; use quote rather than form-oriented quote_plus for explicit component construction.

Use JavaScript when constructing the link in a browser-side flow, and Python when building it in an application or script. In either language, encode the message value—not the entire URL.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common mistakes and limits

  • Passing a formatted phone number: Use the complete international-format number in the form WhatsApp expects, without the plus sign or punctuation. Confirm the correct number representation rather than stripping digits mechanically.
  • Appending raw message text: Characters such as spaces, &, ?, and # can affect URL parsing. Encode the message as one component before appending it.
  • Encoding the whole URL: Leave https://wa.me/ and ?text= as URL syntax; encode only the dynamic message value.
  • Expecting automatic sending: Opening the link prepares the chat and fills the text field; it does not send the message for the user.
  • Assuming every number is reachable: WhatsApp says the recipient must have an active WhatsApp account. Click to chat works on phone and WhatsApp Web, and does not require saving the recipient to the address book.

The examples follow WhatsApp’s published URL format and the language documentation; they are not a claim that the snippets were executed against WhatsApp clients.

Business short links

For businesses using the WhatsApp Business app, WhatsApp says the app automatically generates a shareable short link and lets the business set or edit a default message. Anyone with that link can message the business. See WhatsApp’s guidance on creating short links. A basic wa.me URL does not require a third-party link service.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.