ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Actions SDK로 google assistant Action 만들기
    google assistant 2019. 9. 1. 23:20

    google assistant에서 Action이란 사용자의 요청(intent, 의도에 의해 분류)에 따른 적절한 응답을 정의하는 것이다.

    google assistant Action을 정의하는데에는 대표적으로 Dialogflow와 Actions SDK 두 가지 tool을 사용할 수 있다.

    Dialogflow는 구글에서 제공하는 NLU(자연어 처리) API.AI이다. 미리 정의된 패턴을 통해 사용자가 무슨 말을 하는 지 이해하는 도구이다. Dialogflow는 구글 어시스턴트 앱을 만드는 데 쓰일 뿐만 아니라, 챗봇을 만드는 채널에도 사용된다.

    Actions SDK는 개발자들이 구글 어시스턴트 앱을 쉽게 제작하도록 구글에서 제공하는 library며, NLU기능이 제공되지 않는다.

    만약 개발자가 자체의 NLU를 갖고 있다면, Actions SDK를 사용하여 어시스턴트 앱을 제작하면 된다.

    자체 NLU를 갖고있지 않다면, Dialogflow를 이용하여 자연어처리가 지원되는 어시스턴트 앱을 만들 수 있다.

    이 글에서는 Actions SDK(Node.js)를 통해 간단한 액션을 정의하는 방법을 설명한다.


    1. Actions console에서 프로젝트를 생성

    new project 버튼을 클릭하여 창이 뜨면,


     

    프로젝트 이름을 입력하고 프로젝트를 생성한다.


     

     

    프로젝트 생성 후 화면 하단에 Actions SDK를 선택한다.


     

     

    gactions cli앱을 통해서 action 패키지를 업데이트 하라는 말이 나온다. 확인 버튼을 누른다.

     

     


    2. gactions cli 설치

    (https://developers.google.com/actions/tools/gactions-cli

    나의 로컬 프로젝트 디렉토리에 gactions cli를 설치한다.  (mac os 기준 / 타 os는 위 링크에서 설치 법 확인 가능합니다. )

    // install
    $ curl -O https://dl.google.com/gactions/updates/bin/darwin/amd64/gactions/gactions
    
    // chmod
    chmod : chmod +x gactions
    
    // create action package(action.json)
    using : ./gactions init
    
    // update your action package,
    // [PACKAGE_NAME]: 현재 디렉토리 내 action.json(이름변경 가능)
    // [PROJECT_ID]: actions 콘솔(project settings 탭에서 확인)에서 내 프로젝트 id 확인가능
    update : ./gactions update --action_package [PACKAGE_NAME] --project [PROJECT_ID]

    init 명령어를 입력하면 action.json 이란 액션 패키지가 생성된다.

    원하는 conversation 이름을 입력한 뒤, fullfillment url 영역은 내가 사용할 node.js 서버의 주소를 등록하면 된다.

     

    그 후 위의 update 명령어를 입력하면, cli 상에서 인증을 위한 링크를 준다. 링크를 따라가서 구글 아이디로 인증을 한 후 auth code 를 받아 cli에 입력하면 내 프로젝트에 액션 패키지(action.json)가 업데이트 된다.


    3. fullfullment 빌드

    (https://developers.google.com/actions/sdk/fulfillment#actionsdk)

     

     

    Build Fulfillment  |  Actions on Google  |  Google Developers

    Learn more about building responses The documentation here describes how to build fulfillment generally. See Surface Capabilities and Responses, for more information on how to handle specific portions of your conversation. Fulfillment defines the conversat

    developers.google.com

    'use strict';
    
    const {actionssdk} = require('actions-on-google');
    const functions = require('firebase-functions');
    
    const app = actionssdk({debug: true});
    
    // 나의 앱을 호출할때 앱의 동작 정의
    app.intent('actions.intent.MAIN', (conv) => {
      conv.ask('나의 첫 테스트 앱에 온 것을 환영합니다.');
    });
    
    // 호출 동작 후 나의 말(input)에 따른 응답을 정의
    app.intent('actions.intent.TEXT', (conv, input) => {
     if(input === '사과'){
       conv.ask(input + '는 과일이야');
     } 
     // ... 사용자의 요청에 따른 적절한 응답 작성
      
    });
    
    // More intent handling if needed
    exports.myFunction = functions.https.onRequest(app);

    나의 node.js 프로젝트에 다음과 같은 함수를 작성하고 서버를 동작시킨다. 서버의 호스팅 주소는 action.json에 등록한 fullfillment url 주소와 동일해야 한다.


    4.  Actions console에서 나의 action 테스트

    나의 Actions console 프로젝트에서 내가 빌드한 fullfillment를 테스트 해볼 수 있다.

    댓글

Designed by Tistory.