이 가이드에서는 Reaction
리소스에서 create
메서드를 사용하는 방법을 설명합니다.
Google Chat API의 도움을 받아 메시지에 대한 반응을 추가하세요. 예: 👍, 🏅, 애드센스를 사용합니다.
이
Reaction
리소스
사람들이 메시지에 반응하는 데 사용할 수 있는 이모티콘을 나타냅니다(예: 👍, ↩,
그리고 🏠
기본 요건
Python
- 비즈니스 또는 기업 다음 액세스 권한이 있는 Google Workspace 계정 Google Chat
- 환경을 설정합니다.
<ph type="x-smartling-placeholder">
- </ph>
- Google Cloud 프로젝트를 만듭니다.
- OAuth 동의 화면 구성
- Google Chat API를 사용 설정 및 구성합니다. 아이콘, 채팅 앱 설명이 있습니다.
- 설치 Python Google API 클라이언트 라이브러리를 참조하세요.
- <ph type="x-smartling-placeholder"></ph>
데스크톱 애플리케이션용 OAuth 클라이언트 ID 사용자 인증 정보 만들기 이 실습에서 샘플을 실행하려면
가이드에서 사용자 인증 정보를
client_secrets.json
이라는 JSON 파일로 로컬 디렉터리에 저장합니다
- <ph type="x-smartling-placeholder"></ph> 사용자 인증을 지원하는 승인 범위를 선택합니다.
메시지에 반응 추가하기
메시지에 대한 반응을 만들려면 요청:
chat.messages.reactions.create
,chat.messages.reactions
또는chat.messages
승인 범위- 먼저
create
메서드 에Reaction
리소스. parent
을 반응할 메시지의 리소스 이름으로 설정합니다.body
(요청 본문)을Reaction
여기서unicode
필드는 유니코드로 표시되는 표준 이모티콘입니다. 문자열.
다음 예는 버튼 이모티콘이 포함된 메시지에 반응합니다.
Python
- 작업 디렉터리에
chat_reaction_create.py
라는 파일을 만듭니다. chat_reaction_create.py
에 다음 코드를 포함합니다.from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build # Define your app's authorization scopes. # When modifying these scopes, delete the file token.json, if it exists. SCOPES = ["https://www.googleapis.com/auth/chat.messages.reactions.create"] def main(): ''' Authenticates with Chat API via user credentials, then creates a reaction to a message. ''' # Authenticate with Google Workspace # and get user authorization. flow = InstalledAppFlow.from_client_secrets_file( 'client_secrets.json', SCOPES) creds = flow.run_local_server() # Build a service endpoint for Chat API. chat = build('chat', 'v1', credentials=creds) # Use the service endpoint to call Chat API. result = chat.spaces().messages().reactions().create( # The message to create a reaction to. # # Replace SPACE with a space name. # Obtain the space name from the spaces resource of Chat API, # or from a space's URL. # # Replace MESSAGE with a message name. # Obtain the message name from the response body returned # after creating a message asynchronously with Chat REST API. parent = 'spaces/SPACE/messages/MESSAGE', # The reaction to the message. body = { 'emoji': { # A standard emoji represented by a unicode string. 'unicode': '😀' } } ).execute() # Prints details about the created reaction. print(result) if __name__ == '__main__': main()
코드에서 다음을 바꿉니다.
SPACE
:name
메시지가 게시되면spaces.list
메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.MESSAGE
: 가져올 수 있는 메시지 이름입니다. 비동기식으로 메시지를 만든 후 반환된 응답 본문에서 삭제 Chat API 또는 맞춤 이름 메시지를 만들 때 할당됩니다.
작업 디렉터리에서 샘플을 빌드하고 실행합니다.
python3 chat_reaction_create.py
Chat API는
Reaction
드림
반응이 생성됩니다.