Git Product home page Git Product logo

alexa-skills-kit-states-java's People

Contributors

gitter-badger avatar kaylerch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

alexa-skills-kit-states-java's Issues

upgrade ask-sdk

ask-sdk 2.0.0 uses a different Session class. I think it creates a conflict in instantiating AWSDynamoStateHandler

can't read values back from DynamoDB

I am running into the same issue...
I can persist user scoped model fine but cannot read it back..even if I hard code the id as a constant i.e. "bob" when writing and then reading the model back...

` public static void persistState(Session session) {
// take care of state
try {
String userId = session.getUser().getUserId();
//AWSDynamoStateHandler can't handle IDs with "." convert them to "-"
userId = userId.replaceAll("\.", "-");
logger.info("persistState() persisting state for user: " + userId);

		final AlexaStateHandler handler = new AWSDynamoStateHandler(session);
                     AlexaUser activeUser = handler.readModel(AlexaUser.class, "bob")
					.orElse(handler.createModel(AlexaUser.class, "bob"));
                              ........
			activeUser.saveState();

		}
	} catch (AlexaStateException ase) {
		logger.error("Exception attempting to persist user data to dynamoDB ", ase);
	}
}`

(i've confirmed that the data is written to DyanmoDB:

I see:
amazon-user-id
model-class :
state: "id" : "bob"
)

reading the value back with id "bob" doesn't load the model ...

` public static Optional restoreState(SpeechletRequestEnvelope requestEnvelope) {

	Session session = requestEnvelope.getSession();
	String userId = session.getUser().getUserId();
	userId = userId.replaceAll("\\.", "-");
	logger.info("restoreState(): attempting to restore state for userId: " + userId);
	
	Optional<AlexaUser> activeUser = Optional.empty();
	try {
		final AlexaStateHandler handler = new AWSDynamoStateHandler(requestEnvelope.getSession());

		activeUser = handler.readModel(AlexaUser.class, "bob");
		if (activeUser.isPresent()) {
			logger.info(
					"restoreState() Found previous session for this user, restoring session attributes from AlexaUser: "
                 .....//DO work here....
	} catch (AlexaStateException e) {
		logger.error("Exception while attempting to load user's saved search attributes from dynamoDB: " + userId, e);
	}
	return activeUser;
}`

I've narrowed it down to where it short-circuits the readModel logic...i am not sure if this is a bug or not...

AWSDynamoStateHandler line# 251 readModel(...) calls getItems(..) and passes "false" as the 2nd argument:
final List<Map<String, AttributeValue>> readRequests = getItems(model, false);

getItems then adds primary keys as attribute and only loads USER scoped attribute if "withState" is true..but 'false' was passed..so it returns an empty list..which cases readModel to log line # 265 and return an empty Optional....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.