Skip to content

Commit

Permalink
Closed cskefu#138 支持接入bot.chatopera.com
Browse files Browse the repository at this point in the history
  • Loading branch information
hailiang-wang committed Nov 8, 2018
1 parent c9e00be commit f501933
Show file tree
Hide file tree
Showing 23 changed files with 163 additions and 225 deletions.
29 changes: 27 additions & 2 deletions contact-center/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,34 @@
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.chatopera.chatbot</groupId>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>com.chatopera.bot</groupId>
<artifactId>sdk</artifactId>
<version>1.1.0</version>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ public class ChatbotUtils {

private static ChatMessageRepository chatMessageRes;

/**
* 使用snsid得到ChatbotID
*
* @param snsid
* @return
*/
public static String resolveChatbotIDWithSnsid(String snsid, String clientId) {
return (clientId + "_" + snsid).toLowerCase();
}

/**
* 使用chatbotID得到snsid
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
*/
package com.chatopera.cc.app.model;

import com.chatopera.chatbot.ChatbotAPI;
import com.chatopera.chatbot.ChatbotAPIRuntimeException;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.net.MalformedURLException;
import java.util.Date;

@Entity
Expand All @@ -31,9 +28,6 @@ public class Chatbot {
private String id;
private String name;

@Column(unique=true)
private String chatbotID;

private String description;
private String primaryLanguage;
private String fallback;
Expand All @@ -44,14 +38,15 @@ public class Chatbot {
private String creater; // 创建者
private String channel; // 渠道类型

@Column(unique=true)
@Column(unique = true)
private String snsAccountIdentifier; // 渠道唯一标识
private boolean enabled; // 当前是否被启用
private String workmode; // 工作模式, 机器人优先还是人工客服优先

private ChatbotAPI api;
private Date createtime;
private Date updatetime;
private String clientId;
private String secret;


@Id
Expand All @@ -74,14 +69,6 @@ public void setName(String name) {
this.name = name;
}

public String getChatbotID() {
return chatbotID;
}

public void setChatbotID(String chatbotID) {
this.chatbotID = chatbotID;
}

public String getDescription() {
return description;
}
Expand Down Expand Up @@ -178,14 +165,6 @@ public void setWorkmode(String workmode) {
this.workmode = workmode;
}

@Transient
public ChatbotAPI getApi() throws MalformedURLException, ChatbotAPIRuntimeException {
if(api == null){
api = new ChatbotAPI(this.baseUrl);
}
return api;
}

public Date getCreatetime() {
return createtime;
}
Expand All @@ -201,6 +180,22 @@ public Date getUpdatetime() {
public void setUpdatetime(Date updatetime) {
this.updatetime = updatetime;
}

public String getClientId() {
return clientId;
}

public void setClientId(String clientId) {
this.clientId = clientId;
}

public String getSecret() {
return secret;
}

public void setSecret(String secret) {
this.secret = secret;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public abstract interface ChatbotRepository extends JpaRepository<Chatbot, String> {

public abstract boolean existsByChatbotIDAndOrgi(String chatbotID, String orgi);
public abstract boolean existsByClientIdAndOrgi(String clientId, String orgi);

public abstract boolean existsBySnsAccountIdentifierAndOrgi(String snsid, String orgi);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.chatopera.cc.concurrent.chatbot;

import com.chatopera.bot.exception.ChatbotException;
import com.chatopera.cc.app.basic.MainContext;
import com.chatopera.cc.app.cache.CacheHelper;
import com.chatopera.cc.app.handler.api.request.RestUtils;
Expand All @@ -26,7 +27,6 @@
import com.chatopera.cc.app.persistence.repository.ChatbotRepository;
import com.chatopera.cc.concurrent.user.UserDataEvent;
import com.chatopera.cc.util.Constants;
import com.chatopera.chatbot.ChatbotAPIRuntimeException;
import com.lmax.disruptor.EventHandler;
import org.json.JSONObject;
import org.slf4j.Logger;
Expand Down Expand Up @@ -57,15 +57,15 @@ private void updateAgentUserWithRespData(final String userid, final String orgi,
CacheHelper.getAgentUserCacheBean().put(userid, agentUser, orgi);
}

private void chat(final ChatbotEvent payload) throws MalformedURLException, ChatbotAPIRuntimeException {
private void chat(final ChatbotEvent payload) throws MalformedURLException, ChatbotException {
ChatMessage request = (ChatMessage) payload.getData();
Chatbot c = getChatbotRes()
.findOne(request.getAiid());

logger.info("[chatbot disruptor] chat request baseUrl {}, chatbotID {}, fromUserId {}, textMessage {}", c.getBaseUrl(), c.getChatbotID(), request.getUserid(), request.getMessage());
logger.info("[chatbot disruptor] chat request baseUrl {}, chatbot {}, fromUserId {}, textMessage {}", c.getBaseUrl(), c.getName(), request.getUserid(), request.getMessage());
// Get response from Conversational Engine.
JSONObject result = c.getApi()
.conversation(c.getChatbotID(), request.getUserid(), request.getMessage(), false);
com.chatopera.bot.sdk.Chatbot bot = new com.chatopera.bot.sdk.Chatbot(c.getClientId(), c.getSecret());
JSONObject result = bot.conversation(request.getUserid(), request.getMessage());

// parse response
logger.info("[chatbot disruptor] chat response {}", result.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,17 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">智能问答引擎地址</label>
<label class="layui-form-label">ClientId</label>
<div class="layui-input-inline">
<input type="text" name="baseUrl" required lay-verify="required" placeholder="联系info@chatopera.com,获得智能问答引擎地址"
autocomplete="off" class="layui-input" value="${bot.baseUrl}" <#if id!=null>disabled</#if>>
<input type="text" name="clientId" required lay-verify="required" placeholder="请输入ClientId" autocomplete="off"
class="layui-input" value="${bot.clientId}">
</div>
<label class="layui-form-label"></label>
</div>
<div class="layui-form-item">
<label class="layui-form-label">名称</label>
<label class="layui-form-label">Secret</label>
<div class="layui-input-inline">
<input type="text" name="name" required lay-verify="required" placeholder="请输入名称" autocomplete="off"
class="layui-input" value="${bot.name}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">语言</label>
<div class="layui-input-inline">
<select name="primaryLanguage" lay-verify="required">
<option value="zh_CN" <#if bot.primaryLanguage=="zh_CN">selected="selected"</#if>>中文</option>
<option value="en_US" <#if bot.primaryLanguage=="en_US">selected="selected"</#if>>英文</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">问候语</label>
<div class="layui-input-inline">
<input type="text" name="welcome" required lay-verify="required" placeholder="请输入问候语" autocomplete="off"
class="layui-input" value="${bot.welcome}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">兜底回复</label>
<div class="layui-input-inline">
<input type="text" name="fallback" required lay-verify="required" autocomplete="off" value="${bot.fallback}"
class="layui-input">
<input type="text" name="secret" required lay-verify="required" placeholder="请输入Secret" autocomplete="off"
class="layui-input" value="${bot.secret}">
</div>
</div>
<div class="layui-form-item">
Expand All @@ -74,13 +50,6 @@
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">描述</label>
<div class="layui-input-inline">
<input type="text" name="description" required lay-verify="required" autocomplete="off" value="${bot.description}"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-inline">
<button class="layui-btn" lay-submit lay-filter="save">保存</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
<div class="col-lg-12">
<h1>机器人列表
<div style="float: right;" class="ukefu-bt-text-content">
<button class="layui-btn layui-btn-samll green" onclick="showCreate()">新建机器人</button>
<button class="layui-btn layui-btn-mini layui-btn-radius" onclick="openChatbotBotPlatform()"><i class="layui-icon">&#xe609;</i>机器人开发者平台</button>
</div>
</h1>
</div>
</div>
<button class="layui-btn layui-btn-mini green" onclick="showCreate()">
<i class="layui-icon">&#xe64c;</i>
集成机器人
</button>
<div class="row">
<div class="col-lg-12">
<table class="layui-table" lay-skin="line">
Expand Down Expand Up @@ -159,13 +163,17 @@ <h1>机器人列表

function showCreate() {
layer.open({
title: '新建机器人',
title: '集成机器人',
type: 2,
area: ['800px', '450px'],
content: 'edit.html'
})
}

function openChatbotBotPlatform(){
window.open("https://bot.chatopera.com", "_blank");
}

function init() {
query(1, 50);
}
Expand Down
6 changes: 3 additions & 3 deletions contact-center/config/sql/cskefu-MySQL-slim.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3374,12 +3374,13 @@ DROP TABLE IF EXISTS `cs_chatbot`;
CREATE TABLE `cs_chatbot` (
`ID` varchar(32) NOT NULL COMMENT '主键ID',
`base_url` varchar(255) NOT NULL COMMENT '基础URL',
`client_id` varchar(32) NOT NULL COMMENT 'Client Id',
`secret` varchar(32) NOT NULL COMMENT 'Client Secret',
`creater` varchar(32) NOT NULL COMMENT '创建人',
`orgi` varchar(255) NOT NULL COMMENT '租户ID',
`organ` varchar(32) NOT NULL COMMENT '部门ID',
`createtime` datetime NOT NULL COMMENT '创建时间',
`updatetime` datetime NOT NULL COMMENT '更新时间',
`chatbotid` varchar(255) NOT NULL COMMENT '聊天机器人ID',
`name` varchar(255) NOT NULL COMMENT '聊天机器人名字',
`description` varchar(255) NOT NULL COMMENT '描述',
`primary_language` varchar(20) NOT NULL COMMENT '首选语言',
Expand All @@ -3390,8 +3391,7 @@ CREATE TABLE `cs_chatbot` (
`enabled` tinyint(1) DEFAULT '0' COMMENT '是否开启',
`workmode` varchar(32) NOT NULL COMMENT '工作模式',
PRIMARY KEY (`ID`) USING BTREE,
UNIQUE KEY `snsid` (`sns_account_identifier`,`orgi`) USING BTREE COMMENT '按照渠道标识唯一',
UNIQUE KEY `chatbotID` (`chatbotid`,`orgi`) USING BTREE COMMENT '按照ChatbotID唯一'
UNIQUE KEY `snsid` (`sns_account_identifier`,`orgi`) USING BTREE COMMENT '按照渠道标识唯一'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='机器人客服表';


Expand Down
Binary file not shown.
Binary file removed contact-center/config/sql/update/3.2-3.3增量.sql.zip
Binary file not shown.
Binary file removed contact-center/config/sql/update/3.3-3.4增量.sql.zip
Binary file not shown.
Binary file removed contact-center/config/sql/update/3.5-3.6增量.sql.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed contact-center/config/sql/update/temp.sql.zip
Binary file not shown.
Binary file not shown.
Binary file removed contact-center/config/sql/update/uk_sysdic.sql.zip
Binary file not shown.
Binary file not shown.
Binary file removed contact-center/config/sql/update/uk_templet.sql.zip
Binary file not shown.
Binary file not shown.

0 comments on commit f501933

Please sign in to comment.