Skip to content

Commit 87d2c7f

Browse files
committed
Add web live chat docs.
1 parent d2cb9a5 commit 87d2c7f

File tree

11 files changed

+78
-35
lines changed

11 files changed

+78
-35
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ It's written in C# running on .Net Core that is full cross-platform framework, t
2727
* Support multiple LLM platforms (ChatGPT 3.5 / 4.0, PaLM 2, LLaMA 2, HuggingFace).
2828
* Allow multiple agents with different responsibilities cooperate to complete complex tasks.
2929
* Build, test, evaluate and audit your LLM agent in one place.
30-
* Support different open source UI [Chatbot UI](src/Plugins/BotSharp.Plugin.ChatbotUI/Chatbot-UI.md), [HuggingChat UI](src/Plugins/BotSharp.Plugin.HuggingFace/HuggingChat-UI.md).
30+
* Build-in Web Live Chat UI written in SvelteKit.
3131
* Abstract standard Rich Content data structure. Integrate with popular message channels like Facebook Messenger, Slack and Telegram.
3232
* Provide RESTful Open API and WebSocket real-time communication.
3333

@@ -38,7 +38,19 @@ It's written in C# running on .Net Core that is full cross-platform framework, t
3838
PS D:\> cd BotSharp
3939
PS D:\BotSharp\> dotnet run -p .\src\WebStarter
4040
```
41-
2. Run UI project, reference to [Chatbot UI](src/Plugins/BotSharp.Plugin.ChatbotUI/Chatbot-UI.md).
41+
42+
2. Run UI project, reference to [Web Live Chat](src/web-live-chat/README.md).
43+
```sh
44+
PS D:\> cd .\src\web-live-chat
45+
PS D:\> npm install --force
46+
PS D:\> npm run dev
47+
```
48+
49+
Access http://localhost:5010/chat/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a
50+
51+
![Alt text](./docs/static/screenshots/web-live-chat.png)
52+
53+
4254

4355
### Core Modules
4456

18.1 KB
Loading

src/WebStarter/Program.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using BotSharp.Abstraction.Users;
33
using BotSharp.Core;
44
using BotSharp.Core.Users.Services;
5+
using BotSharp.Plugin.ChatHub;
56
using Microsoft.AspNetCore.Authentication.JwtBearer;
67
using Microsoft.IdentityModel.Tokens;
78
using System.Text;
@@ -50,14 +51,14 @@
5051
builder.Services.AddCors(options =>
5152
{
5253
options.AddPolicy("MyCorsPolicy",
53-
builder =>
54-
{
55-
builder.AllowAnyOrigin()
54+
builder => builder.WithOrigins("http://localhost:5010")
5655
.AllowAnyMethod()
57-
.AllowAnyHeader();
58-
});
56+
.AllowAnyHeader()
57+
.AllowCredentials());
5958
});
6059

60+
builder.Services.AddSignalR();
61+
6162
var app = builder.Build();
6263

6364
// Configure the HTTP request pipeline.
@@ -79,4 +80,6 @@
7980
app.UseCors("MyCorsPolicy");
8081
#endif
8182

83+
app.MapHub<SignalRHub>("/chatHub");
84+
8285
app.Run();

src/WebStarter/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"BotSharp.Plugin.KnowledgeBase",
147147
"BotSharp.Plugin.Qdrant",
148148
"BotSharp.Plugin.PaddleSharp",
149-
// "BotSharp.Plugin.ChatHub",
149+
"BotSharp.Plugin.ChatHub",
150150
"BotSharp.Plugin.WeChat",
151151
// "BotSharp.Plugin.TelegramBots",
152152
// "BotSharp.Plugin.RoutingSpeeder",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"firstName": "Guest",
3+
"lastName": "Anonymous",
4+
"email": "[email protected]",
5+
"salt": "55f8fafcf829479ca97e635937440fee",
6+
"password": "3b459ae9988628d41f0362c499a768dd",
7+
"role": "client",
8+
"updatedTime": "2023-11-13T18:00:00Z",
9+
"createdTime": "2023-11-13T18:00:00Z",
10+
"id": "10d12798-08fb-4aa6-977b-5dd94d82dbfe"
11+
}

src/web-live-chat/README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
# create-svelte
2-
3-
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
4-
5-
## Creating a project
6-
7-
If you're seeing this, you've probably already done this step. Congrats!
8-
9-
```bash
10-
# create a new project in the current directory
11-
npm create svelte@latest
12-
13-
# create a new project in my-app
14-
npm create svelte@latest my-app
15-
```
16-
171
## Developing
182

193
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

src/web-live-chat/src/lib/services/api-endpoints.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const host = 'http://localhost:5500';
22

33
// user
44
export const tokenUrl = `${host}/token`;
5+
export const myInfoUrl = `${host}/user/my`;
56
export const usrCreationUrl = `${host}/user`;
67

78
// plugin

src/web-live-chat/src/lib/services/auth-service.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { userStore, getUserStore } from '$lib/helpers/store.js';
2-
import { tokenUrl, usrCreationUrl } from './api-endpoints.js';
2+
import { tokenUrl, myInfoUrl, usrCreationUrl } from './api-endpoints.js';
33

44
/**
55
* This callback type is called `requestCallback` and is displayed as a global symbol.
@@ -36,6 +36,34 @@ export async function getToken(email, password, onSucceed) {
3636
.catch(error => alert(error.message));
3737
}
3838

39+
/**
40+
* @param {string} token
41+
* @returns {Promise<import('$typedefs').UserModel>}
42+
*/
43+
export async function myInfo(token) {
44+
const headers = {
45+
Authorization: `Bearer ${token}`,
46+
};
47+
48+
const info = await fetch(myInfoUrl, {
49+
method: 'GET',
50+
headers: headers,
51+
}).then(response => {
52+
if (response.ok) {
53+
return response.json();
54+
} else {
55+
alert(response.statusText);
56+
}
57+
}).then(result => {
58+
let user = getUserStore();
59+
userStore.set({ ...user, init: false, id: result.id });
60+
return result;
61+
})
62+
.catch(error => alert(error.message));
63+
64+
return info;
65+
}
66+
3967
/**
4068
* @param {string} firstName
4169
* @param {string} lastName

src/web-live-chat/src/routes/chat/[agentId]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
userToken = token;
2323
});
2424
} else {
25-
userToken = $page.url.searchParams.get('token');
25+
userToken = $page.url.searchParams.get('token') ?? "unauthorized";
2626
}
2727
setAuthorization(userToken);
2828
conversation = await newConversation(params.agentId);

0 commit comments

Comments
 (0)