2017-12-14 2 views
0

두 개의 슬롯을 함수에 전달 중입니다. 나는 다음 XML을 보내고있다.슬롯 값에서 '정의되지 않음'을 얻습니다 (nodejs 람다를 사용하는 Alexa)

다음은 요청 XML입니다.

"requestId": "amzn1.echo-api.request.[unique-value-here]", 
    "intent": { 
     "slots": { 
     "chapter": "4", 
     "shloka": "4" 
     }, 
..... 

코드가 실행 그러나

, 나는 슬롯에 대한 정의는 무엇입니까 는 ..... 심지어 그들이 거기에 생각했다. 여기 슬롯은 ... 여기에 코드를

var intent = this.event.request.intent; 
    console.log('slots are -->'); 
    console.log(intent.slots); 
    var shloka = this.event.request.intent.slots.shloka.value; 
    var chapter = this.event.request.intent.slots.chapter.value; 
    console.log('chapter:' + chapter + ' shloka:' + shloka); 

인 콘솔 로그 입니다 -> ... {장 : '4', shloka : '4'} ... 장 : 정의되지 않은 shloka : 정의되지 않음

이 문제를 해결하는 방법을 알 수 없습니다.

답변

1

우선 shlokachapter의 값에 액세스하기 위해 value을 사용할 필요가 없습니다. 둘째, 왜 어쨌든 intent이있는 경우 (1 호선 - var intent = this.event.request.intent;) 변수 내부 this.event.request.intent 두 번 사용하여 액세스를이 경우에, 당신은 쓸 수 있습니다 :

// Use this 
var shloka = intent.slots.shloka; 
var chapter = intent.slots.chapter; 

// Instead of this 
var shloka = this.event.request.intent.slots.shloka.value; 
var chapter = this.event.request.intent.slots.chapter.value; 

이 작동합니다 예상대로 :

var intent = this.event.request.intent; 
console.log('slots are -->'); 
console.log(intent.slots); 
var shloka = intent.slots.shloka; 
var chapter = intent.slots.chapter; 
console.log('chapter:' + chapter + ' shloka:' + shloka); 
+1

감사합니다. 모든 아마존 예제는 .value를 가지고 슬롯을 검색합니다. 왜 작동하지 않는지 궁금합니다. 어쨌든 고마워. – user1544687

관련 문제