Webchat server that talks to Courier.
To start chat session as new user:
sock = new WebSocket("ws://localhost:8070/wc/connect/7d62d551-3030-4100-a260-2d7c4e9693e7/");
sock.onclose = function (event) {
console.log("bye!");
};
sock.onmessage = function (event) {
console.log(event.data);
};
Can be used to start a new chat session as a new contact:
{
"type": "start_chat"
}
Or resume a chat session as an existing contact:
{
"type": "start_chat",
"chat_id": "65vbbDAQCdPdEWlEhDGy4utO"
}
Server will respond with a chat_started
or chat_resumed
event depending on whether the provided chat ID matches an
existing contact.
Creates a new incoming message from the client:
{
"type": "send_msg",
"text": "I need help!"
}
Acknowledges receipt an outgoing chat message to the client:
{
"type": "ack_chat",
"msg_id": 46363452
}
Requests message history for the current contact:
{
"type": "get_history",
"before": "2024-05-01T17:15:30.123456Z"
}
Server will repond with a history
event.
Updates the email address for the current contact:
{
"type": "set_email",
"email": "[email protected]"
}
A chat session for a new contact has been successfully started:
{
"type": "chat_started",
"chat_id": "65vbbDAQCdPdEWlEhDGy4utO"
}
A chat session for an existing contact has been successfully resumed:
{
"type": "chat_resumed",
"chat_id": "65vbbDAQCdPdEWlEhDGy4utO",
"email": "[email protected]"
}
A new outgoing chat event has been created and should be displayed. Thus far msg_out
is the only type sent.
{
"type": "chat_out",
"msg_out": {
"id": 34634,
"text": "Thanks for contacting us!",
"origin": "flow",
"time": "2024-05-01T17:15:30.123456Z"
}
}
{
"type": "chat_out",
"msg_out": {
"id": 34634,
"text": "Thanks for contacting us!",
"origin": "chat",
"user": {"id": 234, "name": "Bob McTickets", "email": "[email protected]", "avatar": "https://example.com/bob.jpg"},
"time": "2024-05-01T17:15:30.123456Z"
}
}
The client previously requested history with a get_history
command:
{
"type": "history",
"history": [
{
"msg_in": {
"id": 34632,
"text": "I need help!",
"time": "2024-04-01T13:15:30.123456Z"
}
},
{
"msg_out": {
"id": 34634,
"text": "Thanks for contacting us!",
"origin": "chat",
"user": {"id": 234, "name": "Bob McTickets", "email": "[email protected]", "avatar": "https://example.com/bob.jpg"},
"time": "2024-04-01T13:15:30.123456Z"
}
}
]
}