사용자의 스레드 읽기 상태에 대한 세부정보 가져오기

이 가이드에서는 getThreadReadState 메서드를 ThreadReadState 사용자의 채팅 요청에 대한 세부정보를 가져오기 위한 Google Chat API의 리소스입니다. 상태 정보를 전송합니다. 메시지의 읽기 상태를 가져오기 위해 확인하세요. 사용자의 스페이스 읽기 상태에 관한 세부정보 가져오기

ThreadReadState 리소스 인코더-디코더 아키텍처에 대한 세부정보를 나타내는 Google Chat 메시지 대화목록에서 지정된 사용자가 마지막으로 읽은 메시지입니다.

기본 요건

Python

  • Python 3.6 이상
  • pip 패키지 관리 도구
  • 최신 Google 클라이언트 라이브러리 이러한 앱을 설치하거나 업데이트하려면 다음 단계를 따르세요. 명령줄 인터페이스에서 다음 명령어를 실행합니다.
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

Node.js

  • Node.js 14 이상
  • npm 패키지 관리 도구
  • 최신 Google 클라이언트 라이브러리 이러한 앱을 설치하거나 업데이트하려면 다음 단계를 따르세요. 명령줄 인터페이스에서 다음 명령어를 실행합니다.
    npm install @google-cloud/local-auth @googleapis/chat
    

Apps Script

호출 사용자의 스레드 읽기 상태 가져오기

메일 대화목록 내에서 사용자의 읽기 상태에 관한 세부정보를 가져오려면 다음을 포함합니다. 다음을 포함합니다.

  • chat.users.readstate 또는 chat.users.readstate.readonly 지정 승인 범위입니다.
  • 먼저 getThreadReadState 메서드ThreadReadState 리소스.
  • 가져올 스레드 읽기 상태의 name를 전달합니다. 사용자 ID 또는 스페이스 ID로 구성됩니다. 스레드 읽기 상태 가져오기는 읽기 가져오기만 지원합니다. 상태를 호출할 수 있습니다. 이는 있습니다.
    • me 별칭. 예를 들면 users/me/spaces/SPACE/threads/THREAD/threadReadState입니다.
    • 발신자의 Workspace 이메일 주소입니다. 예를 들면 다음과 같습니다. users/user@example.com/spaces/SPACEthreads/THREAD/threadReadState
    • 호출하는 사용자의 사용자 ID입니다. 예를 들면 다음과 같습니다. users/USER/spaces/SPACE/threads/THREAD/threadReadState

다음 예에서는 호출하는 사용자의 스레드 읽기 상태를 가져옵니다.

Python

  1. 작업 디렉터리에서 chat_threadReadState_get.py
  2. chat_threadReadState_get.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.users.readstate.readonly"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then gets the thread read state for the calling user.
        '''
    
        # 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.users().spaces().threads().getThreadReadState(
    
            # The thread read state to get.
            #
            # Replace USER with the calling user's ID, Workspace email,
            # or the alias me.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace THREAD with a thread name.
            # Obtain the thread name from the messages resource of Chat API.
            name='users/me/spaces/SPACE/threads/THREAD/threadReadState'
    
          ).execute()
    
        # Prints the API's response.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. 코드에서 다음을 바꿉니다.

    • SPACE: 스페이스 이름입니다. GCP 콘솔에서 spaces.list 메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.

    • THREAD: 스레드 이름입니다. GCP 콘솔에서 spaces.messages.get 메서드 채팅 API에서 지원됩니다.

  4. 작업 디렉터리에서 샘플을 빌드하고 실행합니다.

    python3 chat_threadReadState_get.py
    

Node.js

  1. 작업 디렉터리에서 chat_threadReadState_get.js
  2. chat_threadReadState_get에 다음 코드를 포함합니다.

    const chat = require('@googleapis/chat');
    const {authenticate} = require('@google-cloud/local-auth');
    
    /**
    * Authenticates with Chat API via user credentials,
    * then gets the thread read state for the calling user.
    * @return {!Promise<!Object>}
    */
    async function getThreadReadState() {
    
      /**
      * Authenticate with Google Workspace
      * and get user authorization.
      */
      const scopes = [
        'https://www.googleapis.com/auth/chat.users.readstate.readonly',
      ];
    
      const authClient =
          await authenticate({scopes, keyfilePath: 'client_secrets.json'});
    
      /**
      * Build a service endpoint for Chat API.
      */
      const chatClient = await chat.chat({version: 'v1', auth: authClient});
    
      /**
      * Use the service endpoint to call Chat API.
      */
      return await chatClient.users.spaces.threads.getThreadReadState({
    
        /**
        * The thread read state to get.
        *
        * Replace USER with the calling user's ID, Workspace email,
        * or the alias me.
        *
        * Replace SPACE with a space name.
        * Obtain the space name from the spaces resource of Chat API,
        * or from a space's URL.
        */
        name: 'users/me/spaces/SPACE/threads/THREADS/threadReadState'
      });
    }
    
    /**
    * Use the service endpoint to call Chat API.
    */
    getThreadReadState().then(console.log);
    
  3. 코드에서 다음을 바꿉니다.

    • SPACE: 스페이스 이름입니다. GCP 콘솔에서 spaces.list 메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.

    • THREAD: 스레드 이름입니다. GCP 콘솔에서 spaces.messages.get 메서드 채팅 API에서 지원됩니다.

  4. 작업 디렉터리에서 샘플을 빌드하고 실행합니다.

    node chat_threadReadState_get.js
    

Apps Script

이 예시에서는 고급 채팅 서비스.

  1. chat.users.readstate.readonly 승인 범위를 Apps Script 프로젝트의 appsscript.json 파일:

    "oauthScopes": [
      "https://www.googleapis.com/auth/chat.users.readstate.readonly"
    ]
    
  2. 이와 같은 함수를 Apps Script 프로젝트의 코드:

    /**
    * Authenticates with Chat API via user credentials,
    * then gets the thread read state for the calling user.
    * @param {string} threadReadStateName The resource name of the thread read state.
    */
    function getThreadReadState(threadReadStateName) {
      try {
        Chat.Users.Spaces.Threads.getThreadReadState(threadReadStateName);
      } catch (err) {
        // TODO (developer) - Handle exception
        console.log('Failed to get read state with error %s', err.message);
      }
    }
    

Google Chat API는 지정된 스레드 읽기 상태를 가져오고 결과를 반환합니다. 인스턴스 ThreadReadState 리소스.