- 11 Jun 2024
- 2 Minutes to read
- Contributors
- Print
- DarkLight
- PDF
Fill /auth process with authorization logic
- Updated on 11 Jun 2024
- 2 Minutes to read
- Contributors
- Print
- DarkLight
- PDF
When the setting up process is completed, fill the /auth process with authorization logic using the following procedure:
- Sending a message to a user.
- Waiting for the user’s reply.
- Checking whether to exit from the process.
- Validating the received phone number.
- Saving the phone number:
- From a message with contact details (Viber, Telegram).
- From a text message (Facebook Messenger).
- Adding the phone number to the user profile.
- Completing the process.
1. Sending message to user
To send a message to a user for a bot:
Copy the task to the Send Message Process.
Add the Copy Task node that calls Send Message Process with the following parameters:
- channel:
{{channel}}
- chat_id:
{{chat_id}}
- text_id:
"askPhone"
- attachment_id:
"sharePhone"
(see an example)
- channel:
2. Waiting for user’s reply
After sending a message, the bot waits for the user’s actions. The waiting job is on the Waiting for Callback node. In case of any reply from the user, the task will be changed and go to Node 3.
3. Checking whether to exit from process
For correct bot running and convenient navigation, providing a button with the /exit command is recommended. This command cancels the current process and leads the user to the main menu. This practice requires a Node with the Condition logic that will check against exit conditions.
4. Validating received phone number
If the user didn’t use the Exit button for cancellation, the /auth process uses the Condition node to validate the received phone number. In our case, if the user entered a wrong value (wrong phone number, etc.), we will offer to enter the phone number or to click the Share Number button one more time.
The regular expression below works with Ukrainian numbers. For other countries' numbers, you need to adjust them. Extending this logic to show an error notification or prompt is possible.
5. Saving phone number
a. From message with contact details (Viber, Telegram)
If the previous condition succeeded and we received the message
object with contact details, we save the phone number into the phone
parameter.
b. From text message (Facebook Messenger)
If the previous condition succeeded, and we received the message
object with a text matching a phone number regular expression, we save the phone number into the phone
parameter.
6. Adding phone number to user profile
The received earlier value of the phone
parameter is added to the user data in the User Profile State Diagram. It is possible to use this value in other processes.
7. Completing process
The /end command is used to complete the process and to return to the main menu. Pass the "command": "/end"
statement to the Router Process using the Copy Task logic.