# Events

# agent.connected

Event is sent to all connected clients of all agents when new agent was connected to server.

interface AgentConnectedEvent {
    id: string
    status: string
    groups: string[]
    email: string
    nickname: string
    fullname: string
    description: string
    avatar: string
    connectedAt: string
}

Example

{
  "id": "3456",
  "status": "online",
  "groups": [],
  "email": "dusan@smartsupp.com",
  "nickname": "morlok",
  "fullname": "Dusan Kmet",
  "description": "I am awesome!",
  "avatar": "https://files.smartsuppcdn.com/files/agents/63jdada.png",
  "connectedAt": "2019-10-04T14:03:21.877Z"
}

# agent.updated

Event is sent to all connected clients of all agents when some agent properties or status was changed.

interface AgentUpdatedEvent {
    id: string
    changes: {
        status?: string
        groups?: Array<string>
        email?: string
        nickname?: string
        fullname?: string
        descriptin?: string
        avatar?: string
    }
}

Example

{
  "id": "86665",
  "changes": {
    "nickname": "John Doe",
    "status": "offline"
  }
}

# agent.disconnected

Event is sent to all connected clients of all agents when the agent lost all connections to server and is no longer considered as online.

interface AgentDisconnectedEvent {
    id: string
}

Example

{
  "id": "86665"
}

# visitor.connected

Event is sent to all connected clients of agents matching group when new visitor was connected to server.

Example

{
  "id": "viJqfKK4RIOh",
  "persisted": true,
  "status": "active",
  "chatId": null,
  "contactId": null,
  "createdAt": "2019-10-04T14:03:21.877Z",
  "connectedAt": "2019-10-04T14:03:21.878Z",
  "lang": null,
  "name": "Mya Rosenbaum",
  "email": null,
  "note": null,
  "bannedAt": null,
  "domain": "maida.com",
  "pageUrl": "https://maida.com",
  "referer": null,
  "locIp": "160.149.222.10",
  "locCode": "us",
  "locCountry": "United States",
  "locCity": "Fort Huachuca",
  "viewsCount": 1,
  "chatsCount": 0,
  "visitsCount": 25,
  "servedBy": [],
  "userAgent": "Mozilla/5.0 (Windows; U; Windows NT 6.2) AppleWebKit/534.2.0 (KHTML, like Gecko) Chrome/27.0.816.0 Safari/534.2.0",
  "browser": "Chrome",
  "browserVersion": "27.0.816.0",
  "platform": "Microsoft Windows",
  "os": "Windows 8",
  "variables": {
    "account_id": "282921"
  }
}

# visitor.updated

Event is sent to all connected clients of agents matching group when some visitor properties or status was changed. Common changes are pageUrl, pageTitle, email, name, variables.

interface VisitorUpdatedEvent {
    id: string
    changes: Partial<Visitor>
}

Example

{
  "id": "viJqfKK4RIOh",
  "changes": {
    "pageUrl": "https://www.smartsupp.com/pricing",
    "pageTitle": "Pricing"
  }
}

# visitor.disconnected

Event is sent to all connected clients of agents matching group when the visitor lost all connections to server and is no longer considered as online.

interface VisitorDisconnectedEvent {
    id: string
}

Example

{
  "id": "viJqfKK4RIOh"
}

# chat.agent_joined

Event is sent to all connected clients of agents matching group when some agent joined to chat.

interface ChatAgentJoinedEvent {
    chatId: string
    agent: AgentInfo
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "agent": {
    "id": "345111",
    "status": "online",
    "nickname": "morlok",
    "fullname": "Dusan Kmet",
    "description": "I am awesome!",
    "avatar": "https://files.smartsuppcdn.com/files/agents/63jdada.png",
    "groups": []
  },
  "message": {
    "id": "G262U5Hvhk",
    "type": "event",
    "subType": "system",
    "channel": {
      "type": "default",
      "id": null
    },
    "chatId": "co2wgLaNKxtOe",
    "visitorId": "viJqfKK4RIOh",
    "groupId": null,
    "agentId": null,
    "triggerId": null,
    "createdAt": "2019-10-09T17:08:46.371Z",
    "content": {
      "type": "agent_join",
      "text": null,
      "data": { "agentId": "7" }
    },
    "tags": [],
    "deliveryStatus": null,
    "deliveryTo": null,
    "deliveredAt": null,
    "deliveryFailReason": null
  }
}

