# sawala

> Wrapper of Qiscus Chat SDK using the React framework. It's designed for Kata Internal needs.

Latest version **0.5.7** (published 2019-11-19) · Apache-2.0 license · 0 weekly downloads

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

## Install

```sh
npm install sawala
pnpm add sawala
yarn add sawala
bun add sawala
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.7 |
| Published | 2019-11-19 |
| First published | 2019-10-29 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kata.ai |
| Maintainers | ybdev |
| Keywords | chat-sdk, kata, react, typescript |

## Links

- npm: https://www.npmjs.com/package/sawala
- Repository: https://github.com/kata-ai/sawala
- Homepage: https://github.com/kata-ai/sawala#readme
- Issues: https://github.com/kata-ai/sawala/issues
- npm.io page: https://npm.io/package/sawala

## Dependencies (9)

- [moment](https://npm.io/package/moment.md) ^2.24.0
- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.15
- [@kata-kit/theme](https://npm.io/package/@kata-kit/theme.md) ^0.7.2
- [qiscus-sdk-core](https://npm.io/package/qiscus-sdk-core.md) ^2.8.33
- [@kata-kit/button](https://npm.io/package/@kata-kit/button.md) ^0.7.4
- [react-modal-image](https://npm.io/package/react-modal-image.md) ^2.5.0
- [styled-components](https://npm.io/package/styled-components.md) ^4.4.0
- [@kata-kit/dropdown](https://npm.io/package/@kata-kit/dropdown.md) ^0.7.4
- [react-confirm-alert](https://npm.io/package/react-confirm-alert.md) ^2.4.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.5.7 (latest) — 2019-11-19
- 0.5.6 — 2019-11-07
- 0.5.5 — 2019-11-03
- 0.5.4 — 2019-11-03
- 0.5.3 — 2019-11-02
- 0.5.1 — 2019-11-01
- 0.5.0 — 2019-11-01
- 0.4.0 — 2019-10-31
- 0.3.5 — 2019-10-31
- 0.3.4 — 2019-10-31
- 0.3.3 — 2019-10-30
- 0.3.2 — 2019-10-29
- 0.3.1 — 2019-10-29
- 0.3.0 — 2019-10-29
- 0.2.0 — 2019-10-29

## README

[![Build Status](https://travis-ci.org/kata-ai/sawala.svg?branch=master)](https://travis-ci.org/kata-ai/sawala)
[![Dependencies](https://david-dm.org/kata-ai/sawala.svg)](https://david-dm.org/kata-ai/sawala)
[![NPM Version](https://img.shields.io/npm/v/sawala.svg)](https://www.npmjs.com/package/sawala)

# Sawala

**Sawala** is an Wrapper of [Qiscus Chat SDK](https://github.com/qiscus/qiscus-sdk-web-core) using the React framework. It's designed for Kata Internal needs.

**Note: Sawala is still in beta.**

---

## Documentation

- [Introduction](./docs/introduction.md)
- [Getting Started](./docs/getting-started.md)
- [Contributing](./docs/contributing.md)

## Contributing

Sawala is developed by the help of developers like you! Please read our [Contributing Guidelines](CONTRIBUTING.md) to get started on developing Sawala.

This project is bound by a [Code of Conduct](CODE_OF_CONDUCT.md).

## Usage

### Install

```bash
# npm
$ npm install --save sawala

# yarn
$ yarn add sawala
```

### How to use

Sawala is built in React, you can use it like this example:

```jsx
import * as React from 'react';
import { SawalaChat } from 'sawala';
import { EmptyMessage } from '@kata-kit/common';

export default class Chat extends React.Component<Props> {
  renderEmptyRoom = () => {
    return (
      <EmptyMessage
        image={require('assets/images/no-page.svg')}
        title={'No chat selected'}
      >
        Please select chat first.
      </EmptyMessage>
    );
  };

