# @vonage/vc-messages

> vc-messages Web Component to be used with the Vonage Client JS SDK following open-wc recommendations

Latest version **2.3.0** (published 2024-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @vonage/vc-messages
pnpm add @vonage/vc-messages
yarn add @vonage/vc-messages
bun add @vonage/vc-messages
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2024-07-28 |
| First published | 2021-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 266.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vonage |
| Maintainers | mprabhu1, gpojula, omrizilber, elimenko.vonage, thealmoggvonage, saurabh.vonage, aviadhouri.va, daniel-sapir, llihovodov, tabdullah, jmoramunoz2, sailusha, hilakl, leppelin, molszewski_v, twilliams253, abolles, lallen2, yonatan.kra, jtiet, vonage-frontier, vonage_client_media_processing, or.cpc, jeffswartz, deliajolt, liranbin, javiermolsanz, v-kpheng, vgai-dev, web-il, iceberg-team, unified_portal, vreporter-npm, vbcbe, voxip_team, yuri.guller, idanvon, nexmo-devrel, vvd, vonagemeetings, vonage-jenkins, maikthomas, arivonage |
| Keywords | web, component, client, sdk, chat, ui, vonage |

## Links

- npm: https://www.npmjs.com/package/@vonage/vc-messages
- Repository: https://github.com/Vonage-Community/web_components-chat_sdk-javascript
- Homepage: https://github.com/Vonage-Community/web_components-chat_sdk-javascript#readme
- Issues: https://github.com/Vonage-Community/web_components-chat_sdk-javascript/issues
- npm.io page: https://npm.io/package/@vonage/vc-messages

## Dependencies (1)

- [lit](https://npm.io/package/lit.md) ^3.1.2

## Alternatives

- [@progress/kendo-ooxml](https://npm.io/package/@progress/kendo-ooxml.md) — 152.1K weekly downloads
- [@progress/kendo-react-ripple](https://npm.io/package/@progress/kendo-react-ripple.md) — 8.0K weekly downloads
- [@progress/kendo-react-orgchart](https://npm.io/package/@progress/kendo-react-orgchart.md) — 4.3K weekly downloads
- [@praxisui/dynamic-fields](https://npm.io/package/@praxisui/dynamic-fields.md) — 2.4K weekly downloads
- [@progress/kendo-vue-listbox](https://npm.io/package/@progress/kendo-vue-listbox.md) — 932 weekly downloads

## Recent versions

- 2.3.0 (latest) — 2024-07-28
- 2.2.0 — 2024-07-28
- 2.1.0 — 2024-07-24
- 2.0.0 — 2024-04-05
- 1.0.2 — 2023-02-13
- 1.0.1 — 2022-06-09
- 1.0.0 — 2021-09-20
- 0.0.7 — 2021-09-17
- 0.0.5 — 2021-07-01
- 0.0.1 — 2021-07-01
- 0.0.0 — 2021-03-29

## README

# \<vc-messages>

This Web Component follows the [open-wc](https://github.com/open-wc/open-wc) recommendation and is meant to be used with the [Vonage Client SDK In-App Messaging](https://developer.vonage.com/en/vonage-client-sdk/in-app-messaging/overview).

A goal is to simplify the code needed to create a chat room quickly. Please see the Creating a chat app [tutorial](https://developer.vonage.com/en/tutorials/vg-in-app-messaging?source=vonage-client-sdk) to see an implementation using Vanilla JavaScript.

This Web Component can be used to replace a part of the Chat app UI.

## Installation

```bash
npm i @vonage/vc-messages
```

## Usage

```html
<script type="module">
  import '@vonage/vc-messages/vc-messages.js';
</script>

<vc-messages></vc-messages>
```

### Attributes that can be used (optional):

- `loadPreviousMessages` : set to load any previous messages in the conversation. Default behavior is to load no previous messages.
- `filter` : set to filter for only the events you want to load. Default is ['message','member:joined','member:left','member:invited']

```html
<vc-messages loadPreviousMessages="10" filter='["message"]'></vc-messages>
```

The `vc-messages` Web Component can handle all its responsibilities in a Conversation.

First, get a reference to the element:
```js
const vcMessages = document.querySelector("vc-messages");
```

Then, pass the Conversation object to the Web Component:
```js
vcMessages.client = client;
vcMessages.conversationId = conversationId;
```
> **Note:** To see where `conversationId` and `client` came from, see [step 4](https://developer.vonage.com/en/tutorials/vg-in-app-messaging/create-conversation/javascript) and [step 11](https://developer.vonage.com/en/tutorials/vg-in-app-messaging/join-conversation/javascript) in the [tutorial](https://developer.vonage.com/en/tutorials/vg-in-app-messaging/introduction/javascript).

## Styling

By default, there are no styles applied to the Web Component.

The `vc-messages` component uses [CSS part](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) to apply custom styles.

Here are two diagram that labels the parts of the component as well as the default style:

![Diagram labeling the parts of the component](vc-messages-style-diagram-1.jpg "Diagram labeling the parts of the component")

To style the overall message, the part is "message". To style the application user's message, the part to target is "message mine".

![Diagram labeling the parts of each message-text of the component](vc-messages-style-diagram-2.jpg "Diagram labeling the parts of each message-text of the component")

![Diagram labeling the parts of each message-image of the component](vc-messages-style-diagram-3.jpg "Diagram labeling the parts of each message-image of the component")

Each message is made up of the text (part is "message-text") or image (part is "message-image"), and their name (part is "username"). To specifically style the application user's message text, target "message-text mine" or for message image, target "message-image mine". For their name, the target would be "username mine".

To style the image itself, the part is "image". To target the user's image, the part is "image mine".

To get the styling shown in the image:

```css
vc-messages {
  height: 300px;
}

vc-messages::part(message) {
  padding: 15px;
  margin: 5px;
}

vc-messages::part(message mine) {
  text-align: right;
}

vc-messages::part(message-text) {
  border-radius: 6px;
  background-color: #f0f0f0;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px 6px 6px 0;
  font-size: 1.4rem;
}

vc-messages::part(message-text mine) {
  background-color: #e0e0ff;
  border-radius: 6px 6px 0px 6px;
}

vc-messages::part(message-image) {
  background-color: #f0f0f0;
  display: inline-block;
  padding: 8px;
  border-radius: 6px 6px 6px 0;
  font-size: 1.4rem;
  width: 100%;
  max-width: 250px;
}

vc-messages::part(message-image mine) {
  background-color: #e0e0ff;
  border-radius: 6px 6px 0px 6px;
}

vc-messages::part(username) {
  font-size: 1.2rem;
}

vc-messages::part(username mine) {
  text-align: right;
  color: black;
}
```

Another example could be:
```css
vc-messages {
  background-color: red;
  height: 300px;
}

vc-messages::part(message) {
  background-color: green;
  border-radius: 20px 20px 20px 0;
}

vc-messages::part(message mine) {
  text-align: left;
  background-color: royalblue;
  border-radius: 20px 20px 0 20px;
  border: 0;
}

vc-messages::part(message-text) {
  background-color: yellow;
  border-radius: 20px 20px 20px 0;
}

vc-messages::part(message-text mine) {
  background-color: purple;
  color: white;
  font-style: italic;
  border-radius: 20px 20px 0 20px;
}

vc-messages::part(message-image) {
  background-color: yellow;
  display: inline-block;
  padding: 8px;
  border-radius: 6px 6px 6px 0;
  font-size: 1.4rem;
  width: 100%;
  max-width: 250px;
}

vc-messages::part(message-image mine) {
  background-color: purple;
  border-radius: 6px 6px 0px 6px;
}

vc-messages::part(username) {
  color: white;
}

vc-messages::part(username mine) {
  text-align: right;
  font-style: italic;
  color: black;
}
```

## Tooling configs

For most of the tools, the configuration is in the `package.json` to minimize the amount of files in your project.

If you customize the configuration a lot, you can consider moving them to individual files.

## Local Demo with `web-dev-server`

```bash
npm start
```

To run a local development server that serves the basic demo located in `demo/index.html`

---
_Source: https://npm.io/package/@vonage/vc-messages · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