# chat.agent_leaved

Event is sent to all connected clients of agents matching group when some agent leaved from chat.

interface ChatAgentLeavedEvent {
    chatId: string
    agent: AgentInfo
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "agent": {
    "id": "345111",
    "status": "online",
    "nickname": "morlok",
    "fullname": "Dusan Kmet",
    "description": "I am awesome!",
    "avatar": "https://files.smartsuppcdn.com/files/agents/63jdada.png",
    "groups": []
  },
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "event",
    "subType": "system",
    "channel": {
      "type": "default",
      "id": null
    },
    "chatId": "co2wgLaNKxtOe",
    "visitorId": "viJqfKK4RIOh",
    "groupId": null,
    "agentId": null,
    "triggerId": null,
    "createdAt": "2019-10-09T17:08:46.371Z",
    "content": {
      "type": "agent_leave",
      "text": null,
      "data": { "agentId": "7" }
    },
    "tags": [],
    "deliveryStatus": null,
    "deliveryTo": null,
    "deliveredAt": null,
    "deliveryFailReason": null
  }
}

# chat.agent_assigned

Event is sent to all connected clients of agents matching group.

interface ChatAgentAssignedEvent {
    chatId: string
    assigned: AgentInfo
    assignedBy: AgentInfo
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "assigned": {
    "id": "345111",
    "nickname": "morlok",
    "fullname": "Dusan Kmet",
    "description": "I am awesome!",
    "avatar": "https://files.smartsuppcdn.com/files/agents/63jdada.png",
    "groups": []
  },
  "assignedBy": {
    "id": "345112",
    "nickname": "john_doe",
    "fullname": "John Doe",
    "description": "I am awesome too!",
    "avatar": "https://files.smartsuppcdn.com/files/agents/63jdada.png",
    "groups": []
  },
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "event",
    "subType": "system",
    "channel": {
      "type": "default",
      "id": null
    },
    "chatId": "co2wgLaNKxtOe",
    "visitorId": "viJqfKK4RIOh",
    "groupId": null,
    "agentId": null,
    "triggerId": null,
    "createdAt": "2019-10-09T17:08:46.371Z",
    "content": {
      "type": "agent_assign",
      "text": null,
      "data": {
        "assigned": "345111",
        "assignedBy": "345112"
      }
    },
    "tags": [],
    "deliveryStatus": null,
    "deliveryTo": null,
    "deliveredAt": null,
    "deliveryFailReason": null
  }
}

# chat.agent_unassigned

Event is sent to all connected clients of agents matching group.

interface ChatAgentUnassignedEvent {
    chatId: string
    unassigned: AgentInfo
    unassignedBy: AgentInfo
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "unassigned": {
    "id": "345111",
    "status": "online",
    "nickname": "morlok",
    "fullname": "Dusan Kmet",
    "description": "I am awesome!",
    "avatar": "https://files.smartsuppcdn.com/files/agents/82jdDjw.png",
    "groups": []
  },
  "unassignedBy": {
    "id": "345112",
    "status": "online",
    "nickname": "john_doe",
    "fullname": "John Doe",
    "description": "I am awesome too!",
    "avatar": "https://files.smartsuppcdn.com/files/agents/63jdada.png",
    "groups": []
  },
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "event",
    "subType": "system",
    "channel": {
      "type": "default",
      "id": null
    },
    "chatId": "co2wgLaNKxtOe",
    "visitorId": "viJqfKK4RIOh",
    "groupId": null,
    "agentId": null,
    "triggerId": null,
    "createdAt": "2019-10-09T17:08:46.371Z",
    "content": {
      "type": "agent_unassign",
      "text": null,
      "data": {
        "unassigned": "345111",
        "unassignedBy": "345112"
      }
    },
    "tags": [],
    "deliveryStatus": null,
    "deliveryTo": null,
    "deliveredAt": null,
    "deliveryFailReason": null
  }
}

# chat.agent_read

