사용자 매개 변수가 Firebase의 값과 일치하는지 어떻게 확인하나요?

돼지

저는 dialogflow 및 javascript를 처음 사용하므로 dialogflow의 이행에서 코딩하는 방법에 익숙하지 않습니다. 이것은 사용자 매개 변수가 firebase의 값과 일치하는지 확인하는 내 if 문이지만 작동하지 않고 대체 의도가 트리거됩니다. 시나리오는 대답 = firebase 값이면 봇이 정확하다고 답하고 점수를 추가하고 다음 질문을 묻는 것입니다.

function q1correct(agent){  
    const q1snapshot = admin.database().ref('quizanswers/q1').once('value');
    if(q1snapshot.val() == agent.parameters.pikachu){
      agent.add(`That's correct!`);
      score = score + 1;
      return admin.database().ref('quizquestions').once('value').then((snapshot) =>{
        const value = snapshot.child('q2').val();                                                            
        agent.add(`${value}`); 
    }); 
    }
    else{
      agent.add(`Sadly, that is incorrect.`);
      score = score;
      return admin.database().ref('quizquestions').once('value').then((snapshot) =>{
      const value = snapshot.child('q2').val();                                                            
      agent.add(`${value}`);

    });
    }
  }

if 문이 작동하지 않습니다.

여기에 표시된 것처럼 데이터베이스 내부의 답변에 변경 사항이 있으면 동적으로 허용하므로 학습 문구가 없습니다. 그렇게 할 수 없습니까? 학습 문구가 있어야합니까?여기에 이미지 설명 입력

여기에 이미지 설명 입력

죄인

It sounds like you have two different issues here - one with how you are expecting Dialogflow to be detecting Intents, the other with how you are expecting Firebase to fetch values.

Dialogflow and Detecting Intents

The purpose of Dialogflow is to take the user's phrases and determine their broad Intent by matching them with a number of possible statements. This lets you create an Intent, for example, where the user can say "yes" or "sure" or "of course" or other variants and your code just needs to handle them one way.

Sometimes we have responses where they may reply with a phrase, but some values in that phrase will vary, so we can setup parameters. If those parameters can come from a fixed set of values (or synonyms for those values), we may set these up as Entities. Dialogflow defines some Entity types, and we're allowed to define our own custom ones.

If your questions expect multiple-choice answers you can even create a Session Entity which contains possible responses for the next question. This way you will know if they answered with something you expect, or if they didn't try.

Things become much more difficult if you are expecting open-ended answers. Since Dialogflow doesn't have any patterns it knows about when the user replies, it will usually end up in the Fallback Intent. This is a special Intent that matches "everything else that doesn't match", and is usually meant for cases where the users says something totally unexpected - although it can be used to collect free-form answers.

All of this happens before any if statements in the fulfillment webhook that you write are evaluated. Once an Intent has been detected (or it reverts to pick the Fallback Intent), it sends this Intent, any parameters detected, and the full phrase to your webhook.

Update

As you note, you don't have any training phrases set for your Intent at all. If you don't have any Events (and you probably don't want one in this case), then Dialogflow will end up never matching this Intent.

The parameter, in this case, is irrelevant. Parameters are placeholders in phrases, and those parameters will be filled in with that part of the phrase as the user entered it.

You can create a Fallback Intent that has an Input Context. This will only trigger the Fallback Intent if no other Intent matches and all of the Contexts listed in the Input Context section are currently active. This will deliver the entire phrase from the user, and you can use this phrase in your comparison in your Handler for this Fallback Intent.

This, however, is probably not a good idea. Not providing training phrases and Entities can make for much more stilted conversations. It sounds like you can create an Entity for all the possible pokemon (say, @pokemon), and create your training phrases to accept things like:

  • I think it is pikachu
  • Pikachu
  • Pikachu is probably correct
  • ...

This way Dialogflow can match all these phrases to the same Intent, but just report "Pikachu" as the parameter to you.

Getting Values from Firebase

With the Firebase database, values are fetched by having a reference to a record in the database and then fetching this record by using once(). (You can also subscribe to updates to a record by using on(), but this is unnecessary in your case.)

Creating a reference is a local operation, so it returns immediately. Getting a value, however, operates asynchronously, so you need to use a Promise that will resolve only when the network operation completes. For sufficiently modern versions of node (which you should be using), you can use async/await.

In your if test, you are checking the value from the user against the reference instead of the value. To check against the value, you may need to do something more like this in an async function (untested):

const db = admin.database();
const q1snapshot = await db.ref('quizanswers/q1').once('value');
if( q1snapshot.val() === agent.parameters.pikachu ){
  // They got it right. Fetch and ask the next question
  const q2snapshot = await db.ref('quizquestions/q2').once('value');
  agent.add(q2snapshot.val());
} else {
  // They got it wrong. Say so.
  agent.add( "That isn't correct. Please try again." );
}

Update based on your updated code and saying that you're using the Dialogflow Inline Editor.

The Inline Editor is still (apparently) using Node 6, which does not support async/await. If you don't use async/await, then you need to use Promises (which Node 6 does support).

So your lines

const q1snapshot = admin.database().ref('quizanswers/q1').once('value');
if(q1snapshot.val() == agent.parameters.pikachu){

still end up being incorrect because q1snapshot is assigned a Promise, and isn't a snapshot of the result at all. So trying to compare val() of a Promise to the parameter won't work.

Your best bet would be to upgrade to a modern Node engine. You would edit your package.json file to include an "engines" section. It might look something like this:

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "8"
  },
  "scripts": {
    ...
  },
  "dependencies": {
    ...
  }
}

