Fill /auth process with authorization logic
  • 11 Jun 2024
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Fill /auth process with authorization logic

  • Dark
    Light
  • PDF

Article summary

When the setting up process is completed, fill the /auth process with authorization logic using the following procedure:

  1. Sending a message to a user.
  2. Waiting for the user’s reply.
  3. Checking whether to exit from the process.
  4. Validating the received phone number.
  5. Saving the phone number:
    1. From a message with contact details (Viber, Telegram).
    2. From a text message (Facebook Messenger).
  6. Adding the phone number to the user profile.
  7. Completing the process.

Auth process

1. Sending message to user

To send a message to a user for a bot:

  1. Copy the task to the Send Message Process.

  2. 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)

    Send mess to user

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.

Waiting for Callback2

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.

Checking

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.

Phone

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.

Save_a

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.

Save b

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.

Adding phone

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.

Complet process


Was this article helpful?