Skip to content

Commit

Permalink
#feat: Made highcharts optional + refactoring
Browse files Browse the repository at this point in the history
* Made tables min-width to 100%
* Moved all the create nodes code to utils
* Extracted all the highcharts related code to highcharts.js
* Fixed README typo to have `table_data` which is expected by the code
* Moved prechat related code to prechat.js
* Added prettier with default formatting
* And finally, made highcharts optional
  • Loading branch information
su-docker committed Mar 14, 2024
1 parent d7fdde1 commit 97e3a26
Show file tree
Hide file tree
Showing 11 changed files with 1,646 additions and 442 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

Tarka Chat UI is a plug and play javascript library to integrate a chat assistant to your website in one line


## Usage

1. Incude the following script (hosted in CDN) in your html

```
<script src="https://d1fmfone96g0x2.cloudfront.net/tarka-chat-2.2.1.umd.js"></script>
```
Include highcharts library to generate charts by highcharts
```
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
```
```
<script src="https://d1fmfone96g0x2.cloudfront.net/tarka-chat-2.2.1.umd.js"></script>
```

Include highcharts library to generate charts by highcharts

```
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
```

2. Initialise the global `TarkaChat` component with options in any script tag

Expand Down Expand Up @@ -85,20 +85,25 @@ where,
"name": "IMAGE_NAME",
}
```

- _HighCharts config type:_

```
{
"type": "highchart-config",
"type": "highchart-config",
"high_chart_config": { highcharts_config_obj }
}
```

- _Table type:_

```
{
"type": "table",
"table-data": { "header":[],"rows":[{}] }
"type": "table",
"table_data": { "header":[],"rows":[{}] }
}
```

3. _Array containing one/multiple of above mentioned types:_
E.g.

Expand All @@ -123,7 +128,7 @@ Link: https://tarkalabs.github.io/tarka-chat/demo/

## Old versions

* v1.1 : https://d1fmfone96g0x2.cloudfront.net/tarka-chat-1.1.umd.js
* v1.0 : https://d1fmfone96g0x2.cloudfront.net/tarka-chat-1.1.umd.js
- v1.1 : https://d1fmfone96g0x2.cloudfront.net/tarka-chat-1.1.umd.js
- v1.0 : https://d1fmfone96g0x2.cloudfront.net/tarka-chat-1.1.umd.js

Check [release notes](RELEASE.md) for details
68 changes: 64 additions & 4 deletions dev/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,69 @@ function getPreChatScreen(onClose) {
async function sendMessage(message, optionalFiles) {
console.log(optionalFiles);
// Do API calls
await new Promise((resolve) => setTimeout(resolve, 3000));
// after getting response
return Promise.resolve("Recieved: " + message + ", Images count: " + optionalFiles?.length ?? 0);
await new Promise((resolve) => setTimeout(resolve, 1000));

// after getting response use any one of the following to simulate different types of responses
let textResponse = "This is a text response";
let textObjResponse = { type: "text", message: "hi tehreee" };
let fileObjResponse = {
type: "file",
name: "tarka trends",
link: "https://tarkalabs.com",
};
let imageObjResponse = {
type: "image",
name: "tarka logo",
link: "https://tarkalabs.com/assets/img/teamg2.94f91078.jpg",
};
let tableObjResponse = {
type: "table",
table_data: {
header: ["col1", "col2"],
rows: [
{ col1: "a", col2: 1 },
{ col1: "b", col2: 2 },
],
},
};
let blankTableObjResponse = {
type: "table",
table_data: {
header: ["col1", "col2"],
rows: [],
},
};
let highchartsResponse = {
type: "highchart-config",
high_chart_config: {
chart: {
type: "pie",
},
title: {
text: "Browsers market share",
},
series: [
{
name: "Brands",
data: [
{
name: "Chrome",
y: 70,
},
{
name: "Firefox",
y: 20,
},
{
name: "Others",
y: 10,
},
],
},
],
},
};
return Promise.resolve(highchartsResponse);
}

const chat = TarkaChat.init({
Expand All @@ -53,4 +113,4 @@ const chat = TarkaChat.init({
expand: true,
});

// chat.toggle(), chat.isOpen()
// chat.toggle(), chat.isOpen()
Loading

0 comments on commit 97e3a26

Please sign in to comment.