Event is sent to all connected clients of agent who mark the chat as read. byId is id of agent who read. When this event is delivered num of unread messages of chat for agent is zero. Event is also sent to all connected clients of visitor related to chat.

interface ChatAgentRead {
    chatId: string
    lastReadAt: string
    byId: string
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "lastReadAt": "2019-10-04T14:03:21.877Z",
  "byId": "345111"
}

# chat.contact_read

Event chat.contact_read is sent to all connected clients of agents matching group. Based on this event agents can confirm that contact read or seen messages from agents.

interface ChatContactRead {
    chatId: string
    lastReadAt: string
    byId: null
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "lastReadAt": "2019-10-04T14:03:21.877Z",
  "byId": null
}

# chat.visitor_typing

Event chat.visitor_typing is sent to all connected clients of agents joined to chat when visitor start typing (typing.is is true), stop typing (typing.is is false) or visitor continue with typing and text is changing (typing.is is true and typing.text is string).

interface ChatVisitorTyping {
    chatId: string
    typing: {
        is: boolean
        text: string | null
    }
    visitor: {
        id: string
        name: string | null
    }
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "typing": {
    "is": true,
    "text": null
  },
  "visitor": {
    "id": "viJqfKK4RIOh",
    "name": null
  }
}

# chat.message_delivered

Event chat.message_delivered is sent to all connected clients of agents matching group, when email message is delivered to visitor's mailbox.

interface ChatMessageDelivered {
    chatId: string
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "message",
    "subType": "agent",
    "channel": {
      "type": "default",
      "id": "null"
    },
    "chatId": "co2wgLaNKxtOe",
    "groupId": null,
    "agentId": "82938",
    "visitorId": "viJqfKK4RIOh",
    "triggerId": null,
    "createdAt": "2019-09-29T16:03:54.316Z",
    "content": {
      "type": "text",
      "text": "Hello",
      "data": null
    },
    "tags": [],
    "deliveryStatus": "ok",
    "deliveryTo": "abc@smartsupp.com",
    "deliveredAt": "2019-09-29T16:03:54.316Z",
    "deliveryFailReason": null
  }
}

# chat.message_delivery_failed

Event chat.message_delivery_failed is sent to all connected clients of agents matching group, when email message failed delivery to visitor's mailbox. Failure can be caused by Mailgun or internal, but the event should be always sent.

interface ChatMessageDeliveryFailed {
    chatId: string
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "message",
    "subType": "agent",
    "channel": {
      "type": "default",
      "id": "null"
    },
    "chatId": "co2wgLaNKxtOe",
    "groupId": null,
    "agentId": "82938",
    "visitorId": "viJqfKK4RIOh",
    "triggerId": null,
    "createdAt": "2019-09-29T16:03:54.316Z",
    "content": {
      "type": "text",
      "text": "Hello",
      "data": null
    },
    "tags": [],
    "deliveryStatus": "permanent_fail",
    "deliveryTo": "abc@smartsupp.com",
    "deliveredAt": "2019-09-29T16:03:54.316Z",
    "deliveryFailReason": null
  }
}

# chat.message_received

Event chat.message_received is sent to all connected clients of agents matching group when visitor, agent or bot send message. Event is also send to agent who send message.

interface ChatMessageReceived {
    chatId: string
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "message",
    "subType": "agent",
    "channel": {
      "type": "default",
      "id": "null"
    },
    "chatId": "co2wgLaNKxtOe",
    "groupId": null,
    "agentId": "82938",
    "visitorId": "viJqfKK4RIOh",
    "triggerId": null,
    "createdAt": "2019-09-29T16:03:54.316Z",
    "content": {
      "type": "text",
      "text": "Hello",
      "data": null
    },
    "tags": [],
    "deliveryStatus": null,
    "deliveryTo": null,
    "deliveredAt": null,
    "deliveryFailReason": null
  }
}

# chat.message_seen

Event chat.message_seen is sent to all connected clients of agents matching group, when email message was opened by visitor in his mailbox.

