1 回答

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
根據(jù)我的理解,您正在詢問(wèn)用戶Do you have any children并將響應(yīng)存儲(chǔ)在childExists插槽中,如果答案是肯定的,那么您想詢問(wèn)孩子的數(shù)量。
所以根據(jù)我的說(shuō)法,你需要有一個(gè)額外的插槽childCount來(lái)存儲(chǔ)孩子的數(shù)量。由于此插槽并非總是必需的,因此請(qǐng)勿在 amazon lex 控制臺(tái)中將其標(biāo)記為必需。
現(xiàn)在,您將在您的 中檢查這一點(diǎn)DialogCodeHook,并僅childExists == 'yes'在childCount. 我們使用這些條件的組合是為了確保它不會(huì)無(wú)限期地運(yùn)行。
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'
}
)
希望能幫助到你。
添加回答
舉報(bào)