Files
telegram-customer-bot/test_with_token.py
2025-11-01 21:58:31 +08:00

37 lines
1.2 KiB
Python

#!/usr/bin/env python3
import os
import asyncio
from claude_agent_sdk import ClaudeSDKClient
os.environ['ANTHROPIC_AUTH_TOKEN'] = 'cr_9792f20a98f055e204248a41f280780ca2fb8f08f35e60c785e5245653937e06'
async def test():
print('Testing claude-agent-sdk...')
try:
client = ClaudeSDKClient()
await client.connect()
info = await client.get_server_info()
print('Account info:', info.get('account'))
await client.query('Hello, reply with OK')
response_text = ''
async for chunk in client.receive_response():
chunk_str = str(chunk)
if 'AssistantMessage' in chunk_str:
import re
match = re.search(r"text='([^']*)'", chunk_str)
if match:
response_text += match.group(1)
if response_text:
print('SUCCESS! AI replied:', response_text)
await client.disconnect()
return True
except Exception as e:
print('FAILED:', e)
import traceback
traceback.print_exc()
return False
if __name__ == '__main__':
result = asyncio.run(test())
print('\nResult:', 'SUCCESS' if result else 'FAILED')