I have a json file containing some rules . This is an example:
[
{
"triggers": ["hello", "hey", "hi"],
"replies": [
{
"reply": "Hey there"
},
{
"reply": "Hola"
},
{
"reply": "Hello World"
}
]
},
{
"triggers": ["who are you", "your name"],
"replies": [
{
"reply": "some name"
},
{
"reply": "lorem ipsum"
}
]
}
]
What I am trying to achive is if a user queries a text, let's say "hello" I want the script to search through the json file and see if the query exists in any trigger array. If it exists, then I want the script to pick a random reply from the replies array.
I can:
- Change the json file as you want, as long as there is a list of triggers and a list of replies for each trigger.
- Use loops. But remember that my json file is bigger than above so they shouldn't slow down my whole script.
I can't:
- Use while loops or infinite loops. I have to process other data alongsides.
I've tried everything. Please help me if you could. Thank you for helping.