The WhatsApp Business API does not have a ref parameter (like Messenger does, for instance) which allows the receiving application to know where a given WhatsApp user came from.

Conversations with a business over WhatsApp are usually initiated via a link -- and the only fields that can be supplied to the wa.me link are the number and text fields (source).

Is there a way that I can get around this restriction, and add a ref parameter (e.g. ref=google-ad) to the link?

Tag:whatsapp

Only one comment.

  1. FloatingRock

    Found a detailed post on encoding params into the WhatsApp link that address this specific question.

    There's no official solution, but the writer has a smart hack: using non-printable characters to encode the DeviceID (or ref param, in your case) to the text parameter.

    Code for encoding/decoding the param is reproduced below, but I recommend reading the article for all the pertinent details:

    # This class handles encoding and decoding of non printable characters # into strings class NonPrintableCoder NON_PRINTABLES = %W(\u200a \u200b \u200c \u200d \u200e) class << self def encode(num) base = NON_PRINTABLES.length output = "" while(num > 0) do output = NON_PRINTABLES[num % base] + output # MSB -> LSB num /= base end output end def decode(str) base = NON_PRINTABLES.length output = 0 str.length.times do |i| chr = str[str.length - i - 1] output += NON_PRINTABLES.index(chr) * base ** i end output end end end

    Usage:

    # Generate link (encode '12345' into text string) "https://wa.me/..?text=" + NonPrintableCoder.encode(12345) + "hi there!" # Incoming webhook (extract '12345' from text string) non_printables = msg.split("").filter do |char| char.in? NonPrintableCoder::NON_PRINTABLES end NonPrintableCoder.decode(non_printables) # => 12345

Add a new comment.