오늘은 입력을 받아서 처리하도록 바꾸어보자.
say "hello"라고 하면 Bixby는 HELLO, WORLD 라고 답을 하고,
say "foo"라고 하면 Bixby는 FOO, BAR라고 답을 한다.
( Bixby Studio를 7.8.1-r19x.13460로 upgrade하면 나오는 warning에 대한 처리.
그전에 Bixby Studio를 7.8.1-r19x.13460로 upgrade하면 이전에 있는 예제 code에서 warning이 나온다.
나오는 위치는 capsule.bxb로 아래와 같은 경고이다.
Line 8:3DEPRECATED: `runtime-flags` is deprecated, move to `runtime-version`
[This deprecation will prevent new submissions in 20A] [deprecation 6797]View Deprecation Guide
그러면 capsule.bxb에 있는 runtime-flags { ... } 부분을 지우고 아래 code로 대체하면 그 경고는 사라진다.
runtime-version (2) {
overrides {
concepts-inherit-super-type-features (true)
}
)
먼저 helloWorld.js에서 입력을 받아서 처리하도록 해보자. 함수를 다음과 같이 바꾼다.
module.exports.function = function helloWorld (what) {
if (what == "foo")
return "foo, bar"
return "hello, world"
}
그러면 Bixby Studio는 바로 아래와 같은 경고를 내보낸다.
there is a warning:
The parameters [what] defined in the function 'null' are not listed in the 'accepted-inputs' []
accepted-inputs에 [what] parameter가 없다. accepted-input은 어디에 있는 것인지...
stack overflow나 bixby developer center에서 찾아보면 endpoints.bxb에서 사용하는 keyword.
즉, what이라는 변수를 Bixby에서 처리할 수 있도록 pipeline을 만들어 주어야 할 것같습니다.
먼저, what을 instance로 하는 hello type을 models/concepts/hello.model.bxb 에 만들어 준다.
( New -> Model -> template:text, name: models/concepts/hello.model.bxb )
그리고, action doHelloWorld에 input parameter가 있다는 것을 알려준다.
아래 내용을 action(doHelloWorld) 안에 넣는다.
collect {
input (what) {
type (hello)
min (Required)
max (One)
}
}
그리고, doHelloWorld action과 javascript을 연결하는 endpoint에 accepted-input keyword를 써서 입력이 있음을 알려준다. action-endpoint (doHelloWorld) 안에 한줄 추가
accepted-inputs (what)
여기까지 하면 warning은 사라지지만, Bixby emulator를 실행시켜보면 뭐라고 말하던 HELLO, WORLD만 외친다.
training에 say "foo"를 학습시켜야 한다. resources/en-US/training에 가서 click하면 학습된 say it이라는 문장이 보인다. 여기서 it을 hello type의 input이라고 알려주어야 한다. 아래와 같이 수정하자.
Save한 다음에 "Compile NL Model"을 click해주면 된다.
Bixby Emulator를 띄워서 say foo라고 치면 "foo, bar"라고 답할 것이다.
여기까지 내용은 제 개인 github에 올라가 있습니다.
마지막으로, Bixby가 이 일련의 과정을 어떻게 처리하는지 제가 이해한 바는 다음과 같습니다.
단말에서 say "foo"라고 하면
1. Bixby는 이 말을 say + parameter:foo로 분해해서
2. resources/en-US/training에 있는 NL Model에 넣는다.
3. NL Model에서 say + parameter pattern을 찾으면 출력이 text:world이다.
4. 출력이 text:world인 action인 doHelloWorld.model.bxb를 찾고,
5. action-endpoint(doHelloWorld)에서 helloWorld.js를 얻은 다음
6. helloWorld(parameter:foo)를 호출하여 return값으로 text:"foo, bar"를 얻는다.
7. 출력은 en-US/dialogs/helloVoice.dialog.bxb내 dialog(Result)에서 처리하는데,
8. text:"foo, bar"이면 "foo, bar"라고 소리를 낸다.