aws-lex

How to know if the bot is using voice or text in Lex


In our Lambda function that gets called from Lex, we need to know if the requests is coming from Connect or from a text source like the console or another chat tool.

We mainly need to know this to decide if we need to respond with plain text or SSML.


Solution

  • You need to look into the request attribute x-amz-lex:accept-content-types. For example in a Node.js function you can do that like this:

    function canUseSSML(event) {
        if (event.requestAttributes) {
            if(event.requestAttributes['x-amz-lex:accept-content-types'] && event.requestAttributes['x-amz-lex:accept-content-types'].indexOf('SSML') != -1) {
                return true;
            }
        }
        return false;
    }