Java alexa lambda函数在时间/操作方面有一些限制



我正在写一个类似于java飞机事实示例的简单技能,我有两个奇怪的行为:

1( 相同的代码在一个意图中正确工作,但在另一个意图导致错误;

2( 我无法从公共静态列表中删除元素!我将尝试用一个非常接近的例子来更好地解释。我有两个意愿,我们可以称之为:-ActionIntent;-StopIntent。

第一个意图检索从类Constants检索的列表(类型为list(,并返回随机CustomObject的属性--这是正确的。然后,它应该将对象设置为会话属性并将其从列表中删除,因为下次响应应该是上一个CustomObject的第二个属性加上新CustomObject的第一个属性。这有道理吗?

这是代码:

// this row works correctly on the other intent
Map<String, Object> sessionAttributes = input.getAttributesManager().getSessionAttributes();
CustomObject last=(sessionAttributes.get("last")!=null) ? (CustomObject)sessionAttributes.get("last") : null;
List<CustomObject> allObjects = MAPPER.convertValue(Constants.getAllObjects(), List.class);
int index = new Random().nextInt(tutti.size());
CustomObject new = allObjects.get(index);
// a simple method that contains allObjects.remove(index) because it didn't work here but also this cause an error
Constants.removeCustomObjectFromList(index);
sessionAttributes.put("ultimoNome", nuovoNome);
String title = Constants.SKILL_TITLE;
String primaryText =new.getTrue();
String secondaryText =(last!=null) ?last.getFalse() : "";
String speechText = "" + secondaryText + " "+primaryText + "?";
return input.getResponseBuilder()
.withSpeech(speechText)
.withSimpleCard(title, primaryText)
.withReprompt(speechText)
.build();

如果我注释掉链接到sessionAttribute和Constants.removeCustomObjectFromList的行,它可以正常工作,但正如我所说,对sessionAttribute的引用在另一个意图中可以正确工作,我必须从我的初始列表中删除CustomObjects,因为用户应该同时侦听两次!有人能告诉我在哪里可以找到关于这个主题的好信息吗?

https://ask-sdk-for-nodejs.readthedocs.io/en/latest/Managing-Attributes.html

以上是官方文件。由于缺乏广泛的解释,理解其中的一些内容可能有点困难,但在大多数情况下,你需要的一切都在那里。至于你的问题,我不知道这是否是唯一的原因,但我不认为getAttributesManager((是一个函数,除非这是你定义的。您的代码:

Map<String, Object> sessionAttributes = input.getAttributesManager().getSessionAttributes();

你能试试吗:

Map<String, Object> sessionAttributes = input.attributesManager.getSessionAttributes();

相反?

最新更新