1.2.1 • Published 1 year ago

simplest-chat-widget v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Simplest Chat Widget

npm version

Simplest Chat Widget is a lightweight and customizable chat widget library that allows you to easily add a chat feature to your web application. It's designed to be simple and easy to use, with minimal setup required.

Demo

Demo

Installation

CDN

<script type="module">
	import ChatWidget from "https://unpkg.com/simplest-chat-widget";

	ChatWidget.create();
</script>

NPM

npm install simplest-chat-widget
import ChatWidget from "simplest-chat-widget";

ChatWidget.create();

Methods

MethodDescription
createCreates the chat widget, that will be appended to the body
destroyRemoves the chat widget from the DOM
showShows the chat widget
hideHides the chat widget
sendToUserSends a message to the user

Types

export interface MessageType {
    // The message sent by the user
    message: string;
    // the Element that will contain the response
    answerEl: HTMLElement;
    // the history of the chat in a format that is suported by chatgpt-3.5-turbo messages
    history: Array<historyItem>;
    // Sets the loading state of the chat
    setLoading: ( isLoading: boolean ) => void
}

export interface historyItem {
    content: string;
    role: string;
}

Options

OptiondefaultTypeDescription
answer( message: MessageType ) => Promise\<string>This function is called when the user submits a message, it should return a promise that resolves with the answer
validate3 < message < 512(message) => Array\This function is called when the user submits a message, if it returns an array of errors, the errors will be displayed to the user,
onInputsqlInjection dummy(message) => Array\This function is called when the user presses a key in the textarea field if it returns an array of warnings, the warnings will be displayed to the user
agentNameassistantstringThis will be displayed on the chat header
agentAvatarUrlhttps://code-for-me.com/build/images/logo-code-md.svgstringThis will be displayed as the avatar of the agent on the chat header
stylesChatWidgetOptionsThe styles of the chat widget. all other styles can be changed by redefining the css classes

Styling

optiondefaultDescription
styles.openerBgColor#202123The background color of the chat opener
styles.openerFillColor#413e50The fill color of the chat opener
styles.chatBgColor#343541The background color of the chat
styles.chatTextColor#fffThe text color of the chat
styles.chatTextareaBgColor#514f60The background color of the textarea
styles.chatHeaderBgColor#202123The background color of the chat header
styles.chatButtonsBgColor#473f56The background color of the chat buttons
styles.chatTextareaColor#fffThe text color of the textarea
styles.loaderColor#9880ffThe color of the loader
styles.fontFamilysystem-ui, -apple-system, BlinkMacSystemFontThe font family of the chat
1.2.1

1 year ago

1.2.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago