Search code examples
iosamazon-web-servicesaws-lambdaaws-sdkamazon-lex

Issue updating Lex sessionAttributes via iOS SDK


My sessionAttributes aren't updating in Lex, when I'm using the iOS sdk.

I send session attributes to Lex as follows:

self.interactionKit?.text(inTextOut: chatTextField.text!, 
    sessionAttributes: ["stage" : getStage() , "bot" : getBot()])

where getStage() and getBot() are functions that return Strings.

My problem is that when I send a set of session attributes across for "stage" and "bot", these values are used by Lex for all subsequent calls, regardless of what updated values I send.

i.e. if on Call #1 I send

["stage" : "one" , "bot" : "first"]

and on Call #2 I send

 ["stage" : "two" , "bot" : "second"]

Lex will use "one" and "first" for both calls.

Is there some caching I'm not aware of? Or do I need to do something with "AWSLexSwitchModeResponse" to update the session attributes?


Solution

  • Finally resolved! It was a bug in the AWS Lex iOS SDK, this is from the AWS Forum where it was answered by an AWS resource:

    "I found the issue in the SDK. In:

    https://github.com/aws/aws-sdk-ios/blob/master/AWSLex/AWSLexInteractionKit.m

    the session attributes are getting cached as you surmised.

    The issue is that the passed in attributes in the textInTextOut and textInAudioOut methods is first adding the passed in attributes and then adding the cached attributes, which if there are any collisions will overwrite those that are passed in as you are trying to do.

    The SDK fix is to reverse the order:

    Currently:

    [attributes addEntriesFromDictionary:sessionAttributes];
    [attributes addEntriesFromDictionary:self.sessionAttributes];
    

    Should be:

    [attributes addEntriesFromDictionary:self.sessionAttributes];
    [attributes addEntriesFromDictionary:sessionAttributes];
    

    This will be fixed in the next release of the SDK."

    I've made the change locally to the SDK in my project and the issue is resolved.