Subscribers write in different ways: with spaces, brackets, extra characters and typos. The functions in this group bring an answer to one format and check it.

Where it helps:

  • bring a phone number to one format before sending it to a CRM or a spreadsheet;
  • accept an answer with a typo, for example “Londn” instead of “London”;
  • pull an order number or an amount out of the subscriber’s message.

Functions

FunctionDescriptionExample
normalize_phone(phone)Leaves only digits in a phone number. An 11-digit number starting with 8 is converted to start with 7.normalize_phone("8 (978) 999-99-99") → "79789999999"
match(text, pattern, ignore_case=True)Checks if the string contains the specified word (by pattern).match("купить товар", "купить") → True
similar(text1, text2, threshold)Compares strings allowing for typos, ignoring case and spaces at the edges. Returns True if the similarity is at least threshold: from 0 to 1, 0.7 by default.similar("Moscow", "Moskow") → True
findall(pattern, text, index)Finds all parts of the text that match a regular expression and returns them as a list. With index, returns one match by number (starting from 0), or an empty string if there's none.findall("\d+", "Order 123 and 456") → ["123", "456"]
findall("\d+", "Order 123 and 456", 1) → "456"

Example: a phone number in one format

client.phone_clean = normalize_phone(client.phone)
client.phone_ok = len(client.phone_clean) == 11

If the subscriber entered 8 (978) 999-99-99, phone_clean gets 79789999999 and phone_ok gets True.

You can copy a flow template with phone number validation via the link.

Example: an answer with a typo

client.city_ok = similar(client.city, "London")

The answers “London”, “london” and “Londn” give True. Case and spaces at the edges are ignored. The default similarity threshold is 0.7; you can change it with the third argument: similar(client.city, "London", 0.9).

Example: an order number from a message

client.order_id = findall("\d+", client.answer, 0)

If the subscriber wrote “My order 48213 hasn’t arrived”, order_id gets 48213.

Important: in findall, the pattern comes first and the text second.

Answer length, letter case and cutting strings are described in Formula: Working with Text.


If you did not find the answer to your question, feel free to contact us in the chat inside your dashboard, message us on Telegram at @BotHelpSupportBot, or email us at hello@bothelp.io.

Enjoy the full functionality of the BotHelp platform for creating broadcasts, automated funnels, and chatbots — free for 14 days.

Get 14 Days Free

Sign up for BotHelp

Get 14 days of full access for free — enough to build your first bot and test it on real subscribers.

Create account

Была ли статья полезна?

Our channelsTelegramMAX
Спасибо за обратную связь!