This show setting it for Node 8. You may wish to consider using Node 10, although this is still in beta support in Cloud Functions for Firebase.

Dialogflow에서 인라인 편집기를 사용하는 경우 이렇게 변경하려면 편집기의 일부인 (package.json) 탭을 선택해야합니다.

package.json을 보여주는 인라인 편집기

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

이메일을 확인하지 않는 경우 Firebase 사용자를 어떻게 삭제할 수 있나요?

분류에서Dev

Rails에서 매개 변수의 기본값을 어떻게 설정하나요?

분류에서Dev

YouTube API search.list 쿼리의 매개 변수에 여러 값을 추가하려면 어떻게하나요?

분류에서Dev

매개 변수가 정규식과 가능한 두 값이 일치하지 않는지 확인하세요.

분류에서Dev

변수의 마지막 세 문자가 다른 변수와 일치하는지 어떻게 확인합니까?

분류에서Dev

내 벡터가 r의 변수 값과 일치하는지 어떻게 알 수 있습니까?

분류에서Dev

Rust의 문자가 숫자인지 점인지 어떻게 확인하나요?

분류에서Dev

매개 변수가 반환 값과 밀접하게 연결된 메서드를 처리하는 방법. 매개 변수가 null이면 어떻게 되나요? 자바

분류에서Dev

SSRS (SQL Server Reporting Services)의 iif 식에서 다중 값 매개 변수를 사용하려면 어떻게하나요?

분류에서Dev

어떻게 스위치 및 열거 매개 변수 자바 (안 ENUM VALUE)를 사용 하는가?

분류에서Dev

사용자가 입력 한 텍스트의 대소 문자를 무시하는 매개 변수 요청을 받으려면 어떻게해야합니까?

분류에서Dev

사용자 입력이 수학 함수 결과와 일치하는지 어떻게 확인합니까?

분류에서Dev

Hough Circle의 매개 변수는 무엇을 의미하며 어떤 값을 사용할지 어떻게 알 수 있습니까?

분류에서Dev

어떻게 CLI를 중지 쉘 스크립트를 사용하는 하나 개의 인수가 일치하는 경우

분류에서Dev

트위터 사용자가 신고 한 위치가 존재하는지 어떻게 확인할 수 있나요?

분류에서Dev

Powershell-세 개의 변수가 두 개의 특정 문자열과 일치하는지 확인

분류에서Dev

Rails를 사용하여 여러 요청 매개 변수에서 하나의 매개 변수를 추출하려면 어떻게해야합니까?

분류에서Dev

배치를 사용하여 단일 문자열에서 두 개의 매개 변수를 가져 오나요?

분류에서Dev

배치 파일에서 파일 이름의 일부가 주어진 문자열과 일치하는지 어떻게 확인합니까?

분류에서Dev

검색 매개 변수와 일치하지 않는 요소를 제거하는 사용자 정의 Javascript 검색

분류에서Dev

저는 파이썬 초보자입니다. 텍스트 파일에서 값과 매개 변수를 가져 와서 함수에 전달하고 싶습니다. 어떻게하나요?

분류에서Dev

어떻게 자바에서 메서드 매개 변수의 일부 주석이 클래스 만 허용하는?

분류에서Dev

Kotlin에서 네이티브 자바 매개 변수를 사용하여 일반 클래스를 인스턴스화하려면 어떻게해야하나요?

