Sources: ~/.openclaw/skills, ~/.agents/skills, workshop-skills, workspace/skills
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""获取 tenant_access_token,同时暴露 app_id 和 bot_open_id。
|
|
用法:
|
|
python3 init_token.py → {"token": "..."}
|
|
python3 init_token.py --full → {"token": "...", "app_id": "...", "bot_open_id": "..."}
|
|
"""
|
|
import json, sys, os
|
|
from pathlib import Path
|
|
|
|
CONFIG = Path.home() / '.openclaw' / 'openclaw.json'
|
|
|
|
def read_config():
|
|
cfg = json.loads(CONFIG.read_text())
|
|
fs = cfg['channels']['feishu']
|
|
return fs['appId'], fs['appSecret'], fs.get('botOpenId', '')
|
|
|
|
def get_token():
|
|
aid, asc, _ = read_config()
|
|
import requests
|
|
r = requests.post(
|
|
'https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal',
|
|
json={'app_id': aid, 'app_secret': asc}
|
|
)
|
|
td = r.json()
|
|
if 'tenant_access_token' not in td:
|
|
print(json.dumps({'error': td}), file=sys.stderr)
|
|
sys.exit(1)
|
|
return td['tenant_access_token']
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
token = get_token()
|
|
result = {'token': token}
|
|
if '--full' in sys.argv:
|
|
aid, asc, bot_id = read_config()
|
|
result['app_id'] = aid
|
|
result['bot_open_id'] = bot_id
|
|
print(json.dumps(result))
|
|
except Exception as e:
|
|
print(json.dumps({'error': str(e)}), file=sys.stderr)
|
|
sys.exit(1)
|