# ...Create a referral program

## **The referral program in WhatsApp**

The functionality of the created bot: \
1\. Generating the referral (partner) link; \
2\. Checking if the user is in the base already; \
3\. Notifying the inviter about the new referral; \
4\. Registering users in the base; \
5\. Requesting the list of referrals.

1. So that we can understand from whom the user came from, the bot creates the link by the template: link = <https://wa.me/(your> number the bot is connected to)?text=You%20were%20recommended%20by%20#{phone}%20Hello

![](https://lh5.googleusercontent.com/UFTHmg7enycazJJcAX85sNe0amCcV-Z1jFDzKio1P_V453pMBBgxDFxzzXD8m_1_moxyfNvekhThOK_iEKFrBXhIpe331F5jt_UnJqeVDfbpTIdaUGWgPSDjct8CWgaEwzxRoXHmBm9OVmY3OA)

Instead of #{phone} the client’s phone number gets entered, the same number that requested its referral link.

The generated link we send not as the block’s text, but as an attachment (a link with a click notification), this way the link seems shorter.

![](https://lh4.googleusercontent.com/xyO2IAkdp1sA4GDQvG6-wxSTVfecBrh_JXXpeepVocvsQqh2Qvll9LUX84QtgS87dB9VVS7MngYuxYJZORZNdGlA_yFRgXtH2PHIxDE4_adZ1FfAiwZhAoLg_4xqFsbRJqR7p8-T8ooMndLdOQ)

2\. So, we have a link through which new users come in to the bot. When moving through the partner link, the client gets an opened chat window with a pre-filled message (as seen below)

![](https://lh3.googleusercontent.com/0Ih9mRg_P3SEJPuHRz6gKQA6WiQPBe3bp6RmCgpS7_Y0JH2C3QSQSBkhhIC6LkX1yf8V22_m6YxD7d2XSHN-V73CDnyj72KmQ-GEK3KhVluA9lDFyoW2yU3TQ0igSIv58ilfJqSGLqWqXudV2Q)

The checking command will work only if the bot finds the phone number from the received message from the client.

The third step:

* divide the phrase into components with the help of the splitter command (instruction [here](https://docs.salebot.ai/variables/calculator#to-work-with-strings))
* set up an arrow with a regular expression (and check if the phone number is correct)
* save the phone number from the message into the variable (like #{ref})
* check the client’s (the one that clicked on the link) phone number to see if it already is someone’s referral (invited earlier by someone else and written down in our base). We do this with the column search function (instruction [here](https://docs.salebot.ai/integrations/google-tables))

![](/files/NeUV03gQPJ56PXdkpfhx)

1. Now let’s put the inviter and the invitee in the database (instruction [here](https://docs.salebot.ai/integrations/google-tables))
2. Let’s add a special command to the bot, a command that lets us see the list of referrals (instruction [here](https://docs.salebot.ai/integrations/google-tables))

![](/files/ACV5E3GVd91JfOZGPgj3)

In other messengers it’s even easier to create such a referral system, because the data on the inviter is shared via a hidden parameter when moving, and the new client doesn’t need to send the text like “I was invited by this number”.

## Video version of the article


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mavibot.ai/faq/questions/refferal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
