Runt the application using:
uvicorn app.main:app --reload
For local development, we can use websocat
:
websocat ws://127.0.0.1:8000/ws/chat -H "X-User-ID: 12345"
After establishing the connection, clients can start a new conversation by sending the following JSON message:
{
"type": "start_conversation"
}
Upon successful initiation, the server will respond with a message indicating the ID of the new conversation.
If clients have a conversation ID from a previous session and want to resume that conversation, they can send the following JSON message:
{
"type": "resume_conversation",
"conversationId": "[Your_Previous_Conversation_ID]"
}
Replace [Your_Previous_Conversation_ID] with the actual ID of the conversation you want to resume.
The server will respond, confirming the conversation's resumption or notifying the client if no matching conversation is found.
Once either a new conversation has been started or a previous one has been resumed, clients can send regular chat messages in the following format:
{
"sender": "[Sender_Type]",
"content": "[Your_Message_Content]"
}
Replace [Sender_Type] with the type of sender (e.g., user) and [Your_Message_Content] with the actual content of the message.
Clients should also be set up to receive messages from the server. This can include responses to their messages or any other information the server wishes to convey.