# vanilla-js-chat

> A tiny html chat using pure Javascript.

Latest version **1.1.4** (published 2019-12-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install vanilla-js-chat
pnpm add vanilla-js-chat
yarn add vanilla-js-chat
bun add vanilla-js-chat
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2019-12-19 |
| First published | 2019-12-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Bruno Casotto |
| Maintainers | brunocasotto |
| Keywords | chat, vanilla, javascript, pure |

## Links

- npm: https://www.npmjs.com/package/vanilla-js-chat
- Repository: https://github.com/BrunoCasotto/vanilla-js-chat
- Homepage: https://github.com/BrunoCasotto/vanilla-js-chat#readme
- Issues: https://github.com/BrunoCasotto/vanilla-js-chat/issues
- npm.io page: https://npm.io/package/vanilla-js-chat

## Recent versions

- 1.1.4 (latest) — 2019-12-19
- 1.1.3 — 2019-12-18
- 1.1.2 — 2019-12-17
- 1.1.1 — 2019-12-17
- 1.1.0 — 2019-12-17
- 1.0.3 — 2019-12-15
- 1.0.2 — 2019-12-15
- 1.0.1 — 2019-12-15
- 1.0.0 — 2019-12-15

## README

<h1 align="center"> vanilla-js-chat</h1>

<p align="center">
  <a href="https://travis-ci.com/BrunoCasotto/vanilla-js-chat"><img src="https://travis-ci.com/BrunoCasotto/vanilla-js-chat.svg?branch=master" alt="Build Status"></a>
  <a href="https://www.npmjs.com/package/vanilla-js-chat"><img src="https://img.shields.io/npm/v/vanilla-js-chat" alt="Version"></a>
  <a href="https://www.npmjs.com/package/vanilla-js-chat"><img src="https://img.shields.io/npm/l/vanilla-js-chat.svg" alt="License"></a>
  <a href="https://codecov.io/gh/BrunoCasotto/vanilla-js-chat"><img src="https://codecov.io/gh/BrunoCasotto/vanilla-js-chat/branch/master/graph/badge.svg" alt="CodeCov"></a></p>

A project developed in vanilla JavaScript that introduces a chat interface to a web page, without dependencies or message sending logic.

<img width="350" alt="" src="https://github.com/BrunoCasotto/vanilla-js-chat/blob/master/docs/chat_image.png">


## Getting start
Install:

``` npm i --save vanilla-js-chat ```

OR

```
<link href="https://unpkg.com/vanilla-js-chat@latest/dist/vanillaJsChat.css" rel="stylesheet" >
<script src="https://unpkg.com/browse/vanilla-js-chat@latest/dist/vanillaJsChat.min.js" />
```

Basic install

```
import 'vanilla-js-chat/dist/vanillaJsChat.css'
import VanillaJsChat from 'vanilla-js-chat'

VanillaJsChat.init()
```

In the current html you should add a div with especific ID

```
  <div id="vanilla-js-chat"></div>
```

If you want another id you should pass into a init funcion the custom ID created

```
<div id="my-project-chat"></div>
VanillaJsChat.init('my-project-chat')
```

## Send message

### ```addMessage``` method params

`name` - Sender name

`message` - Content message

`color` - The background color [green, blue, yellow, red]

`side` - The side wich the message will be aligned [right, left]

```VanillaJsChat.addMessage('John Doe', 'I`m baba yaga', 'red', 'right')```

## Get user message
The method `onSendMessage` receives a callback as parameter, every message send by a user this callback is called. As many callbacks as needed can be inserted.

```
  const storageMessage = ({ message }) => {
    database.save(message)
  }

  const replyMessage = ({ message }) => {
    const responseMessage = handleMessage(message)

    VanillaJsChat.addMessage('John Doe', responseMessage, 'red', 'right')
  }

  VanillaJsChat.onSendMessage(storageMessage) // first callback
  VanillaJsChat.onSendMessage(replyMessage) // second callback
````

## Close and remove instance
```VanillaJsChat.close()```

## Restart chat
```VanillaJsChat.restart()```

---
_Source: https://npm.io/package/vanilla-js-chat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