분류에서Dev

* 매개 변수가 하나의 인수와 일치하지 않는 MVC 경로

분류에서Dev

Bigquery의 time_partitioning_expiration 매개 변수는 어떻게 작동하나요?

분류에서Dev

Rails에서 매개 변수는 어떻게 적용 되나요?

분류에서Dev

Rust에서 함수 인자로 타입 매개 변수를 어떻게 지정하나요?

분류에서Dev

명령의 단일 매개 변수가 수행하는 작업에 대한 매뉴얼 페이지를 어떻게 확인합니까?

분류에서Dev

foreach 루프를 사용하여 배열의 어떤 요소가 주어진 문자열과 같은지 확인하려면 어떻게해야합니까?

Related 관련 기사

  1. 1

    이메일을 확인하지 않는 경우 Firebase 사용자를 어떻게 삭제할 수 있나요?

  2. 2

    Rails에서 매개 변수의 기본값을 어떻게 설정하나요?

  3. 3

    YouTube API search.list 쿼리의 매개 변수에 여러 값을 추가하려면 어떻게하나요?

  4. 4

    매개 변수가 정규식과 가능한 두 값이 일치하지 않는지 확인하세요.

  5. 5

    변수의 마지막 세 문자가 다른 변수와 일치하는지 어떻게 확인합니까?

  6. 6

    내 벡터가 r의 변수 값과 일치하는지 어떻게 알 수 있습니까?

  7. 7

    Rust의 문자가 숫자인지 점인지 어떻게 확인하나요?

  8. 8

    매개 변수가 반환 값과 밀접하게 연결된 메서드를 처리하는 방법. 매개 변수가 null이면 어떻게 되나요? 자바

  9. 9

    SSRS (SQL Server Reporting Services)의 iif 식에서 다중 값 매개 변수를 사용하려면 어떻게하나요?

  10. 10

    어떻게 스위치 및 열거 매개 변수 자바 (안 ENUM VALUE)를 사용 하는가?

  11. 11

    사용자가 입력 한 텍스트의 대소 문자를 무시하는 매개 변수 요청을 받으려면 어떻게해야합니까?

  12. 12

    사용자 입력이 수학 함수 결과와 일치하는지 어떻게 확인합니까?

  13. 13

    Hough Circle의 매개 변수는 무엇을 의미하며 어떤 값을 사용할지 어떻게 알 수 있습니까?

  14. 14

    어떻게 CLI를 중지 쉘 스크립트를 사용하는 하나 개의 인수가 일치하는 경우

  15. 15

    트위터 사용자가 신고 한 위치가 존재하는지 어떻게 확인할 수 있나요?

  16. 16

    Powershell-세 개의 변수가 두 개의 특정 문자열과 일치하는지 확인

  17. 17

    Rails를 사용하여 여러 요청 매개 변수에서 하나의 매개 변수를 추출하려면 어떻게해야합니까?

  18. 18

    배치를 사용하여 단일 문자열에서 두 개의 매개 변수를 가져 오나요?

  19. 19

    배치 파일에서 파일 이름의 일부가 주어진 문자열과 일치하는지 어떻게 확인합니까?

  20. 20

    검색 매개 변수와 일치하지 않는 요소를 제거하는 사용자 정의 Javascript 검색

  21. 21

    저는 파이썬 초보자입니다. 텍스트 파일에서 값과 매개 변수를 가져 와서 함수에 전달하고 싶습니다. 어떻게하나요?

  22. 22

    어떻게 자바에서 메서드 매개 변수의 일부 주석이 클래스 만 허용하는?

  23. 23

    Kotlin에서 네이티브 자바 매개 변수를 사용하여 일반 클래스를 인스턴스화하려면 어떻게해야하나요?

  24. 24

    * 매개 변수가 하나의 인수와 일치하지 않는 MVC 경로

  25. 25

    Bigquery의 time_partitioning_expiration 매개 변수는 어떻게 작동하나요?

  26. 26

    Rails에서 매개 변수는 어떻게 적용 되나요?

  27. 27

    Rust에서 함수 인자로 타입 매개 변수를 어떻게 지정하나요?

  28. 28

    명령의 단일 매개 변수가 수행하는 작업에 대한 매뉴얼 페이지를 어떻게 확인합니까?

  29. 29

    foreach 루프를 사용하여 배열의 어떤 요소가 주어진 문자열과 같은지 확인하려면 어떻게해야합니까?

뜨겁다태그

보관