Compare commits
No commits in common. "70b646700b1c06f5caf2ab8a7c384492d3d9f5cb" and "5d9eb4aac315a788b0f9a1a064e9a25841af04c9" have entirely different histories.
70b646700b
...
5d9eb4aac3
|
|
@ -37,15 +37,6 @@ paths:
|
||||||
- AC-MCA-05
|
- AC-MCA-05
|
||||||
- AC-MCA-06
|
- AC-MCA-06
|
||||||
- AC-MCA-07
|
- AC-MCA-07
|
||||||
parameters:
|
|
||||||
- name: X-Tenant-Id
|
|
||||||
in: header
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
minLength: 1
|
|
||||||
maxLength: 64
|
|
||||||
description: 租户ID,用于多租户场景下的租户标识
|
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.wecom.robot.adapter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -18,7 +17,7 @@ import java.util.stream.Collectors;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class ChannelAdapterFactory {
|
public class ChannelAdapterFactory {
|
||||||
@Resource(name = "channelAdapters")
|
|
||||||
private final Map<String, ChannelAdapter> adapterMap;
|
private final Map<String, ChannelAdapter> adapterMap;
|
||||||
|
|
||||||
public ChannelAdapterFactory(List<ChannelAdapter> adapters) {
|
public ChannelAdapterFactory(List<ChannelAdapter> adapters) {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,4 @@ public class AiServiceConfig {
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
private int timeout = 5000;
|
private int timeout = 5000;
|
||||||
|
|
||||||
private String tenantId = "szmp@ash@2026";
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
package com.wecom.robot.config;
|
|
||||||
|
|
||||||
import com.wecom.robot.adapter.ChannelAdapter;
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class ChannelAdapterConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
public Map<String, ChannelAdapter> channelAdapters(
|
|
||||||
ObjectProvider<List<ChannelAdapter>> adapterProvider) {
|
|
||||||
return adapterProvider.getIfAvailable(Collections::emptyList)
|
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toMap(
|
|
||||||
ChannelAdapter::getChannelType,
|
|
||||||
Function.identity(),
|
|
||||||
(existing, replacement) -> existing // 处理重复key
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +1,10 @@
|
||||||
package com.wecom.robot.config;
|
package com.wecom.robot.config;
|
||||||
|
|
||||||
import com.wecom.robot.adapter.ChannelAdapter;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Component
|
@Component
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ public class RestTemplateConfig {
|
||||||
public RestTemplate restTemplate() {
|
public RestTemplate restTemplate() {
|
||||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||||
factory.setConnectTimeout(5000);
|
factory.setConnectTimeout(5000);
|
||||||
factory.setReadTimeout(30000);
|
factory.setReadTimeout(5000);
|
||||||
return new RestTemplate(factory);
|
return new RestTemplate(factory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,7 +31,6 @@ public class WecomCallbackController {
|
||||||
private final WecomConfig wecomConfig;
|
private final WecomConfig wecomConfig;
|
||||||
private final MessageProcessService messageProcessService;
|
private final MessageProcessService messageProcessService;
|
||||||
private final MessageRouterService messageRouterService;
|
private final MessageRouterService messageRouterService;
|
||||||
@Resource(name = "channelAdapters")
|
|
||||||
private final Map<String, ChannelAdapter> channelAdapters;
|
private final Map<String, ChannelAdapter> channelAdapters;
|
||||||
|
|
||||||
@GetMapping("/callback")
|
@GetMapping("/callback")
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -36,7 +35,6 @@ public class MessageProcessService {
|
||||||
private final WecomApiService wecomApiService;
|
private final WecomApiService wecomApiService;
|
||||||
private final WebSocketService webSocketService;
|
private final WebSocketService webSocketService;
|
||||||
private final MessageRouterService messageRouterService;
|
private final MessageRouterService messageRouterService;
|
||||||
@Resource(name = "channelAdapters")
|
|
||||||
private final Map<String, ChannelAdapter> channelAdapters;
|
private final Map<String, ChannelAdapter> channelAdapters;
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ public class AiServiceClientImpl implements AiServiceClient {
|
||||||
String url = aiServiceConfig.getUrl() + CHAT_ENDPOINT;
|
String url = aiServiceConfig.getUrl() + CHAT_ENDPOINT;
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
headers.set("X-Tenant-Id", aiServiceConfig.getTenantId());
|
|
||||||
HttpEntity<ChatRequest> entity = new HttpEntity<>(request, headers);
|
HttpEntity<ChatRequest> entity = new HttpEntity<>(request, headers);
|
||||||
|
|
||||||
ResponseEntity<ChatResponse> response = restTemplate.postForEntity(
|
ResponseEntity<ChatResponse> response = restTemplate.postForEntity(
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,10 @@ import com.wecom.robot.entity.Session;
|
||||||
import com.wecom.robot.service.*;
|
import com.wecom.robot.service.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -34,8 +32,7 @@ public class MessageRouterServiceImpl implements MessageRouterService {
|
||||||
private final AiServiceClient aiServiceClient;
|
private final AiServiceClient aiServiceClient;
|
||||||
private final TransferService transferService;
|
private final TransferService transferService;
|
||||||
private final WebSocketService webSocketService;
|
private final WebSocketService webSocketService;
|
||||||
@Resource(name = "channelAdapters")
|
private final Map<String, ChannelAdapter> channelAdapters;
|
||||||
private final Map<String, ChannelAdapter> channelAdapterMap;
|
|
||||||
private final StringRedisTemplate redisTemplate;
|
private final StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -201,7 +198,7 @@ public class MessageRouterServiceImpl implements MessageRouterService {
|
||||||
|
|
||||||
String transferReply = reply + "\n\n正在为您转接人工客服,请稍候...";
|
String transferReply = reply + "\n\n正在为您转接人工客服,请稍候...";
|
||||||
|
|
||||||
ChannelAdapter adapter = channelAdapterMap.get(message.getChannelType());
|
ChannelAdapter adapter = channelAdapters.get(message.getChannelType());
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
OutboundMessage outbound = OutboundMessage.builder()
|
OutboundMessage outbound = OutboundMessage.builder()
|
||||||
.channelType(message.getChannelType())
|
.channelType(message.getChannelType())
|
||||||
|
|
@ -225,7 +222,7 @@ public class MessageRouterServiceImpl implements MessageRouterService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendReplyToUser(Session session, InboundMessage message, String reply) {
|
private void sendReplyToUser(Session session, InboundMessage message, String reply) {
|
||||||
ChannelAdapter adapter = channelAdapterMap.get(message.getChannelType());
|
ChannelAdapter adapter = channelAdapters.get(message.getChannelType());
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
OutboundMessage outbound = OutboundMessage.builder()
|
OutboundMessage outbound = OutboundMessage.builder()
|
||||||
.channelType(message.getChannelType())
|
.channelType(message.getChannelType())
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,12 @@ transfer:
|
||||||
- 人工客服
|
- 人工客服
|
||||||
confidence-threshold: 0.6
|
confidence-threshold: 0.6
|
||||||
max-fail-rounds: 3
|
max-fail-rounds: 3
|
||||||
max-session-duration: 180000000
|
max-session-duration: 1800000
|
||||||
max-message-rounds: 50
|
max-message-rounds: 50
|
||||||
|
|
||||||
ai-service:
|
ai-service:
|
||||||
url: http://localhost:8000
|
url: http://localhost:8000
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
tenantId: szmp@ash@2026
|
|
||||||
|
|
||||||
channel:
|
channel:
|
||||||
default-channel: wechat
|
default-channel: wechat
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue