fix: slack adapter

This commit is contained in:
wangcham
2025-11-06 16:50:14 +00:00
parent 913b9a24c4
commit ad64e89a86
2 changed files with 24 additions and 7 deletions

View File

@@ -30,6 +30,13 @@ def handle_validation(body: dict, bot_secret: str):
response = {'plain_token': body['d']['plain_token'], 'signature': signature_hex}
# 打印调试信息
print(f'[QQ Official Validation]')
print(f' event_ts: {body["d"]["event_ts"]}')
print(f' plain_token: {body["d"]["plain_token"]}')
print(f' Message to sign: {msg}')
print(f' Signature: {signature_hex}')
return response
@@ -110,13 +117,17 @@ class QQOfficialClient:
try:
# 读取请求数据
body = await req.get_data()
print(f'[QQ Official] Received request, body length: {len(body)}')
payload = json.loads(body)
# 验证是否为回调验证请求
if payload.get('op') == 13:
print(f'[QQ Official] Received callback validation request (op=13)')
# 生成签名
response = handle_validation(payload, self.secret)
print(f'[QQ Official] Returning validation response')
return response
if payload.get('op') == 0:
@@ -128,6 +139,7 @@ class QQOfficialClient:
return {'code': 0, 'message': 'success'}
except Exception as e:
print(f'[QQ Official] ERROR: {traceback.format_exc()}')
await self.logger.error(f'Error in handle_callback_request: {traceback.format_exc()}')
return {'error': str(e)}, 400

View File

@@ -92,8 +92,6 @@ class SlackAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
config: dict
def __init__(self, config: dict, logger: EventLogger):
self.config = config
self.logger = logger
required_keys = [
'bot_token',
'signing_secret',
@@ -102,13 +100,20 @@ class SlackAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
if missing_keys:
raise command_errors.ParamNotEnoughError('Slack机器人缺少相关配置项请查看文档或联系管理员')
self.bot = SlackClient(
bot_token=self.config['bot_token'],
signing_secret=self.config['signing_secret'],
logger=self.logger,
bot = SlackClient(
bot_token=config['bot_token'],
signing_secret=config['signing_secret'],
logger=logger,
unified_mode=True
)
super().__init__(
config=config,
logger=logger,
bot=bot,
bot_account_id=config['bot_token'],
)
async def reply_message(
self,
message_source: platform_events.MessageEvent,