(Наталья) Working with promo codes
The bot allows not only to give promo codes to clients, but also check their validity and control their one-time use
You can give a promo code to a client in one of two ways:
Prepare a list of promo codes in a Google Sheet, train Mavibot to find an available code, deliver it to the client, and then mark it as issued in the sheet.
Train Mavibot to generate promo codes based on specific rules, provide the code to the client, and then record it in the sheet.
You can check the validity of codes using Google Sheets and its API requests.
Learn more about these processes below:
How to check a promo code from Google Sheets
If you have an objective to limit access to the bot or special offers, you can use the function of checking promo codes.
Prepare a Google Sheet in which one column will be a list of your promo codes. Set the access setting to “Anyone with this link can edit”. How to do this, read in this article
Here’s how the function works: A client enters their promo code into the bot. The function then checks if the code exists in the designated column you created. If the code is found, the phrase "Promo code was used" is added to the adjacent cell, and the function returns this response:
{“status”: ‘’0’’}
Function address: https://store.mavibot.ai/function/check-promocode
To check the code you need to send these parameters from the block:
{"id":"1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI", "promocode": "#{question}", "col_number": "1"}
id is the ID of your Google Sheet containing the promo codes. You can find it in the URL of your document. Make sure the document’s sharing settings allow anyone with the link to edit.
If the promo codes are situated in a separate sheet, then you need to use the parameter list_name, in which you have to place its name, for example:
{"id":"1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI", "promocode": "#{question}", "col_number": "1", "list_name": "Sheet name"}
The next parameter is the promo code that the client applies.
col_number - the column number that holds the codes
{“status”: ‘’1’’}
, after that you can’t apply the code for the second time
If the function doesn’t find the promo code in the sheet or it’s been already used, then it replies with
{“status”: ‘’0’’}
If you’re wondering how to use this and where to place it, check out the screenshot below.
#{custom_answer} - the answer from the server that’s mentioned in the "URL request" tab.
Use this variable in the answer tab to see its contents. If everything is set up correctly, save status->status, then in the arrows under the “Variable for comparison” tab, set the conditions to "status == 0" (replying to the user that the code has already been used) or "status == 1" (allowing the user to proceed).
An example is shown below.
How to give a promo code from Google Sheets
Prepare your sheet as shown in the image below, with promo codes in the first column and the word "Available" in the second column. Configure access settings to “Anyone on the Internet with this link can edit”. How to do this, read in this article
You will get a link similar to this: https://docs.google.com/spreadsheets/d/1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI/edit?usp=sharing
The bold text here is your page ID. You’ll need it later.
Create a block on Mavibot and paste these parameters in its settings:
Request type: POST-json
URL request: https://store.salebot.ai/function/findcell
Stored values:
data->Promo code;
cell_number|row ->line;
JSON parameters:
{"id": "1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI", "find": "Available", "col": 2, "return": 1}
where you need to place your own page id instead of 1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI
Create a block below and click on "Time settings" in the connection settings. In the opened section, under the "Delay before answer" tab, enter -1 to make the transition happen as quickly as possible.
In the new block, set the parameters mentioned below.
To show the client his code, type #{Promo_code}
Request type: POST-json
URL request: https://store.mavibot.ai/function/gsheets
JSON parameters:
{"id": "1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI", "write":{"b#{line}":"Used"}}
where you need to place your own page id instead of 1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI
How to generate a promo code with the Mavibot help
If a promo code can be created with certain rules, then you can generate it right in Mavibot and write it down in Google Sheets for later checking.
You will need variables for this. For example, to generate a unique promo code, you can use the variable #{client_id}. It’s a variable in Mavibot that indicates your client’s number in the system.
In the block’s settings Advanced -> Calculator write down:
Promocode = promo#{client_id}
Paste #{Promo_code} in the "Answer" field You’ll get a promo code promo1330882.
If you want to add more random aspect to your code, then add the function call random()
Promocode = 'promo' + '#{client_id}' + random(0,10)
In this case, it adds 1 random number in the end
Now let’s paste it to our sheet of codes.
First, create a new blank Google Sheet. Set the sharing permissions to "Anyone with the link can edit." Then, type Promo codes into cell A1.
If the first cell is empty, the function won’t work. You need to be sure to fill it in!
You will get a link similar to this:
https://docs.google.com/spreadsheets/d/1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI/edit?usp=sharing
The bold text here is your page ID. You’ll need it later.
Now let’s get back to Mavibot and continue working on your block with the promo code
Request type: POST-json
URL request: https://store.mavibot.ai/function/gsheets
JSON parameters:
{"id": "1sl15vKFjo5TFD98GnVjF3AlLtdhr85-AkEjoeJkgDxE", "mapping":{"a":"#{Promo_code}"}}
Where you need to place your own page id instead of 1HfnHDbJYTGz68-3KWIcRISncTmdEn8v7Vf_OKvDMrOI
You should create something like this:
Last updated