Your question is Messaging Bot Method. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Implement a method for a Brigit messaging bot that selects a preset response for each incoming message. A preset matches when its trigger phrase appears as a contiguous sequence of words in the message, ignoring capitalization and punctuation.
If multiple presets match, return the response for the trigger containing the most words. If multiple matches have the same length, use the preset that appears first in presets. If no preset matches, return fallback.
Implement match_bot_responses(messages, presets, fallback). messages is a list of strings. presets is an ordered list of dictionaries, each containing a nonempty string trigger and a string response. Return a list of response strings in the same order as messages.
Tokenization is defined as extracting contiguous sequences matching [A-Za-z0-9']+, converted to lowercase. For example, "Where's my money?" becomes ["where's", "my", "money"].
def match_bot_responses(messages, presets, fallback):