  render() {
    return (
      <SawalaChat
        config={{
          autoConnect: true,
          appId: 'sdksample',
          user: {
            id: 'rohmad@kata.ai',
            password: 'q1w2e3r4',
            displayName: 'Rohmad from Kata.ai',
            avatar:
              'https://res.cloudinary.com/kata-ai/image/upload/v1572663263/sawala/kata_favicon-02_zzldhx.png'
          }
        }}
        onRendered={this.handleRendered}
        noSelectedComponent={this.renderEmptyRoom()}
        onClickDetailComment={this.handleClickDetailComment}
        loginSuccessCallback={this.handleloginSuccessCallback}
        newMessagesCallback={this.handlenewMessagesCallback}
      />
    );
  }
}
```

## Components

### SawalaChat

`SawalaChat` is the only component needed to use sawala. It will react dynamically to handle all features.

SawalaChat props:

| prop                 | type                                | required | description                                                                                         |
| -------------------- | ----------------------------------- | -------- | --------------------------------------------------------------------------------------------------- |
| config               | [AppConfig](#appconfig)             | yes      | App Configuration for setup to [Qiscus Web SDK Core](https://github.com/qiscus/qiscus-sdk-web-core) |
| onRendered           | function([QiscusCore](#qiscuscore)) | yes      | Callback after Sawala successfully rendered, for example you can call method `qiscus.getNonce()`    |
| newMessagesCallback  | function([messages](#messages))     | yes      | Callback when you are have a new messages incoming                                                  |
| onClickDetailComment | function([Comment](#comment))       | yes      | Callback when you click `Message Details` in your own message                                       |
| noSelectedComponent  | ReactElement                        | no       | React element for showing an empty state                                                            |
| headerComponent      | ReactElement                        | no       | React element for additional feature in Header. E.g: `Context menu`                                 |
| onSelectedRoom       | function([Selected](#selected))     | no       | Callback after selected room using method `window.qiscus.setSelected`                               |
| loginSuccessCallback | function([AuthData](#authdata))     | no       | Callback when you initiate to qiscus is success                                                     |

#### AppConfig

```jsx
export type User = {
  id: string,
  password: string,
  displayName: string,
  avatar?: string
};

