webgesture

1.0.3 • Public • Published

WebGesture

WebGesture is a customizable chat widget that can be integrated into any web application. It provides a seamless way to add a chat interface to your website, allowing users to interact with a chat assistant.

Features

  • Customizable chat UI styles
  • Real-time messaging with Socket.IO
  • Typing indicator
  • Responsive design
  • Event-driven actions

Installation

To install WebGesture, use npm:

npm install webgesture

Usage

HTML

To use WebGesture in a plain HTML file:

  1. Include the necessary scripts and styles in your HTML file:
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="stylesheet" href="styles.css" />
		<title>WebGesture</title>
	</head>
	<body>
		<div id="chat-container"></div>
		<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
		<script src="path/to/webgesture.js"></script>
		<script>
			const chat = new WebGesture({ serverUrl: "http://localhost:3000" });
			chat.initializeChat(document.getElementById("chat-container"));
		</script>
	</body>
</html>

React

To use WebGesture in a React application:

  1. Install the package:
npm install webgesture
  1. Import and use the component in your React application:
import React, { useEffect } from "react";
import WebGesture from "webgesture";

const App = () => {
	useEffect(() => {
		const chat = new WebGesture({ serverUrl: "http://localhost:3000" });
		chat.initializeChat(document.getElementById("chat-container"));
	}, []);

	return <div id="chat-container"></div>;
};

export default App;

Angular

To use WebGesture in an Angular application:

  1. Install the package:
npm install webgesture
  1. Import and use the component in your Angular application:
import { Component, AfterViewInit } from "@angular/core";
import WebGesture from "webgesture";

@Component({
	selector: "app-root",
	template: '<div id="chat-container"></div>',
	styleUrls: ["./app.component.css"],
})
export class AppComponent implements AfterViewInit {
	ngAfterViewInit() {
		const chat = new WebGesture({ serverUrl: "http://localhost:3000" });
		chat.initializeChat(document.getElementById("chat-container"));
	}
}

Vue

To use WebGesture in a Vue application:

  1. Install the package:
npm install webgesture
  1. Import and use the component in your Vue application:
<template>
	<div id="chat-container"></div>
</template>

<script>
import WebGesture from "webgesture";

export default {
	mounted() {
		const chat = new WebGesture({ serverUrl: "http://localhost:3000" });
		chat.initializeChat(document.getElementById("chat-container"));
	},
};
</script>

Custom Styles

You can customize the styles of the chat widget by passing a styles object in the configuration:

const chat = new WebGesture({
	serverUrl: "http://localhost:3000",
	styles: {
		chatButton: {
			backgroundColor: "#ff0000",
		},
		chatContainer: {
			width: "400px",
		},
	},
});

Handling Actions

You can listen for custom actions emitted by the chat assistant:

chat.onAction((action) => {
	console.log("Received action:", action);
	// Handle the action
});

Destroying the Chat

To clean up and disconnect the chat:

chat.destroy();

Package Sidebar

Install

npm i webgesture

Weekly Downloads

141

Version

1.0.3

License

MIT

Unpacked Size

81.1 kB

Total Files

11

Last publish

Collaborators

  • adilshaa