问题描述
我的电报机器人是一个对话框,它需要保留问题和答案(例如TriviaBot).什么是最好的(最有效的)方法?以用户ID为键的数据库?
My telegram bot is a dialog and it needs to keep the questions and the answers (like TriviaBot). What is the best (most efficient) method to do this? A database with the user id as key?
有很多电报机器人,但是带有示例源代码的示例在哪里?
There is a lot of telegram bots, but where are examples with the source code to get ideas?
推荐答案
您的问题与电报机器人API并没有真正的关系.您本质上是在问:我有一个应用程序必须保留用户交互的历史记录,如何做到这一点(有效)?
Your question is not really related to the telegram bot API. You are essentially asking: I have an application that has to keep an history of user interactions, how to do this (efficient)?
要回答这个问题:您可以使用数据库,并使用唯一标识符为每个对话插入一个条目.由于电报在每个对话中都有一个chat_id,因此您可以使用它.根据您要确切存储的内容,应选择存储方式. (每个答案,每个对话或...的条目)
To answer that: you could use a database and insert an entry for each conversation using an unique identifier. Since telegram has a chat_id for each conversation, you could use that. Depending on what you are exactly trying to store, you should choose how to store it. (an entry for each answer, or for each conversation or ...)
如果您使用python编程,则可以使用名为 python-telegram-bot
示例在这里: https://github.com/leandrotoledo/python-telegram-bot#examples
这篇关于电报机器人-保留问题和答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!