export type AppConfig = {
  autoConnect: boolean | true,
  appId: string,
  user?: User | null
};
```

#### QiscusCore

QiscusCore is response from qiscus-sdk-web-core. Look like this:

```json
{
  "events": {},
  "rooms": [],
  "selected": null,
  "room_name_id_map": {},
  "pendingCommentId": 0,
  "uploadedFiles": [],
  "chatmateStatus": null,
  "version": "WEB_2.8.36",
  "userData": {},
  "AppId": "esl-9qaeayalt99fccowr",
  "baseURL": "https://api.qiscus.com",
  "uploadURL": "https://api.qiscus.com/api/v2/sdk/upload",
  "mqttURL": "wss://mqtt.qiscus.com:1886/mqtt",
  "HTTPAdapter": null,
  "realtimeAdapter": {},
  "customEventAdapter": {},
  "isInit": false,
  "isSynced": false,
  "syncInterval": 5000,
  "sync": "socket",
  "httpsync": null,
  "eventsync": null,
  "extras": null,
  "last_received_comment_id": 0,
  "googleMapKey": "",
  "options": { "avatar": true },
  "UI": {},
  "mode": "widget",
  "avatar": true,
  "plugins": [],
  "isLogin": false,
  "isLoading": false,
  "emoji": false,
  "isTypingStatus": "",
  "customTemplate": false,
  "templateFunction": null,
  "debugMode": false,
  "debugMQTTMode": false,
  "lastReceiveMessages": [],
  "_customHeader": {},
  "syncAdapter": { "events": {} }
}
```

#### AuthData

AuthData also is response from qiscus-sdk-web-core. Look like this:

```json
{
  "user": {
    "app": {
      "code": "esl-9qaeayalt99fccowr",
      "id": 8216,
      "id_str": "8216",
      "name": "esl"
    },
    "avatar": {
      "avatar": {
        "url": "https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/75r6s_jOHa/1507541871-avatar-mine.png"
      }
    },
    "avatar_url": "https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/75r6s_jOHa/1507541871-avatar-mine.png",
    "email": "esl-9qaeayalt99fccowr_admin@qismo.com",
    "extras": {},
    "id": 64061322,
    "id_str": "64061322",
    "last_comment_id": 0,
    "last_comment_id_str": "0",
    "last_sync_event_id": 0,
    "pn_android_configured": true,
    "pn_ios_configured": true,
    "rtKey": "somestring",
    "token": "PiJ8ndNiZwDI7pLONsFF1572018149",
    "username": "User from Kata.ai"
  }
}
```

#### Messages

Messages also is response from qiscus-sdk-web-core. Look like this:

```json
[
  {
    "chat_type": "group",
    "comment_before_id": 80343513,
    "comment_before_id_str": "80343513",
    "created_at": "2019-10-31T02:21:06.138008Z",
    "disable_link_preview": false,
    "email": "esl-9qaeayalt99fccowr_admin@qismo.com",
    "extras": {},
    "id": 80541844,
    "id_str": "80541844",
    "is_public_channel": false,
    "message": "Contoh pesan masuk",
    "payload": {},
    "raw_room_name": "Rohmad Sasmito",
    "room_avatar": "https://avatars3.githubusercontent.com/u/10769688?s=100",
    "room_id": 4947400,
    "room_id_str": "4947400",
    "room_name": "Rohmad Sasmito",
    "room_options": null,
    "room_type": "group",
    "status": "sent",
    "timestamp": "2019-10-31T02:21:06Z",
    "topic_id": 4947400,
    "topic_id_str": "4947400",
    "type": "text",
    "unique_temp_id": "bq1572488465709",
    "unix_nano_timestamp": 1572488466138008000,
    "unix_timestamp": 1572488466,
    "user_avatar": "https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/75r6s_jOHa/1507541871-avatar-mine.png",
    "user_avatar_url": "https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/75r6s_jOHa/1507541871-avatar-mine.png",
    "user_id": 64061322,
    "user_id_str": "64061322",
    "username": "User from Kata.ai"
  }
]
```

#### Selected

Selected also is response from qiscus-sdk-web-core. Look like this:

```json
{
  "id": 5000296,
  "last_comment_id": 81421286,
  "last_comment_message": "Jangan lupa makan mahal, minimal sehari sekali.",
  "avatar": "https://api.telegram.org/file/bot925192808:AAHfy0Y0pnVPk_n60w0I6zNJWl4bqzgFXOc/profile_photos/file_15.jpg",
  "name": "Rohmad from Kata.ai",
  "room_type": "group",
  "participants": [],
  "options": null,
  "topics": [],
  "comments": [],
  "count_notif": 0,
  "isLoaded": false,
  "unread_comments": [],
  "custom_title": null,
  "custom_subtitle": null,
  "unique_id": "6f5689f6-0aee-45f9-980f-6fa74eea70df",
  "isChannel": false,
  "participantNumber": 0
}
```

#### Comment

Comment also is response from qiscus-sdk-web-core. Look like this:

```json
{
  "id": 81365202,
  "before_id": 81363608,
  "message": "[file] https://d1edrlpyc25xu0.cloudfront.net/orgin-lg5ja1kyfcrid8r/raw/upload/yptF4THWmI/50727c5bd9eee40535166b73f6f706f5.jpg [/file]",
  "username_as": "User from Kata.ai",
  "username_real": "orgin-lg5ja1kyfcrid8r_admin@qismo.com",
  "date": "2019-11-01",
  "time": "19:48",
  "timestamp": "2019-11-01T12:48:18Z",
  "unique_id": "bq1572612497702",
  "avatar": "https://res.cloudinary.com/kata-ai/image/upload/v1572501422/klient/admin-avatar_2x_b39pbw.png",
  "room_id": 5000305,
  "isChannel": false,
  "unix_timestamp": 1572612498,
  "is_deleted": false,
  "isPending": false,
  "isFailed": false,
  "isDelivered": true,
  "isRead": true,
  "isSent": true,
  "attachment": null,
  "payload": {
    "url": "https://d1edrlpyc25xu0.cloudfront.net/orgin-lg5ja1kyfcrid8r/raw/upload/yptF4THWmI/50727c5bd9eee40535166b73f6f706f5.jpg.webp",
    "caption": "Ini makanan ku hari ini, anti murah-murah club",
    "file_name": "50727c5bd9eee40535166b73f6f706f5.jpg.webp",
    "size": 6678,
    "pages": 1,
    "encryption_key": ""
  },
  "status": "read",
  "type": "file_attachment",
  "subtype": null
}
```

## License

By default, the root level of this repo, as well as the demo site, are licensed under the [Apache 2.0 license](LICENSE). While most components use the same license, please note that some packages (like our assets package) may use a different license. Any overriding licenses for each package will be mentioned in the `LICENSE` file located at the root of each package.

Copyright (c) 2019 Kata.ai and/or contributors. All rights reserved.

## Maintainers

- Rohmad Sasmito ([@rohmad-st](https://github.com/rohmad-st)) – [Kata.ai](https://kata.ai)

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