Skip to content

nyaruka/chip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a920c70 · Feb 12, 2025
Feb 10, 2025
Jun 17, 2024
Feb 12, 2025
Dec 13, 2024
Feb 12, 2025
Dec 13, 2024
May 24, 2024
Jun 5, 2024
Feb 12, 2025
Jan 6, 2025
Feb 7, 2025
Jun 18, 2024
Dec 13, 2024
Dec 13, 2024
Jun 18, 2024

Repository files navigation

🍟 Chip

Build Status

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);
};

Client Commands

start_chat

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.

send_msg

Creates a new incoming message from the client:

{
    "type": "send_msg",
    "text": "I need help!"
}

ack_chat

Acknowledges receipt an outgoing chat message to the client:

{
    "type": "ack_chat",
    "msg_id": 46363452
}

get_history

Requests message history for the current contact:

{
    "type": "get_history",
    "before": "2024-05-01T17:15:30.123456Z"
}

Server will repond with a history event.

set_email

Updates the email address for the current contact:

{
    "type": "set_email",
    "email": "bob@nyaruka.com"
}

Client Events

chat_started

A chat session for a new contact has been successfully started:

{
    "type": "chat_started",
    "chat_id": "65vbbDAQCdPdEWlEhDGy4utO"
}

chat_resumed

A chat session for an existing contact has been successfully resumed:

{
    "type": "chat_resumed",
    "chat_id": "65vbbDAQCdPdEWlEhDGy4utO",
    "email": "bob@nyaruka.com"
}

chat_out

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": "bob@nyaruka.com", "avatar": "https://example.com/bob.jpg"},
        "time": "2024-05-01T17:15:30.123456Z"
    }
}

history

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": "bob@nyaruka.com", "avatar": "https://example.com/bob.jpg"},
                "time": "2024-04-01T13:15:30.123456Z"
            }
        }
    ]
}