2017-08-15 1 views
2

J'envoie InlineQueryResultArticle aux clients et je me demande comment obtenir le résultat et ses données (comme result_id, ...).Télégramme bot: Comment obtenir le résultat en ligne choisi

est ici le code pour envoyer les résultats:

token = 'Bot token' 
bot = telegram.Bot(token) 
updater = Updater(token) 
dispatcher = updater.dispatcher 

def get_inline_results(bot, update): 
    query = update.inline_query.query 
    results = list() 

    results.append(InlineQueryResultArticle(id='1000', 
              title="Book 1", 
              description='Description of this book, author ...', 
              thumb_url='https://fakeimg.pl/100/?text=book%201', 
              input_message_content=InputTextMessageContent(
               'chosen book:'))) 

    results.append(InlineQueryResultArticle(id='1001', 
              title="Book 2", 
              description='Description of the book, author...', 
              thumb_url='https://fakeimg.pl/300/?text=book%202', 
              input_message_content=InputTextMessageContent(
               'chosen book:') 
              )) 

    update.inline_query.answer(results) 


inline_query_handler = InlineQueryHandler(get_inline_results) 
dispatcher.add_handler(inline_query_handler) 

Je suis à la recherche d'une méthode comme on_inline_chosen(data) pour obtenir id de l'élément choisi. (1000 or 1001 pour l'extrait ci-dessus), puis envoyez la réponse appropriée à l'utilisateur.

Répondre

2

OK, j'ai eu ma réponse de here

Manipulation utilisateur résultat choisi:

from telegram.ext import ChosenInlineResultHandler 

def on_result_chosen(bot, update): 
    print(update.to_dict()) 
    result = update.chosen_inline_result 
    result_id = result.result_id 
    query = result.query 
    user = result.from_user.id 
    print(result_id) 
    print(user) 
    print(query) 
    print(result.inline_message_id) 
    bot.send_message(user, text='fetching book data with id:' + result_id) 


result_chosen_handler = ChosenInlineResultHandler(on_result_chosen) 
dispatcher.add_handler(result_chosen_handler) 
4

Vous devez définir /setinlinefeedback à @BotFather, alors vous obtiendrez cette mise à jour

+0

Merci, mais je suis Je me demande comment implémenter 'on_inline_result_selected()' dans le code. –