1 回答

TA貢獻1877條經驗 獲得超6個贊
根據我的理解,您正在詢問用戶Do you have any children并將響應存儲在childExists插槽中,如果答案是肯定的,那么您想詢問孩子的數量。
所以根據我的說法,你需要有一個額外的插槽childCount來存儲孩子的數量。由于此插槽并非總是必需的,因此請勿在 amazon lex 控制臺中將其標記為必需。
現在,您將在您的 中檢查這一點DialogCodeHook,并僅childExists == 'yes'在childCount. 我們使用這些條件的組合是為了確保它不會無限期地運行。
def book_hotel(intent_request):
slots = intent_request['currentIntent']['slots']
welcome = slots['welcome']
location = slots['Location']
fromDate = slots['FromDate']
adultCount = slots['adultCount']
nights = slots['nights']
childExists = slots['childExists']
childCount = slots['childCount']
source = intent_request['invocationSource']
if source == 'DialogCodeHook':
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
if childExists.lower() == 'yes':
if not childCount:
return elicit_slot (
output_session_attributes,
'HotelReservation',
slots,
'childCount',
{
'contentType':'PlainText',
'content':'Please enter number of Children'
}
)
return delegate(output_session_attributes, intent_request['currentIntent']['slots'])
if source == 'FulfillmentCodeHook':
return close (
output_session_attributes,
'Fulfilled',{
'contentType':'PlainText',
'content':'Here is the temparature in'
}
)
希望能幫助到你。
添加回答
舉報