H5客服聊天系统是一款基于HTML5标准构建的营销推广落地页面中实现在线客服聊天功能的软件。支持在任何第三方平台生成的H5页面中添加在线咨询功能按钮,浏览广告的用户可以直接点击页面上的客服咨询并留下联系方式,是企业营销活动中重要的客户获取组成部分。
接入H5客服聊天系统后,企业可以通过软件提供的自动回复、优质话术推荐等功能,引导客户高效快速地留下联系信息,并对不同渠道的客户信息进行综合管理。
1、客户输入内容预览
点击H5页面上的在线咨询按钮后,界面将跳转至H5客服聊天系统提供的第三方聊天窗口。用户在消息输入框中编辑的内容可以被客服人员实时查看,让客服人员提前掌握客户的心理趋势和潜在需求,提高转化率。
2、客户服务优质话术推荐
H5客服聊天系统将对用户提出的每一个问题进行智能分析,并为客服人员提供客户满意的答案。点击合适的话术可以一键快速回复,提升效率的同时也保证了引导用户留联的概率。
3、客服机器人自动回复
H5客服聊天系统提供的智能客服机器人功能可用于自动回复。客服机器人会根据用户的语义判断意思并自动回复相应的话术。
4、客户资源集成管理
当客户在H5聊天系统中留下微信、qq和电话等联系信息时,系统会自动提取相关信息和渠道ID,将其存储为名片并导入内置的crm系统。支持与企业现有的OA、CRM、ERP、HIS等系统的数据同步,并自动管理来自不同渠道的数据。
5、用户数据统计分析
系统可以自动提取所有客服聊天记录,对客户聊天内容中的高频词进行统计分析,结合客户咨询产品分类、资金预算、转化率等数据,构建不同群体的用户需求画像,协助营销人员优化推广策略。
/// <summary>
/// 表示一个会话管理对象。
/// </summary>
public class ConversationManage
{
private static Keisoft.Logger.Log log = new Keisoft.Logger.Log("ChatCore");
// 默认编码。
private static System.Text.Encoding _encoding = System.Text.Encoding.UTF8;
/// <summary>
/// 帐号 Id。
/// </summary>
private long _accountId;
// 当前会话的 WebSocket。
private WebSocket _webSocket;
private Conversation _conversation;
private HandlerSystemMessage _hsm;
private HandlerPrivateMessage _hpm;
private HandlerGroupMessage _hgm;
/// <summary>
/// 初始化会话管理对象。
/// </summary>
/// <param name="accountId"> 帐号 Id。</param>
/// <exception cref="ArgumentNullException"> 获取帐号信息失败异常。</exception>
public ConversationManage(long accountId)
{
_accountId = accountId;
_conversation = new Conversation();
// 获取推送配置数据。
var _accountLogic = LogicDependencyResolver.GetService<IAccountLogic>();
// 获取帐号资料。
var lram = _accountLogic.GetPushConfig(accountId);
if (lram.IsSucceed && lram.Value != null)
// 设置推送配置。
_conversation.ClientId = lram.Value.ClientId;
MessageHelp.WriteInfoLog(_accountId, "帐号请求连接");
}
/// <summary>
/// 启动会话。
/// </summary>
/// <param name="context"> WebSocket 上下文。</param>
/// <returns> 会话任务。</returns>
public async Task Start(AspNetWebSocketContext context)
{
MessageHelp.WriteInfoLog(_accountId, "帐号连接成功");
//var socket = context.WebSocket;
_webSocket = context.WebSocket;
_conversation.WebSocket = _webSocket;
// 保存会话。
CacheConversation.Save(_accountId, _conversation);
try
{
_hsm = new HandlerSystemMessage(_accountId, _webSocket);
_hpm = new HandlerPrivateMessage(_accountId, _webSocket);
_hgm = new HandlerGroupMessage(_accountId, _webSocket);
}
catch (Exception ex)
{
MessageHelp.WriteInfoLog(_accountId, string.Concat("帐号初始化数据出现异常,异常内容:", ex.ToString()));
// 返回错误。
MessageHelp.SendMessageAsync
(
_webSocket,
MessageHelp.ReturnSendError(null, MessageReportState.ArgErrorCode, "禁止连接")
).Wait();
return;
}
// 上线发“离线私聊、群聊消息”。
await _hpm.Online();
// 上线发送“新朋友申请”。
await _hsm.OnlinePushNewFriendApply();
// 持续监听。
while (true)
{
if (_webSocket.State != WebSocketState.Open)
{
MessageHelp.WriteInfoLog(_accountId, "会话状态未打开", _webSocket.State);
// 关闭会话。
CacheConversation.Close(_accountId);
// 处理离线操作。
_hpm.OffLine();
break;
}
// 获取客户端请求的消息。
var messageBody = await ReceiveMessageAsync();
if (messageBody == null)
{
// 接收请求失败,告知客户端“发送消息失败”。
var noticeBuffer = MessageHelp.ReturnSendError(null);
await MessageHelp.SendMessageAsync(_webSocket, noticeBuffer);
// 继续监听。
continue;
}
if (messageBody.IsClose)
{
// 关闭会话。
await CloseAsync();
break;
}
switch (messageBody.BodyType)
{
// 心跳包。
case MessageBodyType.Heartbeat:
// 回复心跳包。
await _hsm.ReplyHeartbeat(messageBody.Id, _conversation, _hpm);
break;
// 私聊天。
case MessageBodyType.PrivateChat:
// 服务器接收消息,然后转发给客户端。
await _hpm.Process(messageBody);
break;
// 群聊。
case MessageBodyType.GroupChat:
await _hgm.Process(messageBody);
break;
// 消息应答。
case MessageBodyType.Answer:
await _hpm.ProcessAnswer(messageBody);
break;
}
}
MessageHelp.WriteInfoLog(_accountId, "本次回会话已结束", _webSocket.State);
}
/// <summary>
/// 接收消息。
/// </summary>
/// <returns> 消息主体。</returns>
private async Task<MessageBody> ReceiveMessageAsync()
{
var buffer = new ArraySegment<byte>(new byte[2048]);
WebSocketReceiveResult result = null;
try
{
result = await _webSocket.ReceiveAsync(buffer, CancellationToken.None);
}
catch (Exception ex)
{
//MessageHelp.WriteInfoLog(_accountId, string.Concat("接收发送异常,异常内容:", ex.ToString()));
// 关闭。
return new MessageBody { IsClose = true };
}
if (result.MessageType == WebSocketMessageType.Close)
{
// 关闭。
return new MessageBody { IsClose = true };
}
// 获取消息内容。
string message = _encoding.GetString(buffer.Array, 0, result.Count);
MessageBody body;
// 尝试将 JSON 字符串转换成对象。
if (MessageHelp.TryToMessageBody(message, out body) && body != null)
{
body.Content = System.Net.WebUtility.HtmlEncode(body.Content);
return body;
}
MessageHelp.WriteInfoLog(_accountId, string.Concat("发送 MessageBody 异常,MessageBody 内容:", message));
return null;
}
/// <summary>
/// 关闭会话。
/// </summary>
/// <returns> 异步任务。</returns>
private async Task CloseAsync()
{
MessageHelp.WriteInfoLog(_accountId, "请求关闭连接", _webSocket.State);
// 关闭会话。
CacheConversation.Close(_accountId);
// 处理离线操作。
_hpm.OffLine();
try
{
if (_webSocket.State == WebSocketState.CloseReceived)
// 关闭 WebSocket。
await _webSocket.CloseAsync(WebSocketCloseStatus.Empty, string.Empty, CancellationToken.None);
}
catch (Exception ex)
{
MessageHelp.WriteInfoLog(_accountId, string.Concat("关闭连接出现异常,异常内容:", ex.ToString()));
}
MessageHelp.WriteInfoLog(_accountId, "关闭连接完毕", _webSocket.State);
}
}