I need help writing code for my Telegram bot in Python. I have a config.py file that contains two lists of keywords: keywords and button_phrases.
keywords – responsible for buttons that reveal sub-buttons when clicked.
button_phrases – responsible for buttons that open links when clicked.
I need the bot to check the text entered by the user and look for keywords in the following order:
Check for the presence of keywords from keywords.
Check for the presence of keywords from button_phrases.
The get_matching_keywords function should perform a specific task: checking for the presence of keywords in a single message. In our case, the function should use two loops that will close when the keywords are found and send the appropriate buttons.
The loops should work as follows:
Check for the presence of keywords from keywords. If found, add the button and exit the loop.
Check for the presence of keywords from button_phrases. If found, add the button and exit the loop.
If the text contains keywords from both lists (keywords and button_phrases), the bot should send the corresponding buttons together.
I would appreciate any advice or example code that can help implement this logic. Thanks!
I wrote a function that checks for keywords, but I am not sure how to structure the loops correctly to ensure both lists are checked and the appropriate buttons are sent.
Edgar Hakobyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.