Created
January 9, 2019 01:33
-
-
Save prestomation/6ee14f8299aa822b191bc5797ec47d00 to your computer and use it in GitHub Desktop.
Setting lex session/request attributes from Sumerian Lex State Machine actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will override an internal method of the sumerian lex actions | |
// This override is NOT guaranteed to work as we upgrade engine versions, but works with some limited testing with Sumerian 0.18 | |
// In the following version, the code is exactly what we have in the engine, with the addition of the 'sessionAttributes' property | |
// Any parameter supported by PostContent in the Lex API documentation may be added here, specifically `requestAttributes` and `sessionAttributes` | |
// See more here: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexRuntime.html#postContent-property | |
// | |
// Add this in a script before executing a lex action | |
// You may execute this whenever updating session attributes OR you may pull from other global data from within this function | |
// Do not change any of the other parameters, or the Lex actions likely won't work | |
sumerian.api.aws.lex.LexProcessingAction.prototype._getLexConfig = function(entity, inputStream) { | |
const { name, alias } = entity.dialogueComponent; | |
const contentType = this._getContentType(); | |
return { | |
accept: 'text/plain; charset=utf-8', | |
botName: name, | |
botAlias: alias, | |
contentType, | |
inputStream, | |
userId: this._userId, | |
sessionAttributes: { | |
"attr1" : "value1", | |
"attr2" : "value2" | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Where exactly in a script should this code be executed in order to set the attributes. I am currently trying to set some sessions attributes to send to Lex from a host in Sumeria but I am getting Cannot read property 'LexProcessingAction' of undefined TypeError: Cannot read property 'LexProcessingAction' of undefined. what am I missing?
Thanks,
Kel