chip

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2025 License: AGPL-3.0, AGPL-3.0-or-later Imports: 14 Imported by: 0

README

🍟 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"
            }
        }
    ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(rt *runtime.Runtime, courier courier.Courier) *Service

func (*Service) CloseChat

func (s *Service) CloseChat(ctx context.Context, ch *models.Channel, contact *models.Contact) error

func (*Service) ConfirmDelivery

func (s *Service) ConfirmDelivery(ctx context.Context, ch *models.Channel, contact *models.Contact, itemID queue.ItemID) error

func (*Service) CreateMsgIn

func (s *Service) CreateMsgIn(ctx context.Context, ch *models.Channel, contact *models.Contact, text string) error

func (*Service) QueueMsgOut

func (s *Service) QueueMsgOut(ctx context.Context, ch *models.Channel, contact *models.Contact, msg *models.MsgOut) error

func (*Service) Start

func (s *Service) Start() error

func (*Service) StartChat

func (s *Service) StartChat(ctx context.Context, ch *models.Channel, chatID models.ChatID) (*models.Contact, bool, error)

func (*Service) Stop

func (s *Service) Stop()

func (*Service) Store

func (s *Service) Store() models.Store

Directories

Path Synopsis
cmd
chipserver command
core
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL