4

I want to hyperlink a particular text in lambda function content. I tried doing this but didn't work.

if (intentName == "greetings") {
        var message = {
            'contentType': 'PlainText', 
            'content': '<a href="www.google.com">click here</a>'
        }

        responseMsg = close( sessionAttributes, 'Fulfilled', message );
    }

I know we can hyperlink response card, but i want to hyperlink a particular text in content. Any idea how to do it or any alternative? i am using javascript.

Edit 1 : I am able to do it by Attachments through attachment :

function close(sessionAttributes,fulfillmentState,message){   
return{
        sessionAttributes,
        dialogAction: {
            type: 'Close',
            fulfillmentState,
            message,
            "responseCard": {
                "contentType": "application/vnd.amazonaws.card.generic",
                "genericAttachments": [
                    {
                    'title': 'Google',
                    'attachmentLinkUrl': 'https://www.google.com',
                    }
                ]
            }
        }
    };
}
Noob
  • 119
  • 1
  • 10
  • Sounds like your 'Edit 1' solved the problem. If that is true, you are encouraged on StackOverflow to answer your own questions. If that didn't fix it, then you can leave it as an Edit, but it sounds like that worked for you. – Jay A. Little Feb 19 '18 at 13:08
  • 1
    through attachments it create a separate text area, but i want to do it within message. any idea for that? – Noob Feb 19 '18 at 16:36
  • 1
    @JayA.Little actually we can provide `HTML` data in the `content` of `dialogAction` and it will be responsibility of the client to render it and show accordingly. – sid8491 Feb 20 '18 at 07:01
  • @sid8491 Oh that's good to know. Do you know if it converts the message from text-to-speech like through Amazon Connect, does it then ignore the HTML tags? I'll be sure to play around with this now. – Jay A. Little Feb 20 '18 at 07:21
  • @JayA.Little there is no inbuilt functionality but we can have some regex to ignore HTML tags then it converts to speech. – sid8491 Feb 20 '18 at 07:27

2 Answers2

1

I was trying this out on HTML a few months ago, you can check out my question at LexResponse output does not understand HTML data

The answer that worked was a JS function that looks like this:

function showResponse(lexResponse) {

    var conversationDiv = document.getElementById('conversation');
    var responsePara = document.createElement("P");
    responsePara.className = 'lexResponse';
    if (lexResponse.message) {
        var message = lexResponse.message.replace(/"/g, '\'');
        responsePara.innerHTML = message;               
        responsePara.appendChild(document.createElement('br'));
    }           
    conversationDiv.appendChild(responsePara);
    conversationDiv.scrollTop = conversationDiv.scrollHeight;
}

Please note that this is only to RENDER the response in HTML.

0

I implemented this recently. I wanted a message with custom display, but also wanted normal speech. Sending text with tags in it will cause the Text to Speech engine to read out the tags as well.

So, for each message I sent to the user, I put the "speechText" into the message content in the Lex response.

I put the "displayText" with tags and what not, within sessionAttributes.

but I had to make sure not to stringify that displayText. I only stringify a value in sessionAttributes if it is not a simple string.

On the client side, I pulled the audio data from the lex response, and I displayed the text I pull from the sessionAttributes.

sry if this is confusing.

Matt Wilde
  • 271
  • 2
  • 18