Google Chat 앱의 홈페이지 빌드하기

이 페이지에서는 나만의 홈페이지를 만드는 방법을 Google Chat 앱 앱 홈은 맞춤설정이 가능한 카드 인터페이스입니다. 사용자가 채팅 앱을 열 때 채팅 앱에서 사용자에게 보내는 채팅 앱으로 메시지를 주고받을 수 있습니다.

위젯 2개가 있는 앱 홈 카드

예를 들어 다음을 사용하는 채팅 앱 슬래시 명령어 최종 사용자의 경우 앱 홈은 다음과 같은 경우 채팅 앱의 채팅 메시지에서만 사용할 수 있습니다. 앱 개발자가 기능을 사용 설정해야 합니다.


카드 빌더를 사용하여 채팅 앱용 JSON 카드 메시지를 디자인하고 미리 봅니다.

카드 빌더 열기 <ph type="x-smartling-placeholder">
</ph>

기본 요건

Python

Apps Script

Google Cloud 콘솔에서 구성

Python

  1. Google Cloud 콘솔에서 메뉴로 이동합니다. <ph type="x-smartling-placeholder"></ph> &gt; 제품 더보기 &gt; Google Workspace &gt; 제품 라이브러리 &gt; Google Chat API.

    Google Chat API로 이동

  2. 관리를 클릭한 다음 구성 탭을 클릭합니다.

  3. 지원 앱 홈을 사용 설정합니다.

  4. Support App Home 체크박스를 선택합니다.

  5. App Home URL(앱 홈 URL) 입력란에 URL을 추가합니다. 이 값은 일반적으로 동일합니다. URL을 앱 URL로 사용합니다. 이 URL은 APP_HOME 이벤트.

  6. 저장을 클릭합니다.

Apps Script

  1. Google Cloud 콘솔에서 메뉴로 이동합니다. <ph type="x-smartling-placeholder"></ph> &gt; 제품 더보기 &gt; Google Workspace &gt; 제품 라이브러리 &gt; Google Chat API.

    Google Chat API로 이동

  2. 관리를 클릭한 다음 구성 탭을 클릭합니다.

  3. Support App Home 체크박스를 선택합니다.

  4. 저장을 클릭합니다.

Chat 앱 구성

앱 홈용 채팅 앱을 구성합니다.

Python

사용자가 채팅 앱에서 채팅 메시지를 열면 APP_HOME 이벤트가 채팅 앱으로 전송됩니다. 사용자가 채팅 앱은 RenderActions pushCard 탐색과 함께 반환됩니다.

@app.route('/', methods=['POST'])
def on_event():
  event = request.get_json()
  chat = event.get('chat')
  if chat is not None:
    return handle_chat_event(event)

def handle_chat_event(event):
  if event['chat'].get('type') == 'APP_HOME':
    return get_app_home_card()

def get_app_home_card():
  return {
    "action": {
      "navigations": [
        {
          "pushCard": {
            "sections": [
              {
                "widgets": [
                  {
                    "buttonList": {
                      "buttons": [
                        {
                          "text": "Open documentation",
                          "onClick": {
                            "openLink": {
                              "url": "https://developers.google.com/chat"
                            }
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  }

Apps Script

이 예시에서는 카드 JSON과 함께 사용합니다. 또한 Apps Script 카드 서비스.

onAppHome 함수를 구현하여 RenderActions pushCard 탐색:

// "onAppHome" is the pre-defined name of the callback that the Chat servers
// execute.
function onAppHome() {
  return {
    action: {
      navigations: [
        {
          pushCard: getCard()
        }
      ]
    }
  };
}

function getCard() {
  return {
    sections: [
      {
        widgets: [
          {
            buttonList: {
              buttons: [
                {
                  text: "Open documentation",
                  onClick: {
                    openLink: {
                      url: "https://developers.google.com/chat"
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    ]
  };
}

앱 홈 카드 업데이트

사용자가 정보를 제출하거나 앱을 종료할 때 앱 홈 카드를 업데이트할 수 있습니다. 대화상자 예를 들어 초기 앱 홈 카드에는 사용자에게 정보로 양식을 작성하도록 요청합니다. 사용자가 양식에서 앱 홈 카드가 업데이트됩니다. 업데이트가 인스턴스와 함께 반환되어야 합니다. /RenderActions updateCard 탐색이 포함된 클래스

Python

HTTP 앱의 경우 앱 홈 카드를 업데이트하는 방법은 다음과 비슷합니다. 사용자가 입력한 정보를 처리합니다. 하지만 RenderActions를 반환해야 합니다. invokedFunctionCard 위젯과 연결된 호출된 함수입니다. 자세한 내용은 보기 CommonEventObject 다음 예에서 submitForm 드림 사용자가 양식을 제출했음을 보여줍니다. 데이터:

@app.route('/', methods=['POST'])
def on_event():
  event = request.get_json()
  chat = event.get('chat')
  if chat is not None:
    return handle_chat_event(event)

def handle_chat_event(event):
  if event['chat'].get('type') == 'SUBMIT_FORM':
    event_object = event.get('commonEventObject')
    if event_object is not None:
      // Forms
      if 'submitForm' == event_object.get('invokedFunction'):
        return {
          'render_actions': {
            'action': {
              'navigations': [{
                'updateCard': get_update_card()
              }]
            }
          }
        }

def get_update_card():
  return {
      "action": {
          "navigations": [{
              "pushCard": {
                  "sections": [{
                      "widgets": [{
                          "buttonList": {
                              "buttons": [{
                                  "text": "Open documentation",
                                  "onClick": {
                                      "openLink": {
                                          "url": "https://developers.google.com/chat"
                                      }
                                  },
                              }]
                          }
                      }]
                  }]
              }
          }]
      }
  }

Apps Script

이 예시에서는 카드 JSON과 함께 사용합니다. 또한 Apps Script 카드 서비스.

// Called from elsewhere (i.e. on button press).
function updateAppHomeCard(event) {
  return {
    render_actions: {
      action: {
        navigations: [
          {
            updateCard: getCard()
          }
        ]
      }
    }
  }
}

function getCard() {
  return {
    sections: [
      {
        widgets: [
          {
            buttonList: {
              buttons: [
                {
                  text: "Open documentation",
                  onClick: {
                    openLink: {
                      url: "https://developers.google.com/chat"
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    ]
  };
}

제한사항

일반적으로 navigation: 채팅 앱에서는 사용할 수 없습니다. 여러 장의 카드를 반환할 수 없습니다. pushCard (초기 응답용) 및 updateCard (업데이트용)만 채팅 앱에서 사용할 수 있습니다.