diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs
index 3d82500c..230a3f2d 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs
@@ -81,4 +81,9 @@ public abstract class ConversationHookBase : IConversationHook
{
return Task.CompletedTask;
}
+
+ public virtual Task OnUserAgentConnectedInitially(Conversation conversation)
+ {
+ return Task.CompletedTask;
+ }
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs
index 890fca04..e2531438 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs
@@ -10,6 +10,14 @@ public interface IConversationHook
Conversation Conversation { get; }
IConversationHook SetConversation(Conversation conversation);
+ ///
+ /// Triggered when user connects with agent first time.
+ /// This hook is the good timing to show welcome infomation.
+ ///
+ ///
+ ///
+ Task OnUserAgentConnectedInitially(Conversation conversation);
+
///
/// Triggered once for every new conversation.
///
diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs
index c475d6a5..7774cf50 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs
@@ -5,6 +5,7 @@ public interface IConversationService
IConversationStateService States { get; }
string ConversationId { get; }
Task NewConversation(Conversation conversation);
+ Task MarkConnectionReady(string conversationId);
void SetConversationId(string conversationId, List states);
Task GetConversation(string id);
Task> GetConversations();
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs
index 0fce3f4c..3f61bc8d 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/IRichMessage.cs
@@ -2,5 +2,6 @@ namespace BotSharp.Abstraction.Messaging;
public interface IRichMessage
{
+ string Type { get; }
string Text { get; set; }
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs
index b0081c81..4fb1bcdb 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/QuickReplyMessage.cs
@@ -1,8 +1,8 @@
namespace BotSharp.Abstraction.Messaging.Models.RichContent
{
- public class QuickReplyMessage : IRichMessage
+ public class QuickReplyMessage : RichMessageBase, IRichMessage
{
- public string Text { get; set; } = string.Empty;
+ public override string Type => "quick reply";
[JsonPropertyName("quick_replies")]
public List QuickReplies { get; set; } = new List();
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplateMessage.cs
index 2ec5464e..93af426a 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplateMessage.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ButtonTemplateMessage.cs
@@ -3,12 +3,12 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
///
/// https://developers.facebook.com/docs/messenger-platform/send-messages/buttons
///
- public class ButtonTemplateMessage : IRichMessage
+ public class ButtonTemplateMessage : RichMessageBase, IRichMessage, ITemplateMessage
{
- public string Text { get; set; } = string.Empty;
+ public override string Type => "template";
[JsonPropertyName("template_type")]
- public string TemplateType => "button";
+ public override string TemplateType => "button";
public List Buttons { get; set; } = new List();
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs
index 8fb74efd..d4ab5fb0 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/CouponTemplateMessage.cs
@@ -4,15 +4,17 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
/// Coupon Template
/// https://developers.facebook.com/docs/messenger-platform/send-messages/template/coupon
///
-public class CouponTemplateMessage : IRichMessage, ITemplateMessage
+public class CouponTemplateMessage : RichMessageBase, IRichMessage, ITemplateMessage
{
- [JsonIgnore]
- public string Text { get; set; }
- public string Title { get; set; }
- public string Subtitle { get; set; }
+ public override string Type => "template";
[JsonPropertyName("template_type")]
- public string TemplateType => "coupon";
+ public override string TemplateType => "coupon";
+
+ [JsonIgnore]
+ public override string Text { get; set; }
+ public string Title { get; set; }
+ public string Subtitle { get; set; }
[JsonPropertyName("coupon_code")]
public string CouponCode { get; set; }
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplateMessage.cs
index df8e1183..a7b0e5ff 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplateMessage.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/MultiSelectTemplateMessage.cs
@@ -1,8 +1,8 @@
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
{
- public class MultiSelectTemplateMessage : IRichMessage
+ public class MultiSelectTemplateMessage : RichMessageBase, IRichMessage
{
- public string Text { get; set; } = string.Empty;
+ public override string Type => "template";
[JsonPropertyName("template_type")]
public string TemplateType => "multi-select";
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs
index bfbdcbb3..ccdd66a5 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/ProductTemplateMessage.cs
@@ -2,6 +2,7 @@ namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template;
public class ProductTemplateMessage : TemplateMessageBase, IRichMessage
{
+ [JsonPropertyName("template_type")]
public override string TemplateType => "product";
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs
index b2d568cc..ab2ecd66 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/Template/TemplateMessageBase.cs
@@ -1,12 +1,15 @@
namespace BotSharp.Abstraction.Messaging.Models.RichContent.Template
{
- public class TemplateMessageBase
+ public class TemplateMessageBase : RichMessageBase
{
[JsonIgnore]
public string Text { get; set; }
+ public override string Type => "template";
+
[JsonPropertyName("template_type")]
public virtual string TemplateType => string.Empty;
+
public T[] Elements { get; set; }
}
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs
index dfb611d3..a615318e 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/Models/RichContent/TextMessage.cs
@@ -1,8 +1,8 @@
namespace BotSharp.Abstraction.Messaging.Models.RichContent;
-public class TextMessage : IRichMessage
+public class TextMessage : RichMessageBase, IRichMessage
{
- public string Text { get; set; } = string.Empty;
+ public string Type => "text";
public TextMessage(string text)
{
diff --git a/src/Infrastructure/BotSharp.Abstraction/Messaging/RichMessageBase.cs b/src/Infrastructure/BotSharp.Abstraction/Messaging/RichMessageBase.cs
new file mode 100644
index 00000000..39c39b80
--- /dev/null
+++ b/src/Infrastructure/BotSharp.Abstraction/Messaging/RichMessageBase.cs
@@ -0,0 +1,11 @@
+namespace BotSharp.Abstraction.Messaging;
+
+public class RichMessageBase
+{
+ public virtual string Type { get; }
+
+ public virtual string Text { get; set; }
+
+ [JsonPropertyName("template_type")]
+ public virtual string TemplateType { get; }
+}
diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs
index 92084c78..874690b5 100644
--- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs
+++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs
@@ -84,6 +84,9 @@ public partial class ConversationService : IConversationService
var hooks = _services.GetServices().ToList();
foreach (var hook in hooks)
{
+ // If user connect agent first time
+ await hook.OnUserAgentConnectedInitially(sess);
+
await hook.OnConversationInitialized(record);
}
@@ -115,4 +118,15 @@ public partial class ConversationService : IConversationService
_state.Load(_conversationId);
states.ForEach(x => _state.SetState(x.Split('=')[0], x.Split('=')[1]));
}
+
+ public async Task MarkConnectionReady(string conversationId)
+ {
+ var hooks = _services.GetServices();
+ var conv = await GetConversation(conversationId);
+ foreach (var hook in hooks)
+ {
+ // Need to check if user connected with agent is the first time.
+ await hook.OnUserAgentConnectedInitially(conv);
+ }
+ }
}
diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs
index dde37482..97b10cd2 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs
@@ -41,6 +41,13 @@ public class ConversationController : ControllerBase, IApiAdapter
return ConversationViewModel.FromSession(conv);
}
+ [HttpPatch("/conversation/{conversationId}/ready")]
+ public async Task ReadyToInteractive([FromRoute] string conversationId)
+ {
+ var service = _services.GetRequiredService();
+ await service.MarkConnectionReady(conversationId);
+ }
+
[HttpGet("/conversations/{agentId}")]
public async Task> GetConversations()
{
diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs
index 3ff1f069..2ef67efd 100644
--- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs
+++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs
@@ -1,6 +1,7 @@
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Routing.Models;
+using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Agents;
@@ -15,12 +16,20 @@ public class AgentViewModel
public List Responses { get; set; }
public List Samples { get; set; }
public bool IsPublic { get; set; }
+
+ [JsonPropertyName("allow_routing")]
public bool AllowRouting { get; set; }
public bool Disabled { get; set; }
public List Profiles { get; set; }
+
+ [JsonPropertyName("routing_rules")]
+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List RoutingRules { get; set; }
+ [JsonPropertyName("created_datetime")]
public DateTime CreatedDateTime { get; set; }
+
+ [JsonPropertyName("updated_datetime")]
public DateTime UpdatedDateTime { get; set; }
public static AgentViewModel FromAgent(Agent agent)
diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj
index 03f701cd..81205002 100644
--- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj
+++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj
@@ -1,4 +1,4 @@
-
+
netstandard2.1
@@ -6,7 +6,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- True
+ $(GenerateDocumentationFile)
diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/BotSharp.Plugin.ChatHub.csproj b/src/Plugins/BotSharp.Plugin.ChatHub/BotSharp.Plugin.ChatHub.csproj
index 487a2e95..34a924d4 100644
--- a/src/Plugins/BotSharp.Plugin.ChatHub/BotSharp.Plugin.ChatHub.csproj
+++ b/src/Plugins/BotSharp.Plugin.ChatHub/BotSharp.Plugin.ChatHub.csproj
@@ -7,7 +7,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- True
+ $(GenerateDocumentationFile)
diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs
index 4fadba6f..472b20b1 100644
--- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs
+++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/ChatHubConversationHook.cs
@@ -1,3 +1,4 @@
+using BotSharp.Abstraction.Messaging;
using Microsoft.AspNetCore.SignalR;
namespace BotSharp.Plugin.ChatHub.Hooks;
@@ -14,6 +15,30 @@ public class ChatHubConversationHook : ConversationHookBase
_chatHub = chatHub;
}
+ public override async Task OnUserAgentConnectedInitially(Conversation conversation)
+ {
+ var agentService = _services.GetService();
+ var agent = await agentService.LoadAgent(conversation.AgentId);
+
+ // Check if the Welcome template exists.
+ var welcomeTemplate = agent.Templates.FirstOrDefault(x => x.Name == "welcome");
+ if (welcomeTemplate != null)
+ {
+ var messages = JsonSerializer.Deserialize(welcomeTemplate.Content, new JsonSerializerOptions
+ {
+ PropertyNameCaseInsensitive = true
+ });
+
+ foreach (var message in messages)
+ {
+ await Task.Delay(300);
+ await OnResponseGenerated(new RoleDialogModel(AgentRole.Assistant, message.Text));
+ }
+ }
+
+ await base.OnUserAgentConnectedInitially(conversation);
+ }
+
public override async Task OnConversationInitialized(Conversation conversation)
{
var userService = _services.GetRequiredService();
diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/SignalRHub.cs b/src/Plugins/BotSharp.Plugin.ChatHub/SignalRHub.cs
index ea18acb7..d01d2b08 100644
--- a/src/Plugins/BotSharp.Plugin.ChatHub/SignalRHub.cs
+++ b/src/Plugins/BotSharp.Plugin.ChatHub/SignalRHub.cs
@@ -17,28 +17,6 @@ public class SignalRHub : Hub
_user = user;
}
- public async Task OnMessageReceivedFromClient(string message)
- {
- // await Clients.User(_user.Id).SendAsync("ReceiveMessage", message);
- }
-
- ///
- /// Received message from client
- ///
- ///
- ///
- ///
- public async Task SendMessage(string user, string message)
- {
- // await Clients.User(_user.Id).SendAsync("ReceiveMessage", message);
- }
-
- public async Task SendMessageToCaller(string user, string message)
- => await Clients.Caller.SendAsync("ReceiveMessage", user, message);
-
- public async Task SendMessageToGroup(string user, string message)
- => await Clients.Group("SignalR Users").SendAsync("ReceiveMessage", user, message);
-
public override Task OnConnectedAsync()
{
Console.WriteLine($"SignalR Hub: {Context.UserIdentifier} connected in {Context.ConnectionId} [{DateTime.Now}]");
diff --git a/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj b/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj
index 8d96e352..39ea06b2 100644
--- a/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj
+++ b/src/Plugins/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj
@@ -6,7 +6,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- True
+ $(GenerateDocumentationFile)
diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/BotSharp.Plugin.GoogleAI.csproj b/src/Plugins/BotSharp.Plugin.GoogleAI/BotSharp.Plugin.GoogleAI.csproj
index 12a2a417..02eef190 100644
--- a/src/Plugins/BotSharp.Plugin.GoogleAI/BotSharp.Plugin.GoogleAI.csproj
+++ b/src/Plugins/BotSharp.Plugin.GoogleAI/BotSharp.Plugin.GoogleAI.csproj
@@ -6,7 +6,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- True
+ $(GenerateDocumentationFile)
diff --git a/src/Plugins/BotSharp.Plugin.MetaAI/BotSharp.Plugin.MetaAI.csproj b/src/Plugins/BotSharp.Plugin.MetaAI/BotSharp.Plugin.MetaAI.csproj
index 7bf6a42e..2a6171f7 100644
--- a/src/Plugins/BotSharp.Plugin.MetaAI/BotSharp.Plugin.MetaAI.csproj
+++ b/src/Plugins/BotSharp.Plugin.MetaAI/BotSharp.Plugin.MetaAI.csproj
@@ -6,7 +6,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- True
+ $(GenerateDocumentationFile)
diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj b/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj
index d4ce7850..c247a41f 100644
--- a/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj
+++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/BotSharp.Plugin.MetaMessenger.csproj
@@ -5,7 +5,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- GenerateDocumentationFile
+ $(GenerateDocumentationFile)
diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentMessage.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentMessage.cs
index 08aaad34..68e3336a 100644
--- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentMessage.cs
+++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MessagingModels/AttachmentMessage.cs
@@ -10,4 +10,6 @@ public class AttachmentMessage : IRichMessage
[JsonPropertyName("attachment")]
public AttachmentBody Attachment { get; set; }
+
+ public string Type => "template";
}
diff --git a/src/Plugins/BotSharp.Plugin.TelegramBots/BotSharp.Plugin.TelegramBots.csproj b/src/Plugins/BotSharp.Plugin.TelegramBots/BotSharp.Plugin.TelegramBots.csproj
index 55b5db95..480ebabc 100644
--- a/src/Plugins/BotSharp.Plugin.TelegramBots/BotSharp.Plugin.TelegramBots.csproj
+++ b/src/Plugins/BotSharp.Plugin.TelegramBots/BotSharp.Plugin.TelegramBots.csproj
@@ -6,7 +6,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- True
+ $(GenerateDocumentationFile)
diff --git a/src/Plugins/BotSharp.Plugin.WeChat/BotSharp.Plugin.WeChat.csproj b/src/Plugins/BotSharp.Plugin.WeChat/BotSharp.Plugin.WeChat.csproj
index e08f0f13..8c06e96f 100644
--- a/src/Plugins/BotSharp.Plugin.WeChat/BotSharp.Plugin.WeChat.csproj
+++ b/src/Plugins/BotSharp.Plugin.WeChat/BotSharp.Plugin.WeChat.csproj
@@ -5,7 +5,7 @@
$(LangVersion)
$(BotSharpVersion)
$(GeneratePackageOnBuild)
- True
+ $(GenerateDocumentationFile)
diff --git a/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/welcome.liquid b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/welcome.liquid
new file mode 100644
index 00000000..6a0b2780
--- /dev/null
+++ b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/welcome.liquid
@@ -0,0 +1,8 @@
+[
+ {
+ "text": "Hello, I'm an AI assistant that help you do variety of tasks."
+ },
+ {
+ "text": "How can I help you today?"
+ }
+]
\ No newline at end of file
diff --git a/src/web-live-chat/package-lock.json b/src/web-live-chat/package-lock.json
index cc5be5bf..aa704d78 100644
--- a/src/web-live-chat/package-lock.json
+++ b/src/web-live-chat/package-lock.json
@@ -1,11 +1,11 @@
{
- "name": "embedded-chat",
+ "name": "web-live-chat",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
- "name": "embedded-chat",
+ "name": "web-live-chat",
"version": "0.1.0",
"dependencies": {
"@microsoft/signalr": "^8.0.0",
diff --git a/src/web-live-chat/src/lib/helpers/typedefs.js b/src/web-live-chat/src/lib/helpers/typedefs.js
index e5aaf0c8..085987c7 100644
--- a/src/web-live-chat/src/lib/helpers/typedefs.js
+++ b/src/web-live-chat/src/lib/helpers/typedefs.js
@@ -16,6 +16,19 @@
* @property {string} assembly - The plugin assembly.
*/
+/**
+ * @typedef {Object} AgentWelcomeInfo
+ * @property {string[]} messages - The welcome messages in Rich content format.
+ */
+
+/**
+ * @typedef {Object} AgentModel
+ * @property {string} id - Agent Id.
+ * @property {string} name - Agent name.
+ * @property {string} description - Agent description.
+ * @property {AgentWelcomeInfo} welcome_info - Welcome information.
+ */
+
/**
* @typedef {Object} ConversationModel
* @property {string} id - The conversation id.
diff --git a/src/web-live-chat/src/lib/services/agent-service.js b/src/web-live-chat/src/lib/services/agent-service.js
new file mode 100644
index 00000000..3b58ce28
--- /dev/null
+++ b/src/web-live-chat/src/lib/services/agent-service.js
@@ -0,0 +1,20 @@
+import { agentListUrl, agentDetailUrl } from '$lib/services/api-endpoints.js';
+import axios from 'axios';
+
+/**
+ * @returns {Promise}
+ */
+export async function getAgents() {
+ const response = await axios.get(agentListUrl);
+ return response.data;
+}
+
+/**
+ * @param {string} id
+ * @returns {Promise}
+ */
+export async function getAgent(id) {
+ let url = agentDetailUrl.replace("{id}", id);
+ const response = await axios.get(url);
+ return response.data;
+}
diff --git a/src/web-live-chat/src/lib/services/api-endpoints.js b/src/web-live-chat/src/lib/services/api-endpoints.js
index 4948b1bd..421b2fdb 100644
--- a/src/web-live-chat/src/lib/services/api-endpoints.js
+++ b/src/web-live-chat/src/lib/services/api-endpoints.js
@@ -14,6 +14,7 @@ export const agentDetailUrl = `${host}/agent/{id}`;
// conversation
export const conversationInitUrl = `${host}/conversation/{agentId}`
+export const conversationReadyUrl = `${host}/conversation/{conversationId}/ready`
export const conversationMessageUrl = `${host}/conversation/{agentId}/{conversationId}`
export const conversationsUrl = `${host}/conversations/{agentId}`
export const dialogsUrl = `${host}/conversation/{conversationId}/dialogs`
diff --git a/src/web-live-chat/src/lib/services/conversation-service.js b/src/web-live-chat/src/lib/services/conversation-service.js
index 38e96a50..d6158c76 100644
--- a/src/web-live-chat/src/lib/services/conversation-service.js
+++ b/src/web-live-chat/src/lib/services/conversation-service.js
@@ -2,6 +2,7 @@ import {
conversationInitUrl,
conversationMessageUrl,
dialogsUrl,
+ conversationReadyUrl,
} from './api-endpoints.js';
import axios from 'axios';
@@ -17,6 +18,16 @@ export async function newConversation(agentId) {
return response.data;
}
+/**
+ * Coversation is ready
+ * @param {string} conversationId
+ */
+export async function conversationReady(conversationId) {
+ let url = conversationReadyUrl.replace("{conversationId}", conversationId);
+ const response = await axios.patch(url, {});
+ return response.data;
+}
+
/**
* Get dialog history
* @param {string} conversationId
diff --git a/src/web-live-chat/src/routes/chat/[agentId]/+page.svelte b/src/web-live-chat/src/routes/chat/[agentId]/+page.svelte
index caab5640..9492b4ab 100644
--- a/src/web-live-chat/src/routes/chat/[agentId]/+page.svelte
+++ b/src/web-live-chat/src/routes/chat/[agentId]/+page.svelte
@@ -13,7 +13,8 @@
/** @type {import('$typedefs').ConversationModel} */
let conversation;
let conversationId = "undefined";
- let agentId = "undefined";
+
+ let agentId = params.agentId;
onMount(async () => {
let userToken = "";
@@ -25,9 +26,11 @@
userToken = $page.url.searchParams.get('token') ?? "unauthorized";
}
setAuthorization(userToken);
- conversation = await newConversation(params.agentId);
+
+ // new conversation
+ conversation = await newConversation(agentId);
conversationId = conversation.id;
- agentId = params.agentId;
+
window.location.href = `/chat/${agentId}/${conversationId}?token=${userToken}`;
});
diff --git a/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/+page.svelte b/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/+page.svelte
index 35f81569..43ccc78e 100644
--- a/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/+page.svelte
+++ b/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/+page.svelte
@@ -1,5 +1,29 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
index 640e454b..a3707493 100644
--- a/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
+++ b/src/web-live-chat/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
@@ -13,10 +13,9 @@
import { page } from '$app/stores';
import { onMount } from 'svelte';
import Link from 'svelte-link';
- import { myInfo } from '$lib/services/auth-service.js';
- import { signalr } from '$lib/services/signalr-service.js';
- import { sendMessageToHub, GetDialogs } from '$lib/services/conversation-service.js';
import { setAuthorization } from '$lib/helpers/http';
+ import { signalr } from '$lib/services/signalr-service.js';
+ import { sendMessageToHub, GetDialogs, conversationReady } from '$lib/services/conversation-service.js';
const options = {
scrollbars: {
@@ -32,9 +31,12 @@
const params = $page.params;
let text = "Hi";
+
+ /** @type {import('$typedefs').AgentModel} */
+ export let agent;
/** @type {import('$typedefs').UserModel} */
- let currentUser;
+ export let currentUser;
// @ts-ignore
let scrollbar;
@@ -46,14 +48,15 @@
const token = $page.url.searchParams.get('token') ?? "unauthorized";
setAuthorization(token);
- currentUser = await myInfo(token);
-
dialogs = await GetDialogs(params.conversationId);
+
signalr.onMessageReceivedFromClient = onMessageReceivedFromClient;
signalr.onMessageReceivedFromCsr = onMessageReceivedFromCsr;
signalr.onMessageReceivedFromAssistant = onMessageReceivedFromAssistant;
await signalr.start();
+ await conversationReady(params.conversationId);
+
const scrollElements = document.querySelectorAll('.scrollbar');
scrollElements.forEach((item) => {
scrollbar = OverlayScrollbars(item, options);