我的工作Amazon
Lex
bot
,在我python
Lambda
功能,我有以下的輸出回:根據傳入請求的contentType在Amazon Lambda函數輸出中指定contentType?
def close(session_attributes, fulfillment_state, message):
response = {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': 'Close',
'fulfillmentState': fulfillment_state,
'message': message
}
}
return response
def Test_Bot(intent_request):
# bunch of other code processing
# call to close() in final output return
return close(
session_attributes,
'Fulfilled',
{
'contentType': 'PlainText',
'content': 'Thanks for asking!'
}
)
這是我輸入Lambda
函數的樣子:
def dispatch(intent_request):
intent_name = intent_request['currentIntent']['name']
# Dispatch to your bot's intent handlers
if intent_name == 'TestBot':
return Test_Bot(intent_request)
raise Exception('Intent with name ' + intent_name + ' not supported')
# --- Main handler ---
def lambda_handler(event, context):
return dispatch(event)
注意這不是完整的代碼,而是輸入和輸出代碼的一部分。
現在我面臨的問題是,如果我通過Lex
測試機器人控制檯我的問題type-in
,我的代碼完全正常工作從開始到結束。但如果我的問題是我的問題,那麼代碼將在終點處打破中斷。現在,如果我是正確的,因爲contentType
設置爲PlainText
,所以當我type-in
的問題,它的工作正常,但當我speak-in
的問題,那麼它 這是不存在,所以它中斷。
所以我的問題是如何訪問傳入請求的contentType
?意思是如果用戶正在打字,那麼以上述響應格式中的contentType
被設置爲PlainText
,並且當用戶在說話時,contentType
被設置爲audio
?
貴機器人配置了語音輸出?在控制檯中,檢查設置>輸出語音 – Milk