# @commt/node-sdk

> Ultimate chat kit nodejs sdk for web services

Latest version **0.1.0** (published 2023-12-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @commt/node-sdk
pnpm add @commt/node-sdk
yarn add @commt/node-sdk
bun add @commt/node-sdk
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-12-25 |
| First published | 2023-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Mesut KILINCASLAN |
| Maintainers | sedanur, crazycoder-io |
| Keywords | commt, commt-chat-sdk, commt-node-sdk, chat, nodejs, message, messanger, commt-nodejs, node-js-chat |

## Links

- npm: https://www.npmjs.com/package/@commt/node-sdk
- Repository: https://github.com/commt/commt-nodejs
- Homepage: https://commt.co/doc
- Issues: https://github.com/commt/commt-nodejs.git/issues
- npm.io page: https://npm.io/package/@commt/node-sdk

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^1.6.2
- [node-forge](https://npm.io/package/node-forge.md) ^1.3.1

## Recent versions

- 0.1.0 (latest) — 2023-12-25
- 0.0.1 — 2023-12-08

## README

# COMMT: Chat SDK for NodeJS

![NPM](https://img.shields.io/npm/l/%40commt%2Fnode-sdk?color=blue&style=for-the-badge)
![npm](https://img.shields.io/npm/v/%40commt%2Fnode-sdk?style=for-the-badge)
![npm](https://img.shields.io/npm/dw/%40commt%2Fnode-sdk?label=npm%20downloads&style=for-the-badge)
<!-- ![npm total downloads](https://img.shields.io/npm/dt/%40commt%2Fnode-sdk?label=Total%20NPM%20Downloads&style=for-the-badge) -->


<p align="center">
<img src="./src/assets/node-js-logo.png" width="300" />
</p>
<br />

Welcome to Commt's NodeJS package – the heart of secure chat functionalities for your NodeJS applications!
Commt is a versatile chat plugin designed to seamlessly integrate secure and customizable chat functionalities into your applications. Commt ensures a secure and reliable real-time communication experience for your users.



## Features
- Written in **TypeScript**
- Fully customizable pre-build components with plugins
- Multiple projects support with only one client configuration
- AES encryption as default and end-to-end (E2E) support
- Webhooks usage flexibility
- Customizable and easy to manage system messages
- `Typing`, `user online` and `message read` indicators
- Emoji keyboard and all emoji types support with plugins
- Hooks usage flexibility

## Installation

- NPM: `npm i -S @commt/node-sdk`
- Yarn: `yarn add @commt/node-sdk`

For detailed installation instructions and configuration options, please refer to our [documentation](https://commt.co/doc/nodejs#installation).

## Usage

Get started with Commt in just a few steps:

- Initialize Commt: Import the Commt module and init it in index file of your application then you can have a global instance of it by using `with` method.
- Access From Everywhere: Define once in the beginning of your application and set it as global to access all over the files of your application.
- Implement Secure Chat: Decrypt messages in your codebase, since Commt sends messages with encrypted format!

Check out our [documentation](https://commt.co/doc/nodejs#introduction) for comprehensive usage examples and API reference.

## Example

You can get client configs info from [Commt Dashboard](https://dashboard.commt.co)

**index.ts**
```
import { Commt } from "@commt/node-sdk";

// Initiate Commt in your app/index file
Commt.init({
  apiKey: "123456789?",
  projectId: "0987654321?",
  secret: "4k4hum6rfuvxorul94zimh55", // Must to be 16, 24 or 32 bytes
});

global.commt = Commt.with(); // Define it as a global variable
```

**chat.js**
```
router.post('/save-message', async (req, res) => {
    try {
        // Get encrypted message from req.body
        const { message: cipher, iv } = req.body;

        // Decrypt it by using commt and parse it to object
        const result = JSON.parse(commt.decrypt({ cipher, iv }));

        // Get required parameters from decrypted result
        const {roomId, message} = result;


        // Save message to your database
        await MessageModel.create({
            roomId,
            type: message.type,
            senderId: message.senderId,
            createdAt: message.createdAt,
            message: message.text,
        });

        // Return 200 status code
        res.status(200).send();
    } catch (err) {
        res.status(500).send(err.message);
    }
});
```
**room.ts**
```
router.post('/create-room', async (req, res) => {
    try {
        // Get array of string participants
        const { participants } = req.body;

        // Inform commt for newly created room by passing array of chatAuthIds of the users and get chatRoomAuthId field in return
        const chatRoomAuthId = commt.createRoom(participants.chatAuthIds);

        // Create new room with given data
        await RoomModel.create({
            roomId,
            chatRoomAuthId,
            participants: participants.ids,
            ...(communityAvatar && communityName && { communityAvatar, communityName})
        });

        // Return 200 status code
        res.status(200).send();
    } catch (err) {
        res.status(500).send(err.message);
    }
});
```

## Compatibility

Commt is compatible with:

- [React Native](https://commt.co/doc#react-native)
- [ReactJS](https://commt.co/doc#reactjs)
- [NodeJS](https://commt.co/doc#nodejs)

## Support and Feedback

For any questions, feedback or issues, feel free to reach out to us via <contact@commt.co>.

## License

[MIT](https://github.com/commt/commt-nodejs/blob/master/LICENSE)

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