이 가이드에서는 Google Chat API의 Reaction
리소스에서 delete
메서드를 사용하여 메시지에서 반응을 삭제하는 방법(예: 👍, が, 💯)을 설명합니다. 반응을 삭제해도 메시지는 삭제되지 않습니다.
Reaction
리소스는 사람들이 메시지에 반응하는 데 사용할 수 있는 그림 이모티콘을 나타냅니다(예: 👍, ↘, Windows).
기본 요건
Python
- Python 3.6 이상
- pip 패키지 관리 도구
Python용 최신 Google 클라이언트 라이브러리입니다. 이를 설치하거나 업데이트하려면 명령줄 인터페이스에서 다음 명령어를 실행합니다.
pip3 install --upgrade google-api-python-client google-auth-oauthlib
- Google Chat API가 사용 설정되고 구성된 Google Cloud 프로젝트 단계는 Google Chat 앱 빌드를 참고하세요.
채팅 앱에 구성된 승인입니다. 반응을 삭제하려면
chat.messages.reactions
또는chat.messages
승인 범위를 사용하는 사용자 인증이 필요합니다.
반응 삭제
메시지에서 반응을 삭제하려면 요청에 다음을 전달합니다.
chat.messages.reactions
또는chat.messages
승인 범위를 지정합니다.Reaction
리소스에서delete
메서드를 호출합니다.name
을 삭제할 반응의 리소스 이름으로 설정합니다.
다음 예에서는 메시지에서 키 반응을 삭제합니다.
Python
- 작업 디렉터리에
chat_reaction_delete.py
라는 파일을 만듭니다. chat_reaction_delete.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"] def main(): ''' Authenticates with Chat API via user credentials, then deletes 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().delete( # The reaction to delete. # # 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. # # Replace REACTION with a reaction name. # Obtain the reaction name from the reaction resource of Chat API. name = 'spaces/SPACE/messages/MESSAGE/reactions/REACTION' ).execute() if __name__ == '__main__': main()
코드에서 다음을 바꿉니다.
SPACE
: Chat API의spaces.list
메서드 또는 스페이스 URL에서 가져올 수 있는 스페이스 이름입니다.MESSAGE
: 메시지 이름입니다. Chat API를 사용하여 비동기식으로 메시지를 만든 후 반환된 응답 본문에서 가져오거나 생성 시 메시지에 할당된 커스텀 이름을 사용하여 가져올 수 있습니다.REACTION
: 반응 이름으로, Chat API의spaces.messages.reactions.list
메서드에서 가져오거나 Chat API를 사용하여 비동기식으로 반응을 만든 후 반환된 응답 본문에서 가져올 수 있습니다.
작업 디렉터리에서 샘플을 빌드하고 실행합니다.
python3 chat_reaction_delete.py
성공하면 응답 본문이 비어 있으며, 이는 반응이 삭제되었음을 나타냅니다.