My bot passes a simple string (query.query) through a function that returns a "big" dictionary with many subdictionaries (each representing "card" data) inside it. As it works right now, all keys and values for all returned subdictionaries get displayed in-line (until pagination limit). So for example, writing "blue" will return the key:value pairs for all subdictionaries whose card name == "blue".
I want the bot to first display inline results for card names and, after the user chooses a card, for the bot to display the rest of the card data, so the user can choose what part to send in chat. This would look like:
- User queries the word "blue" and makes card titles for "blue blob", "blue drake", "blue beard" appear in-line
- User select "blue beard" from that menu, making bot then display available data for "blue-beard" in-line (stats, attack, etc.)
Here's a snippet of said code. Check the # comment to see where I think it all breaks down
@bot.inline_handler(lambda query: len(query.query) > 3)
def query_card(inline_query):
temp_names_list = []
results_list = []
try:
sound_dict = scrape(inline_query.query)
for key, sub_dict in sound_dict.items():
temp_names_list.append(types.InlineQueryResultArticle(id=key, title=sub_dict['Name'], input_message_content=types.InputTextMessageContent(sub_dict['Name'])))
bot.answer_inline_query(inline_query.id, temp_names_list, cache_time=1)
#The code breaks down here since I haven't found a way of passing the result to ^ this answer_inline_query into the next part of the loop:
for key, sub_dict in sound_dict.items():
for k, v in sub_dict.items():
if k == ['message']['text']:
results_list.append(types.InlineQueryResultArticle(id=key+k, title=k, input_message_content=types.InputTextMessageContent(sub_dict['Name']+"\'s ["+k+"] bit:\n"+v)))
#results_list.append(types.InlineQueryResultVoice(id=k, voice_url=v, title="^ "+sound_dict['Name']+"\'s ["+k+"] bit:\n"+v, caption=sound_dict['Name']+"\'s ["+k+"] bit"))
bot.answer_inline_query(inline_query.id, results_list, cache_time=1)
except Exception as e:
print(e)