简体   繁体   English

如何使用 Telegram Bot API 在 python 中获取 session_id、其开始和结束时间以及 bot_id?

[英]How to get a session_id, its start and end time and bot_id in python with Telegram Bot API?

I'm making a Telegram Bot in Python with the help of Telegram Bot API.在 Telegram Bot API 的帮助下,我正在 Python 中制作 Telegram Bot。 So I want to keep some information about the Telegram Chat in SQLite database and i need to get message_id, message_time, session_id, session_start_time, session_end_time, message_text and user/bot_id.所以我想在 SQLite 数据库中保留一些关于电报聊天的信息,我需要获取 message_id、message_time、session_id、session_start_time、session_end_time、message_text 和 user/bot_id。 So I've found how to get message_id, message_time, message_text and user_id.所以我找到了如何获取 message_id、message_time、message_text 和 user_id。 But can't find how to get the other.但是找不到其他方法。

  1. How do I get session_id and its start and end time and bot_id?如何获取 session_id 及其开始和结束时间以及 bot_id? I've looked it up in the documentation and found nothing.我在文档中查了一下,什么也没找到。
  2. How to insert both user_id and bot_id in the same column or it's better to make 2 columns for that?如何在同一列中插入 user_id 和 bot_id 或者最好为此制作 2 列? Like it doesn't matter who sent the message, most important is that the message was sent.就像谁发送消息并不重要,最重要的是消息是发送的。 That's what I came up with so far:到目前为止,这就是我想出的:
    conn = sqlite3.connect("emojic_database.db")
    cur = conn.cursor()
    tconv = lambda x: time.strftime("%H:%M:%S %d.%m.%Y", time.localtime(x))
    cur.execute("INSERT INTO messages (mes_id, mes_time, ses_id, mes_text, user_id)\
                    VALUES (?,?,?,?,?)", (message.message_id, tconv(message.date), ???, message.text, message.from_user.id)
    cur.execute("INSERT INTO sessions (ses_id, start_time, end_time)\
                    VALUES (?,?,?)", (???))
    conn.close()

Or maybe I have to use another API?或者也许我必须使用另一个 API? Any help appreciated.任何帮助表示赞赏。

Have you considered a usage of any library builded upon the Telegram API?您是否考虑过使用基于 Telegram API 构建的任何库? Development will go much faster and those library's documentations also help to understand Telegram API.开发将 go 更快,这些库的文档也有助于理解 Telegram API。

Check for example:检查例如:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Wit.ai机器人对话结束时删除context / session_id - How to delete context/session_id at end of conversation in Wit.ai bot Telegram bot API:获取消息 ID 以转发它 - Telegram bot API: get message id to forward it 如何从电报机器人获取 chat_id、user_id 和时间? - How to get chat_id, user_id and time from telegram bot? 如何获得正确的 session_id? (Scrapy,Python) - How to get a correct session_id? (Scrapy, Python) 如何通过python-telegram-bot接收file_id? - How to receive file_id through python-telegram-bot? 如何获取我通过 Python 使用 Telegram 机器人发送的消息的 ID? - How get id of the message I sent with my Telegram bot via Python? Python-telegram-bot:如何在电报 api 中通过机器人获取自定义编号的最新消息? - Python-telegram-bot: How can I get customized number latest message by bot in telegram api? 如何在电报(pytelegramBotAPI)中获取chat_id和message_id以更新电报bot(Python)中最后发送的消息 - how to get chat_id and message_id in telebot(pytelegramBotAPI) to update last sent message in telegram bot(Python) 如何在 python 电报机器人 api 中获取照片描述? - How to get photo description in python telegram bot api? Python-telegram-bot 检测实时位置的开始和结束 - Python-telegram-bot detect start and end of live location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM