dueros / bot-sdk-java Goto Github PK
View Code? Open in Web Editor NEW度秘bot开发的Java版SDK
License: Apache License 2.0
度秘bot开发的Java版SDK
License: Apache License 2.0
您好!
目前的bot-sdk-java代码中通过setSlot函数是不是还不能给槽位直接进行赋值?因项目需要,我们很需要这个功能,麻烦帮忙实现和提供此功能?非常感谢。
另外了解到,目前在Node.js版本的bot-sdk中已经实现了通过 setSlot(field, value, index = 0)函数给槽位进行赋值了,麻烦给Java版本的bot-sdk也增加一下这个功能?谢谢。
DuerOs请求不到我的WebService
部署方式选择“WebService”设置域名,保存后提示“请联系工作人员添加白名单”
请问WebService白名单如何添加?
请问DuerOs请求不到我的WebService是否是由于没有添加白名单的原因。
SDK怎么不更新了
我开发的自定义技能服务部署在阿里云服务器,在百度DuerOS控制台配置了Web Service部署地址,
模拟测试时,输入打开xxx技能名称,百度DuerOS给技能服务发送了LaunchRequest请求(onLaunch对话事件);
继续对话输入意图,百度DuerOS没有给技能服务发送IntentRequest请求(onInent对话事件);
请问这是什么原因导致的?
针对小白用户,有没有一个入门的完整例子呢?
有没有一个官方的文档地址,我去学习一下。
应该返回value吧?
/**
* 获取session属性信息中某个字段的值
*
* @param key
* 属性信息的key
* @return String 属性信息的值value
*/
protected String getSessionAttribute(final String key) {
return request.getSession().getAttributes().get(key);
}
/**
* 设置session属性信息中某个字段的值
*
* @param key
* 属性信息的key
* @param value
* 属性信息的值value
*/
protected void setSessionAttribute(final String key, final String value) {
session.getAttributes().put(key, value);
}
在中 /java-sdk/src/main/java/com/baidu/dueros/data/response/directive/videoplayer/Stream.java
的内部类。
public class ProgressReport {
// 如果此字段存在,则设备端在播放该video
// item时,播放到所指定时间之后会上报ProgressReportDelayElapsed事件;不存在则不上报此事件
private int progressReportDelayInMilliseconds = 0;
// 如果此字段存在,则设备端在播放该video
// item时,每隔指定时间上报ProgressReportIntervalElapsed事件,不存在则不上报此事件
private int progressReportIntervalInMilliseconds = 0;
.....
}
属性 progressReportDelayInMilliseconds 、progressReportIntervalInMilliseconds 被定义成原子类型,因此序列化必然存在这两个字段。跟注释:“不存在则不上报此事件” 有冲突。
此处应该改成 Integer?
当点击发布上线的时候 会发送一个请求过来没有内容。只有header
这时候调用
com.baidu.dueros.bot.BaseBot(HttpServletRequest)
方法就会报错。希望内部能够做个判断下
这是请求数据
{
"header": {
"payloadVersion": "1",
"name": "DiscoverAppliancesRequest",
"namespace": "DuerOS.ConnectedHome.Discovery",
"messageId": "b4146860-d379-11e8-8452-e57802d0e23a_1#1_0_Smarthome_5bc996f084ee41.82722267"
},
"payload": {
"accessToken": "ecea08e3-3fa9-4d6d-a81e-e7604a1d2eb4",
"openUid": "b5609b69af31eabd6ea22661faa519b8"
}
}
目前需要主动通知的功能,回调dueros的功能。
com.fasterxml.jackson.databind.JsonMappingException: Could not find creator property with name 'requestId' (in class com.baidu.dueros.data.request.RequestBody)
at [Source: java.io.StringReader@67e5ba; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:700)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:577)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:270)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:168)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:401)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:350)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:263)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:243)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:144)
at com.fasterxml.jackson.databind.DeserializationContext.findContextualValueDeserializer(DeserializationContext.java:366)
at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.construct(PropertyBasedCreator.java:96)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:414)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:294)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:243)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:144)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:381)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3095)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2989)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2098)
at com.baidu.dueros.bot.BaseBot.(BaseBot.java:168)
at com.baidu.dueros.samples.tax.TaxBot.(TaxBot.java:53)
at com.baidu.dueros.samples.tax.TaxAction.doPost(TaxAction.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
请问下什么时候支持在技能里调用设备的设置闹钟和timer功能?
详见https://dueros.baidu.com/forum/topic/show/307433
技能之所以能够对数据统计是因为web服务在将response返回给音箱之前,把response也发给了百度数据统计服务器。见BaseBot源代码中的run方法。
public String run() throws Exception {
// 请求参数不合法
if (verify() == false) {
return this.illegalRequest();
}
this.dispatch();
String responseStr = this.build(response);
this.botMonitor.setResponse(responseStr);//将response注入
this.botMonitor.uploadData();//提交给统计服务器
return responseStr;
}
我开始以为uploadData()方法出了问题,后来发现第一个问题出现在setResponse里。见BotMonitor的setResponse方法。
public void setResponse(String responseData) {
if (StringUtils.isBlank(responseData)|| this.isShouldDisable()) {
return;
}
this.requestEndTime = this.getMillisecond();
this.response = new Response(responseData);
}
这个本该为monitor中response属性赋值的方法执行后,response总是为空,因为isShouldDisable()只会返回true,具体说是this.response == null这个条件永远是true。
public boolean isShouldDisable() {
if (StringUtils.isBlank(this.privateKey)
|| this.request == null
|| this.response == null
|| !this.enabled) {
return true;
}
return false;
}
monitor从BaseBot构造方法创建后response默认为空,除了setResponse方法没有其他地方赋值。setResponse方法中的赋值语句却因为调用isShouldDisable返回true,永远没有机会执行。参照nodejs和python中的isShouldDisable方法,你会发现只有Java版的isShouldDisable方法增加了request和response两个条件。
nodejs版
isShouldDisable() {
if (this._privateKey == null || this._privateKey.length === 0
|| !Number.isInteger(this._environment) || !this._enabled) {
return true;
}
return false;
}
python版
def is_should_disable(self):
'''
判断Monitor是否可用
:return:
'''
if not self.enabled:
logging.warning('未开启数据统计功能, 如果使用统计功能需要调用set_monitor_enabled(True)')
return True
if self.enabled:
if not self.private_key or len(self.private_key) == 0:
logging.warning('未配置私钥, 请调用set_environment_info(prikey)')
return True
return False
这两个isShouldDisable方法只检查privateKey和enabled,nodejs还检查了environment,但二者均没有检查request和response。显然,检查request和response应该放在uploadData方法中,而不是这里。
注释掉这两个判断条件,果然monitor的response有值了,uploadData也执行了,但是依然没有统计数据。
uploadData方法片段
httpClient.execute(httpPost, new FutureCallback() {
@OverRide
public void completed(HttpResponse result) {//原文这里就是result,很奇特。
}
@OverRide
public void failed(Exception ex) {
}
@OverRide
public void cancelled() {
}
});
在completed方法中添加调试信息发现,返回结果是“bot pubkey not found.”(通过一个上线但发布新版本的技能访问)或“get bot pub key error.”(通过一个从未上线的技能访问。顺便说下这个问题在论坛也有人问过,结果是无人回复。zeali 发布的 get bot pub key error.)。以上结果是我的environment为0,即调试模式的前提下。我将environment改为1后返回“Failed to verify the signature.”(通过一个上线但发布新版本的技能访问)或“get bot pub key error.”(通过一个从未上线的技能访问。因为截至目前技能上线还没通过,所以不排除上线后能得到正确结果的可能性。
我开始怀疑是公钥私钥不匹配的问题,所以还验证了一下。签名是通过monitor自带的Certificate类的rsaSign方法,验证是网上找的一段方法。结论是公钥和私钥都不能包含第一行和最后一行的说明。bot-sdk-java在示例里强调了这一点,但技能后台配置界面上不论是否去掉收尾两行都不正确。
至此,我认为我能做的已经结束了,虽然知道问题出在数据统计服务器那头,但个人注定是无法解决了。希望sdk开发人员早日解决,提交新版本。
然而,事情却没有结束。隔一段时间我收到短信,告诉我技能稳定性指标不达标。上服务器一看,每次请求都会报异常,too many open files,Failure opening selector createDefault等等。异常指向uploadData方法。
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
httpClient.start();
HttpPost httpPost = new HttpPost(Config.getUploadUrl());
try {
Map<String, String> contentMap = new HashMap<>();
contentMap.put("data", base64Str);
JSONObject jsonContent = new JSONObject(contentMap);
httpPost.setEntity(new StringEntity(base64Str.toString()));
httpPost.setHeader("SIGNATURE", signRet);
httpPost.setHeader("botId", botId);
httpPost.setHeader("timestamp", timestamp.toString());
httpPost.setHeader("pkversion", pkversion);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
httpClient.execute(httpPost, new FutureCallback() {
@OverRide
public void completed(HttpResponse result) {
}
@OverRide
public void failed(Exception ex) {
}
@OverRide
public void cancelled() {
}
});
} catch (Exception e) {
e.printStackTrace();
}
原因是httpClient大量创建,长期没有关闭,导致资源耗尽。在completed方法里加上close后,这个问题不再出现。
listItem 里image放tag时,反序列化报错,提示No suitable constructor found for type [simple type, class com.baidu.dueros.data.response.directive.display.templates.Tag]:
能去掉 openapi:7.0.3 的引用吗,我看到监控 里面 只使用 一个 方法,这个包 10M +++
1.0.2 版本中 开始加入的 这个包的,
com.intellij
openapi
我有一个跟定时相关的需求:定时自动唤醒自己开发的某个技能。
具体是:在小度音箱上,用户可以通过语音来设置自定义时间,在此时间点到达时自动唤醒本技能,例如每天七点准时自动唤醒本技能执行,该如何实现?
类似现在的闹钟功能,是不是需要百度开放定时timer的接口才能实现? 具体要如何实现?要是有demo来参考就更好了。
调用以下代码时报异常,不知哪里有问题
StringEscapePolicy p = StringEscapePolicy.NORMAL;
Exception in thread "main" java.lang.NoSuchFieldError: ESCAPE_JSON at com.github.wnameless.json.flattener.StringEscapePolicy.<clinit>(StringEscapePolicy.java:46) ....
版本:1.1.1
public Certificate(HttpServletRequest request) {
try {
Map<String, String> map = new HashMap();
Enumeration headernames = request.getHeaderNames();
String signature;
String signaturecerturl;
while(headernames.hasMoreElements()) {
signature = (String)headernames.nextElement();
signaturecerturl = request.getHeader(signature);
map.put(signature, signaturecerturl);
}
signature = (String)map.get("signature");
signaturecerturl = (String)map.get("signaturecerturl");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "utf-8"));
StringBuffer stringBuffer = new StringBuffer("");
String temp = "";
while((temp = bufferedReader.readLine()) != null) {
stringBuffer.append(temp);
}
String message = stringBuffer.toString();
this.signature = signature;
this.signaturecerturl = signaturecerturl;
this.message = message;
} catch (IOException var10) {
;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.