To use the ChatDOC API, you have two options:
-
Directly call the ChatDOC RESTful API from your own service and custom the UI by yourself.
-
Use the
@chatdocai/chatdoc-sdk
to display documents(.pdf, .epub, .txt, .md, .html) and retrieve data by calling the ChatDOC RESTful API.Before using the API, you need to obtain an API Key on ChatDOC.com.
You can download ChatDOC-API-Demo to start your application.
git clone https://github.com/chatdoc-com/ChatDOC-API-Demo
The server folder is an node server, which request the ChatDOC RESTful API.
The client folder is a vue web app, which use
@chatdocai/chatdoc-sdk
to show the document, and request the node server.
Here are the steps to start the demo:
-
run
pnpm install
-
Set the env variable API_KEY.
API_KEY is the API key that you obtained after purchasing the API package or membership plan.
-
run
pnpm start
When using a self-signed certificate in your local development environment, you may encounter a browser prompt saying: 'This site can't provide a secure connection'. Please be aware that this is a specific situation in the local development environment and will not affect the use of your genuine SSL certificate when deployed online. For online deployment, you can use your own SSL certificate to ensure a secure connection.
By following these steps, you will have a simple ChatDOC API application.
If you only want to know how to use the @chatdocai/chatdoc-sdk
, you can refer to the ChatDOC Document Viewer section.
Here are some typical use cases of @chatdocai/chatdoc-sdk
in the demo that you might be interested in:
-
When you select text on the document and click the chat icon, you can obtain the
HTMLMaterialData
orPDFMaterialData
from the callback handler of EVENT_TYPES.CHAT_ICON_CLICKED event. Then, you can post it to the Ask Question API. -
The response from the Ask Question API contains the
source_info
field. You can convert thesource_info
to the data type of Source and use the drawSources method of@chatdocai/chatdoc-sdk
to navigate to the page of the sources and highlight them. -
By using the setFileUrl method of @chatdocai/chatdoc-sdk, you can switch the displayed document.