이 페이지에서는 다음을 사용하여 채팅 앱을 만드는 방법을 설명합니다. Pub/Sub 이러한 유형의 유용한 채팅 앱 아키텍처 Chat이 채팅 앱으로 메시지를 전송하거나 채팅 앱은 Google Workspace Events API. 그러나 Kubernetes 아키텍처에는 이러한 아키텍처가 채팅 앱은 주고받기만 할 수 있습니다. 비동기 메시지:
- 대화상자를 사용할 수 없음 메시지를 보냅니다. 대신 카드 메시지를 참고하세요.
- 동기식 응답으로 개별 카드를 업데이트할 수는 없습니다. 대신
전체 메시지를
patch
드림 메서드를 사용하여 축소하도록 요청합니다.
다음 다이어그램은 Google Cloud의 Pub/Sub로 빌드된 채팅 앱:
위 다이어그램에서 Pub/Sub와 상호작용하는 사용자는 채팅 앱에는 다음과 같은 정보 흐름이 있습니다.
사용자가 Chat에서 채팅 메시지 또는 채팅 창 Chat 스페이스 또는 Chat 스페이스에서 이벤트가 발생하는 경우 채팅 앱에 활성 상태인 구독
Chat이 Pub/Sub 주제로 메시지를 전송합니다.
애플리케이션 서버(클라우드 또는 온프레미스 시스템)는 채팅 앱 로직을 포함하며, 방화벽을 통해 메시지를 수신할 Pub/Sub 주제
채팅 앱에서 선택적으로 Chat API를 통해 비동기식으로 메시지를 게시하거나 작업을 수행할 수 있습니다
기본 요건
자바
- 비즈니스 또는 기업 다음 액세스 권한이 있는 Google Workspace 계정 Google Chat
- 결제가 사용 설정된 Google Cloud 프로젝트. 기존 프로젝트에 결제가 사용 설정되어 있는지 확인하려면 다음 안내를 따르세요. 자세한 내용은 결제 상태를 볼 수 있습니다. 프로젝트를 만들고 결제를 설정하려면 다음을 참조하세요. Google Cloud 프로젝트를 만듭니다.
- Java 11 이상
- Maven 패키지 관리 도구
Python
- 비즈니스 또는 기업 다음 액세스 권한이 있는 Google Workspace 계정 Google Chat
- 결제가 사용 설정된 Google Cloud 프로젝트. 기존 프로젝트에 결제가 사용 설정되어 있는지 확인하려면 다음 안내를 따르세요. 자세한 내용은 결제 상태를 볼 수 있습니다. 프로젝트를 만들고 결제를 설정하려면 다음을 참조하세요. Google Cloud 프로젝트를 만듭니다.
- Python 3.6 이상
- pip 패키지 관리 도구
Node.js
- 비즈니스 또는 기업 다음 액세스 권한이 있는 Google Workspace 계정 Google Chat
- 결제가 사용 설정된 Google Cloud 프로젝트. 기존 프로젝트에 결제가 사용 설정되어 있는지 확인하려면 다음 안내를 따르세요. 자세한 내용은 결제 상태를 볼 수 있습니다. 프로젝트를 만들고 결제를 설정하려면 다음을 참조하세요. Google Cloud 프로젝트를 만듭니다.
- Node.js 14 이상
- npm 패키지 관리 도구
-
초기화된 Node.js 프로젝트 새 프로젝트를 초기화하려면
새 폴더로 전환한 후 명령줄 인터페이스에서 다음 명령어를 실행합니다.
npm init
환경 설정
Google API를 사용하려면 먼저 Google Cloud 프로젝트에서 사용 설정해야 합니다. 단일 Google Cloud 프로젝트에서 하나 이상의 API를 사용 설정할 수 있습니다.Google Cloud 콘솔에서 Google Chat API 및 Pub/Sub API를 사용 설정합니다.
Pub/Sub 설정
Pub/Sub 주제 만들기 채팅 API가 메시지를 보낼 수 있습니다 이때 채팅 앱당 단일 주제입니다.
Chat에 게시 권한 부여하기 다음 주제에 Pub/Sub 게시자 역할을 할당하여 서비스 계정:
chat-api-push@system.gserviceaccount.com
서비스 계정 만들기 채팅 앱이 Pub/Sub 및 채팅하면서 비공개 키 파일을 작업 디렉터리에 저장합니다.
풀 구독 만들기 주제를 자세히 살펴보겠습니다.
구독에 대한 Pub/Sub 구독자 역할을 할당합니다. 이전에 만든 서비스 계정에 대한 액세스 권한을 제공합니다
스크립트 작성
자바
CLI에서 서비스 계정 사용자 인증 정보를 제공합니다.
export GOOGLE_APPLICATION_CREDENTIALS=SERVICE_ACCOUNT_FILE_PATH
CLI에서 Google Cloud 프로젝트 ID를 제공합니다.
export PROJECT_ID=PROJECT_ID
CLI에서 Pub/Sub 구독의 구독 ID를 제공합니다. 다음을 수행합니다.
export SUBSCRIPTION_ID=SUBSCRIPTION_ID
작업 디렉터리에
pom.xml
라는 파일을 만듭니다.pom.xml
파일에 다음 코드를 붙여넣습니다.작업 디렉터리에
src/main/java
디렉터리 구조를 만듭니다.src/main/java
디렉터리에Main.java
라는 파일을 만듭니다.Main.java
에 다음 코드를 붙여넣습니다.
Python
CLI에서 서비스 계정 사용자 인증 정보를 제공합니다.
export GOOGLE_APPLICATION_CREDENTIALS=SERVICE_ACCOUNT_FILE_PATH
CLI에서 Google Cloud 프로젝트 ID를 제공합니다.
export PROJECT_ID=PROJECT_ID
CLI에서 Pub/Sub 구독의 구독 ID를 제공합니다. 다음을 수행합니다.
export SUBSCRIPTION_ID=SUBSCRIPTION_ID
작업 디렉터리에
requirements.txt
라는 파일을 만듭니다.requirements.txt
파일에 다음 코드를 붙여넣습니다.작업 디렉터리에
app.py
라는 파일을 만듭니다.app.py
에 다음 코드를 붙여넣습니다.
Node.js
CLI에서 서비스 계정 사용자 인증 정보를 제공합니다.
export GOOGLE_APPLICATION_CREDENTIALS=SERVICE_ACCOUNT_FILE_PATH
CLI에서 Google Cloud 프로젝트 ID를 제공합니다.
export PROJECT_ID=PROJECT_ID
CLI에서 Pub/Sub 구독의 구독 ID를 제공합니다. 다음을 수행합니다.
export SUBSCRIPTION_ID=SUBSCRIPTION_ID
작업 디렉터리에
package.json
라는 파일을 만듭니다.package.json
파일에 다음 코드를 붙여넣습니다.작업 디렉터리에
index.js
라는 파일을 만듭니다.index.js
에 다음 코드를 붙여넣습니다.
Chat에 앱 게시
Google Cloud 콘솔에서 메뉴 > API 및 서비스 > 사용 설정된 API 및 서비스 > Google Chat API > 구성을 탭합니다.
Pub/Sub용 채팅 앱을 구성합니다.
- 앱 이름에
Quickstart App
를 입력합니다. - 아바타 URL에
https://developers.google.com/chat/images/quickstart-app-avatar.png
를 입력합니다. - 설명에
Quickstart app
를 입력합니다. - 기능에서 1:1 메시지 수신 및 스페이스 및 그룹 대화 참여를 선택합니다.
- 연결 설정에서 Cloud Pub/Sub를 선택하고 이전에 만든 Pub/Sub 주제의 이름입니다.
- 공개 상태에서 도메인의 특정 사용자 및 그룹이 이 Google Chat 앱을 사용할 수 있도록 설정을 선택하고 이메일 주소를 입력합니다.
- 로그에서 Logging에 오류 로깅을 선택합니다.
- 앱 이름에
저장을 클릭합니다.
앱이 Chat에서 메시지를 수신하고 응답할 준비가 되었습니다.
스크립트 실행
CLI에서 작업 디렉터리로 전환하고 스크립트를 실행합니다.
자바
mvn compile exec:java -Dexec.mainClass=Main
Python
python -m venv env
source env/bin/activate
pip install -r requirements.txt -U
python app.py
Node.js
npm install
npm start
코드를 실행하면 애플리케이션이 게시된 메시지를 리슨하기 시작합니다. 살펴보겠습니다
채팅 앱 테스트
채팅 앱을 테스트하려면 다음을 사용하여 채팅 메시지 스페이스를 엽니다. 채팅 앱을 열고 메시지를 보내세요.
사용하는 Google Workspace 계정을 사용하여 Google Chat을 엽니다. 제공됩니다.
- 새 채팅을 클릭합니다.
- 1명 이상 사용자 추가 입력란에 채팅 앱
검색 결과에서 채팅 앱을 선택합니다. 직접 메시지가 열립니다.
- 앱과의 새 채팅 메시지에
Hello
을 입력하고enter
신뢰할 수 있는 테스터를 추가하고 양방향 기능 테스트에 관해 자세히 알아보려면 다음을 참고하세요. Google의 양방향 기능 테스트 Google Chat 앱.
문제 해결
Google Chat 앱 또는 card가 오류를 반환하는 경우 Chat 인터페이스에 '문제가 발생했습니다'라는 메시지가 표시됨 또는 '요청을 처리할 수 없습니다'와 같은 메시지가 표시됩니다. 채팅 UI가 오류 메시지가 표시되지 않지만 채팅 앱 또는 카드에서 예기치 않은 결과가 발생합니다. 예를 들어 카드 메시지가 나타납니다.
채팅 UI에 오류 메시지가 표시되지 않을 수도 있지만 오류 해결에 도움이 되는 오류 메시지 및 로그 데이터를 사용할 수 있음 채팅 앱의 오류 로깅이 사용 설정된 경우 보는 데 도움이 필요한 경우 오류를 수정하는 방법에 대한 자세한 내용은 Google Chat 오류 문제 해결하기
삭제
서비스 요금이 Google Cloud 계정에 청구되지 않도록 리소스 사용을 중단하려면 Cloud 프로젝트입니다.
-
Google Cloud 콘솔에서 리소스 관리 페이지로 이동합니다. 클릭
메뉴 > IAM 및 관리자
> 리소스 관리를 클릭합니다.
<ph type="x-smartling-placeholder"></ph> Resource Manager로 이동 를 통해 개인정보처리방침을 정의할 수 있습니다.
- 프로젝트 목록에서 삭제할 프로젝트를 선택한 후 를 삭제합니다.
- 대화상자에서 프로젝트 ID를 입력한 후 종료를 클릭하여 삭제합니다. 프로젝트입니다
관련 주제
채팅 앱에 기능을 더 추가하려면 다음을 참고하세요. 있습니다.