mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-17 09:56:06 +00:00
fix: slack adapter
This commit is contained in:
@@ -30,6 +30,13 @@ def handle_validation(body: dict, bot_secret: str):
|
|||||||
|
|
||||||
response = {'plain_token': body['d']['plain_token'], 'signature': signature_hex}
|
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
|
return response
|
||||||
|
|
||||||
|
|
||||||
@@ -110,13 +117,17 @@ class QQOfficialClient:
|
|||||||
try:
|
try:
|
||||||
# 读取请求数据
|
# 读取请求数据
|
||||||
body = await req.get_data()
|
body = await req.get_data()
|
||||||
|
|
||||||
|
print(f'[QQ Official] Received request, body length: {len(body)}')
|
||||||
|
|
||||||
payload = json.loads(body)
|
payload = json.loads(body)
|
||||||
|
|
||||||
# 验证是否为回调验证请求
|
# 验证是否为回调验证请求
|
||||||
if payload.get('op') == 13:
|
if payload.get('op') == 13:
|
||||||
|
print(f'[QQ Official] Received callback validation request (op=13)')
|
||||||
# 生成签名
|
# 生成签名
|
||||||
response = handle_validation(payload, self.secret)
|
response = handle_validation(payload, self.secret)
|
||||||
|
print(f'[QQ Official] Returning validation response')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
if payload.get('op') == 0:
|
if payload.get('op') == 0:
|
||||||
@@ -128,6 +139,7 @@ class QQOfficialClient:
|
|||||||
return {'code': 0, 'message': 'success'}
|
return {'code': 0, 'message': 'success'}
|
||||||
|
|
||||||
except Exception as e:
|
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()}')
|
await self.logger.error(f'Error in handle_callback_request: {traceback.format_exc()}')
|
||||||
return {'error': str(e)}, 400
|
return {'error': str(e)}, 400
|
||||||
|
|
||||||
|
|||||||
@@ -92,8 +92,6 @@ class SlackAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
|
|||||||
config: dict
|
config: dict
|
||||||
|
|
||||||
def __init__(self, config: dict, logger: EventLogger):
|
def __init__(self, config: dict, logger: EventLogger):
|
||||||
self.config = config
|
|
||||||
self.logger = logger
|
|
||||||
required_keys = [
|
required_keys = [
|
||||||
'bot_token',
|
'bot_token',
|
||||||
'signing_secret',
|
'signing_secret',
|
||||||
@@ -102,13 +100,20 @@ class SlackAdapter(abstract_platform_adapter.AbstractMessagePlatformAdapter):
|
|||||||
if missing_keys:
|
if missing_keys:
|
||||||
raise command_errors.ParamNotEnoughError('Slack机器人缺少相关配置项,请查看文档或联系管理员')
|
raise command_errors.ParamNotEnoughError('Slack机器人缺少相关配置项,请查看文档或联系管理员')
|
||||||
|
|
||||||
self.bot = SlackClient(
|
bot = SlackClient(
|
||||||
bot_token=self.config['bot_token'],
|
bot_token=config['bot_token'],
|
||||||
signing_secret=self.config['signing_secret'],
|
signing_secret=config['signing_secret'],
|
||||||
logger=self.logger,
|
logger=logger,
|
||||||
unified_mode=True
|
unified_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
config=config,
|
||||||
|
logger=logger,
|
||||||
|
bot=bot,
|
||||||
|
bot_account_id=config['bot_token'],
|
||||||
|
)
|
||||||
|
|
||||||
async def reply_message(
|
async def reply_message(
|
||||||
self,
|
self,
|
||||||
message_source: platform_events.MessageEvent,
|
message_source: platform_events.MessageEvent,
|
||||||
|
|||||||
Reference in New Issue
Block a user