# Chat API, Live Chat and approvals from Node.js

> A server SDK with no dependencies for the Hibira products the pusher package does not cover: the Chat API, Live Chat verified visitors with Express, Fastify and Koa middleware, and Approvals.

Source: https://hibira.io/guides/node-sdk

A server SDK with no dependencies for the Hibira products the pusher package does not cover: the Chat API, Live Chat verified visitors with Express, Fastify and Koa middleware, and Approvals.

Package: @hibira-io/node

- hibira.chat creates conversations, posts as a member, reads history and marks messages read.
- Express, Koa and Fastify middleware put the Live Chat widget on your pages with signed-in users verified.
- hibira.approvals asks a person for a decision and waits for the answer; verifyApprovalCallback() checks signed callbacks.

## 1. Install

```shell
npm install @hibira-io/node
```

## 2. Set it up

```shell
HIBIRA_APP_ID=YOUR_APP_ID
HIBIRA_KEY=YOUR_APP_KEY
HIBIRA_SECRET=YOUR_APP_SECRET
HIBIRA_HOST=ws.hibira.io
HIBIRA_LIVECHAT_WORKSPACE=YOUR_WORKSPACE_ID
HIBIRA_LIVECHAT_IDENTITY_SECRET=YOUR_IDENTITY_SECRET
```

## 3. Use it

```ts
import { createHibira } from '@hibira-io/node';

const hibira = createHibira();

// Live Chat on every page, signed-in users verified: <%- hibiraLiveChat.scriptTag %>
app.use(hibira.liveChat.express({ getUser: (req) => req.user && { id: req.user.id, name: req.user.name } }));

await hibira.chat.putConversation('order-1042', { members: ['buyer-7', 'seller-3'] });
await hibira.chat.sendMessage('order-1042', 'seller-3', 'Shipped today!');

const ask = await hibira.approvals.request({ title: 'Refund order #1042 for $89?', options: ['Refund', 'Decline'] });
const answer = await hibira.approvals.wait(ask.approval_id, { timeout: 600 });
```

## Before you start

- The app secret is shown only once, when you create the app or rotate its secret. Keep it on your server, never in a browser or game build.
- For realtime events and channel auth, use the pusher npm package pointed at your Hibira host; for waiting rooms, @hibira-io/waiting-room.

- [npm](https://www.npmjs.com/package/@hibira-io/node)
- [GitHub](https://github.com/hibira-io/node)