interface ChatMessageSeen {
    chatId: string
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "message",
    "subType": "agent",
    "channel": {
      "type": "default",
      "id": "null"
    },
    "chatId": "co2wgLaNKxtOe",
    "groupId": null,
    "agentId": "82938",
    "visitorId": "viJqfKK4RIOh",
    "triggerId": null,
    "createdAt": "2019-09-29T16:03:54.316Z",
    "content": {
      "type": "text",
      "text": "Hello",
      "data": null
    },
    "tags": [],
    "deliveryStatus": "seen",
    "deliveryTo": "abc@smartsupp.com",
    "deliveredAt": "2019-09-29T16:03:54.316Z",
    "deliveryFailReason": null
  }
}

# chat.opened

Event chat.opened is sent to all connected clients of agents matching group when status of chat was changed to opened. It can happens when chat was closed and any of participants send new message or when chat has status pending (serving by bot) and now should be handled by agents.

interface ChatOpenedEvent {
    chatId: string
}

Example

{
  "chatId": "co2wgLaNKxtOe"
}

# chat.closed

Event chat.closed is sent to all connected clients of agents matching group when status of chat was changed to closed.

  • closeType can be visitor_close or agent_close or null when is closed automatically
interface ChatClosedEvent {
    chatId: string,
    closeType: string | null
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "closeType": "visitor_close",
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "event",
    "subType": "system",
    "channel": {
      "type": "default",
      "id": null
    },
    "chatId": "co2wgLaNKxtOe",
    "visitorId": "viJqfKK4RIOh",
    "groupId": null,
    "agentId": null,
    "triggerId": null,
    "createdAt": "2019-10-09T17:08:46.371Z",
    "content": {
      "type": "chat_close",
      "text": null,
      "data": null
    },
    "tags": [],
    "deliveryStatus": null,
    "deliveryTo": null,
    "deliveredAt": null,
    "deliveryFailReason": null
  }
}

# chat.rated

Event chat.rated is sent to all connected clients of agents matching group when visitor gave rating. Property text is optional and is null when visitor don't leave any comment. Rating value can be from 1 to 5 where 5 is best rating.

interface ChatRatedEvent {
    chatId: string
    rating: {
        value: number
        text: string | null
    }
    message: Message
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "rating": {
    "value": 5,
    "text": "Best support ever!"
  },
  "message": {
    "id": "msFw4w25g4Oa",
    "type": "event",
    "subType": "system",
    "channel": {
      "type": "default",
      "id": null
    },
    "chatId": "co2wgLaNKxtOe",
    "visitorId": "viJqfKK4RIOh",
    "groupId": null,
    "agentId": null,
    "triggerId": null,
    "createdAt": "2019-10-09T17:08:46.371Z",
    "content": {
      "type": "chat_rating",
      "text": null,
      "data": { "value": 5, "text": "Best support ever!" }
    },
    "tags": [],
    "deliveryStatus": null,
    "deliveryTo": null,
    "deliveredAt": null,
    "deliveryFailReason": null
  }
}

# chat.updated

Event chat.updated is sent to all connected clients of agents matching group when chat properties was updated. Reported are only changes of property important and groupId.

interface ChatUpdatedEvent {
    chatId: string
    changes: {
        important?: boolean
        groupId?: string | null
        contactId?: string
    }
}

Example

{
  "chatId": "co2wgLaNKxtOe",
  "changes": {
    "groupId": "kw92kdAs"
  }
}

# contact.updated

Event contact.updated is sent to all connected clients of agents matching group when some contact properties was changed. Common changes are name, note, phone.

interface ContactUpdatedEvent {
    id: string
    changes: Partial<Contact>
}

Example

{
  "id": "ct0yKCfPky6Y",
  "changes": {
    "name": "Bernard"
  }
}

# bulk

Event bulk aggregate multiple events. Bulk can contains events of visitor.connected, visitor.disconnected, visitor.updated.

Array<{
    item: string
    data: any
}>

Example

[
  {
    "name": "visitor.connected",
    "data": {...}
  },
  {
    "name": "visitor.disconnected",
    "data": {...}
  },
  {
    "name": "visitor.updated",
    "data": {...}
  }
]

# error

Event error is sent to connection where some interaction with socket server cause error. Usually it happens when client sending event request and dont provide callback to handle error.

interface ErrorEvent {
    message: string
    event?: string
    type?: string
}

Example

{
  "message": "Chat not found",
  "event": "chat.transfer",
  "type": "not_found"
}