CharacterAI
  • 👋Welcome
  • 🧑‍💻Quick Start
  • 🛠️API
    • 🔑 Values
    • ⚠️ Errors
    • connect
    • ping
    • user
      • info
      • get_profile
      • followers
      • following
      • recent
      • update
    • post
      • get_post
      • my_posts
      • get_posts
      • upvote
      • undo_upvote
      • send_comment
      • delete_comment
      • create
      • delete
      • get_topics
      • feed
    • character
      • create
      • update
      • trending
      • recommended
      • categories
      • info
      • search
      • voices
    • chat
      • create_room
      • rate
      • next_message
      • get_histories
      • get_history
      • get_chat
      • send_message
      • delete_message
      • new_chat
    • chat2
      • next_message
      • send_message
      • get_histories
      • new_chat
      • get_chat
      • get_history
      • rate
      • delete_message
  • 📚Examples
    • Chatting
    • Parse Chat
  • ⚠️Issues
Powered by GitBook
On this page
  1. Examples

Parse Chat

Showing the entire chat

from characterai import PyCAI

client = PyCAI('TOKEN')

history = client.chat.get_history('HISTORY_ID')

for h in history['messages']:
    name = h['src_char']['participant']['name']
    text = h['text']

    print(f'{name}: {text}')
import asyncio
from characterai import PyAsyncCAI

async def main():
    client = PyAsyncCAI('TOKEN')

    history = await client.chat.get_history('HISTORY_ID')

    for h in history['messages']:
        name = h['src_char']['participant']['name']
        text = h['text']

        print(f'{name}: {text}')

asyncio.run(main())
PreviousChattingNextIssues

Last updated 1 year ago

📚