Response cards not displaying in website-lex

萝らか妹 提交于 2020-07-22 05:51:08

问题


I have created Lex Chatbot and developed a website and integrated this Chatbot. Its working fine.But response cards in the form of buttons are not showing up.I got to know that I have to invoke it from lambda function.So I included the response card code .It works ,but after displaying the buttons it goes back and asks the first slot value again.I dont know where I am wrong

Here is the expected conversation.

User:Hi
Lex:Please provide me your eid
User:e123456
Lex:Choose one of the impact below:
1.low 2.high 3.medium (in form of buttons)
User clicks on low
Lex:Thanks,your ticket has been raised(expected)

What happens:

User:Hi
Lex:Please provide me your eid
User:e123456
Lex:Choose one of the impact below:
1.low 2.high 3.medium
User clicks on low
Lex:Please provide me your eid(goes back and asks the first slot value)

Here is my code:

import json
import logging
import re
import http.client
import mimetypes

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

  
def elicit_slot_response(output_session_attributes,intent_name,slot_to_elicit,message):
    responses= {
     'dialogAction': {
     'type': 'ElicitSlot',
     'slottoElicit':'slot_to_elicit',
     'message': {
      'contentType': 'PlainText',
      'content': message
                },
      'responseCard': {
                'version': '0',
                'contentType': 'application/vnd.amazonaws.card.generic',
                'genericAttachments': [
                    {
                    'title': 'title1',
                    'subTitle': 'subtitle',
                    "buttons":[ 
                     {
                        "text":"button 1",
                        "value":"value 1"
                     },
                     {
                        "text":"button 2",
                        "value":"value 2"
                     },
                     {
                        "text":"button 3",
                        "value":"value 3"
                     }
                        ]
                    }
                    ]
                                 }
     }
   }

    return responses    


def close():
    val=  {
             "dialogAction":
            {
                "fulfillmentState":"Fulfilled",
                "type":"Close",
                "message":
                 {
                     "contentType":"PlainText",
                     "content":"Hey your ticket has been raised"
                 }
                    }
                    
                }
    print(val)
    return val
    

def lambda_handler(event, context):
    val = ""
    slots = event['currentIntent']['slots']
    empidemployee= event['currentIntent']["slots"]["empidemployee"]
    latestdesc= event['currentIntent']["slots"]["latestdesc"]
    latestimpact= event['currentIntent']["slots"]["latestimpact"]
    output_session_attributes = event['sessionAttributes'] if event['sessionAttributes'] is not None else {}
    elicit_slot_response(output_session_attributes,'latestdetails','latestimpact',"impact")
    val=close()
    return val
   
    

回答1:


The conversation flow restarts because in the ElicitSlot response from the Lambda function containing the response cards, you are not returning the slots parameter which would contain the slot values already taken as an input from the user.

So, include the slots parameter in the response the value for which could be event['currentIntent']['slots'].



来源:https://stackoverflow.com/questions/62940392/response-cards-not-displaying-in-website-lex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!