历史记录导入问题
deskmonster opened this issue · 7 comments
deskmonster commented
telegram-search-bot/web_manager.py
Line 37 in ed597d4
这里遍历messages后检测 user是否在'from_id'中,但是有些特殊事件(比如加群,退群)是没有'from_id'的而是'actor_id',遍历到这种字段会直接报错:
{
"id": -000000,
"type": "service",
"date": "2022-04-29T21:21:41",
"actor": "测试号",
"actor_id": "user5555",
"action": "join_group_by_link",
"inviter": "Group",
"text": ""
}
[2022-06-15 03:53:09,020] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "web_manager.py", line 92, in upload_file
success_count, fail_count, fail_messages = insert_messages(history_json['id'],history_json['messages'])
File "web_manager.py", line 37, in insert_messages
if 'user' not in message['from_id']:
KeyError: 'from_id'
192.168.208.1 - - [15/Jun/2022 03:53:09] "POST / HTTP/1.1" 500 -
解决方案:
写一个try或者先判断'from_id'是否在字段里:
if 'from_id' not in message :
continue
elif 'user' not in message ['from_id']:
continue
deskmonster commented
另外bot自己记录的chat的id是-100xxxx
导入的chatid是xxxxx
好像也会导致无法搜索
解决方案:
导入的时候给加上-100?
Taosky commented
chat id应该是唯一的吧,导入的id和实际的不一致吗?
deskmonster commented
Taosky commented
deskmonster commented
Taosky commented
telegram-search-bot/web_manager.py
Line 19 in a461b6c
这里 new chat 的chat id 还是没有修改..
另外这里似乎有两个一样的判断
修改了,判断是不是小于0,不是的话就加上-100
deskmonster commented
测试可用