aws-solutions / qnabot-on-aws

AWS QnABot is a multi-channel, multi-language conversational interface (chatbot) that responds to your customer's questions, answers, and feedback. The solution allows you to deploy a fully functional chatbot across multiple channels including chat, voice, SMS and Amazon Alexa.
https://aws.amazon.com/solutions/implementations/aws-qnabot
Apache License 2.0
393 stars 251 forks source link

Allow session to end after a response is given #130

Closed steve228uk closed 1 year ago

steve228uk commented 6 years ago

Currently when a response is given Alexa will continue to listen as the session is not ended. It might be a good idea to expose this as an option so the middleware does not need to be edited manually.

https://github.com/aws-samples/aws-ai-qna-bot/blob/3e914e8c3f475db1811e987c7b45223e627116ee/lambda/fulfillment/lib/middleware/alexa.js#L103

The same could be said for the stop intent response:

https://github.com/aws-samples/aws-ai-qna-bot/blob/3e914e8c3f475db1811e987c7b45223e627116ee/lambda/fulfillment/lib/middleware/alexa.js#L72

JohnCalhoun commented 6 years ago

I agree, this would be a good parameter to expose

pdkn commented 4 years ago

This is a much needed feature. Current workaround is to set a sessionAttribute in Content Designer item {{setSessionAttr 'shouldEndSession' true}}. And then amend fulfillment/lib/middleware/alexa.js assemble() to

exports.assemble=function(request,response){

    let sessionAttributes = _.get(response,'session',{});

    return {
        version:'1.0',
        response:{
            outputSpeech:_.pickBy({
                type:response.type,
                text:response.type==='PlainText' ? response.message : null,
                ssml:response.type==='SSML' ? response.message : null,
            }),
            card:_.get(response,"card.imageUrl") ? {
                type:"Standard",
                title:response.card.title || request.question,
                text:_.has(response.card,'subTitle')? response.card.subTitle +"\n\n" + response.plainMessage:response.plainMessage,
                image:{
                    smallImageUrl:response.card.imageUrl,
                    largeImageUrl:response.card.imageUrl
                }
            } : {
                type:"Simple",
                title:_.get(response,"card.title") || request.question || "Image",
                content:_.has(response.card,'subTitle')? response.card.subTitle +"\n\n" + response.plainMessage:response.plainMessage
            },
            shouldEndSession:_.get(sessionAttributes,'shouldEndSession',false)
        },
        sessionAttributes:sessionAttributes
    }
}