I'm making a Telegram Bot in Python with the help of Telegram Bot API. 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. So I've found how to get message_id, message_time, message_text and user_id. But can't find how to get the other.
- How do I get session_id and its start and end time and bot_id? I've looked it up in the documentation and found nothing.
- How to insert both user_id and bot_id in the same column or it's better to make 2 columns for that? 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? Any help appreciated.
Have you considered a usage of any library builded upon the Telegram API? Development will go much faster and those library's documentations also help to understand Telegram API.
Check for example: