跳到内容
Yuva chat hook菜单

Yuva chat hook

A React hook over the useyuva headless client for live chat: the session, conversation list, one thread with realtime messages, typing, read state, sending text and files, rating and attachment download. Labels with English defaults.

loading

    预览使用示例数据运行,不需要网络,也不需要渠道。

    安装

    在 shadcn 项目中运行。文件会复制到你自己的代码里。

    Shell
    npx shadcn@latest add https://useyuva.com/r/use-yuva-chat.json

    用法

    tsx
    import { useYuvaChat } from "@/hooks/use-yuva-chat"
    
    const chat = useYuvaChat({ server, channel })

    Props

    UseYuvaChatOptions

    Prop类型
    server?string
    channel?string
    client?YuvaClient
    identityToken?IdentityTokenSource | null
    helpArticleId?string

    YuvaChatState

    Prop类型
    loadingboolean
    errorunknown
    inboxClientInbox | null
    contactClientContact | null
    connectionConnectionState["state"]
    conversationsClientConversation[]
    hasMoreConversationsboolean
    loadMoreConversations() => Promise<void>
    activeIdstring | null
    conversationClientConversation | null
    open(id: string | null) => Promise<void>
    removedboolean
    threadLoadingboolean
    messagesYuvaChatMessage[]
    hasEarlierboolean
    loadEarlier() => Promise<void>
    typingClientMessage["author"] | null
    memberReadAtstring | null
    send(input: YuvaChatSendInput) => Promise<void>
    retry(id: string) => Promise<void>
    discard(id: string) => void
    setTyping(on: boolean) => void
    markRead() => Promise<void>
    rate(rating: Rating, comment?: string) => Promise<void>
    openAttachment(attachment: ClientAttachment) => Promise<void>
    saveEmail(email: string) => Promise<void>

    依赖

    安装此项时还会添加以下内容。

    npm 包