Google Chat स्पेस में उपयोगकर्ता की सदस्यता अपडेट करना

इस गाइड में, membership संसाधन पर patch तरीके को इस्तेमाल करने का तरीका बताया गया है का इस्तेमाल किया जा सकता है. स्पेस के सदस्य को स्पेस मैनेजर बनाना या स्पेस मैनेजर को स्पेस का सदस्य बनाना.

कॉन्टेंट बनाने Membership संसाधन यह बताता है कि किसी उपयोगकर्ता या Google Chat ऐप्लिकेशन को किसी स्पेस का हिस्सा है या नहीं है.

ज़रूरी शर्तें

Python

  • कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.
  • Python 3.6 या इससे नया वर्शन
  • पीआईपी पैकेज मैनेजमेंट टूल
  • Google की नई क्लाइंट लाइब्रेरी. उन्हें इंस्टॉल या अपडेट करने के लिए, अपने कमांड-लाइन इंटरफ़ेस में यह कमांड चलाएं:
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

Node.js

  • कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.
  • Node.js 14 या उसके बाद का वर्शन
  • npm पैकेज मैनेजमेंट टूल
  • Google की नई क्लाइंट लाइब्रेरी. उन्हें इंस्टॉल या अपडेट करने के लिए, अपने कमांड-लाइन इंटरफ़ेस में यह कमांड चलाएं:
    npm install @google-cloud/local-auth @googleapis/chat
    

Apps Script

  • कारोबार या एंटरप्राइज़ Google Workspace खाता, जिसके पास इसका ऐक्सेस है Google Chat.

पैसे चुकाकर ली गई सदस्यता अपडेट करना

स्पेस की सदस्यता अपडेट करने के लिए, अपने अनुरोध में यह जानकारी दें:

  • chat.memberships की अनुमति के दायरे के बारे में बताएं.
  • कॉल करें patch तरीका Membership संसाधन पर उपलब्ध है, और सदस्यता को अपडेट करने के लिए, name को पास करें. साथ ही, updateMask और body, जो अपडेट किए गए सदस्यता एट्रिब्यूट की जानकारी देता है.
  • updateMask में, पैसे चुकाकर ली जाने वाली सदस्यता से जुड़ी जानकारी को अपडेट किया जाता है. इसमें ये शामिल हैं:
    • role: चैट स्पेस में उपयोगकर्ता की भूमिका. इससे तय होता है कि उसे किन उपयोगकर्ताओं को सूचना भेजनी है कार्रवाइयां. आपको ये वैल्यू दिख सकती हैं:
      • ROLE_MEMBER: स्पेस का सदस्य. उपयोगकर्ता के पास बुनियादी अनुमतियां होती हैं, जैसे कि स्पेस में मैसेज भेजना. 1:1 और बिना नाम वाले ग्रुप में बातचीत, सभी की भूमिका है.
      • ROLE_MANAGER: स्पेस मैनेजर. उपयोगकर्ता के पास सभी बुनियादी अनुमतियां और साथ ही एडमिन से जुड़ी अनुमतियों की मदद से, वह स्पेस को मैनेज कर सकता है. जैसे: सदस्यों को हटाने के बारे में ज़्यादा जानें. यह सुविधा सिर्फ़ उन स्पेस में काम करती है जहां spaceType, SPACE है (नाम वाले स्पेस).

स्पेस के किसी नियमित सदस्य को स्पेस मैनेजर बनाना

स्पेस के सामान्य सदस्य को स्पेस मैनेजर बनाने के लिए, नीचे दिए गए उदाहरण में बताया गया है: body में ROLE_MANAGER के तौर पर role, जो अपडेट की गई सदस्यता की जानकारी देता है विशेषताएं:

Python

  1. अपनी वर्किंग डायरेक्ट्री में, chat_membership_update.py नाम की फ़ाइल बनाएं.
  2. chat_membership_update.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.memberships"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then updates a specified space member to change
        it from a regular member to a space manager.
        '''
    
        # 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().members().patch(
    
            # The membership to update, and the updated role.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MEMBERSHIP with a membership name.
            # Obtain the membership name from the membership of Chat API.
            name='spaces/SPACE/members/MEMBERSHIP',
            updateMask='role',
            body={'role': 'ROLE_MANAGER'}
    
          ).execute()
    
        # Prints details about the updated membership.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.

    • MEMBERSHIP: सदस्यता का नाम, जो तो आपको यहां से spaces.members.list तरीका Chat API में.

  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    python3 chat_membership_update.py
    

Node.js

  1. अपनी वर्किंग डायरेक्ट्री में, chat_membership_update.js नाम की फ़ाइल बनाएं.
  2. chat_membership_update.js में यह कोड शामिल करें:

    const chat = require('@googleapis/chat');
    const {authenticate} = require('@google-cloud/local-auth');
    
    /**
    * Updates a membership in a Chat space to change it from
    * a space member to a space manager.
    * @return {!Promise<!Object>}
    */
    async function updateSpace() {
    
      /**
      * Authenticate with Google Workspace
      * and get user authorization.
      */
      const scopes = [
        'https://www.googleapis.com/auth/chat.memberships',
      ];
    
      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.spaces.patch({
    
        /**
        * The membership to update, and the updated role.
        *
        * Replace SPACE with a space name.
        * Obtain the space name from the spaces resource of Chat API,
        * or from a space's URL.
        *
        * Replace MEMBERSHIP with a membership name.
        * Obtain the membership name from the membership of Chat API.
        */
        name: 'spaces/SPACE/members/MEMBERSHIP',
        updateMask: 'role',
        requestBody: {
          role: 'ROLE_MANAGER'
        }
      });
    }
    
    /**
    * Use the service endpoint to call Chat API.
    */
    updateSpace().then(console.log);
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.

    • MEMBERSHIP: सदस्यता का नाम, जो तो आपको यहां से spaces.members.list तरीका Chat API में.

  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    python3 chat_membership_update.js
    

Apps Script

इस उदाहरण में, Chat API को बेहतर चैट सेवा.

  1. chat.memberships की अनुमति का स्कोप जोड़ें Apps Script प्रोजेक्ट की appsscript.json फ़ाइल:

    "oauthScopes": [
      "https://www.googleapis.com/auth/chat.memberships"
    ]
    
  2. Apps Script प्रोजेक्ट के लिए, इस तरह का फ़ंक्शन जोड़ें कोड:

    /**
     * Updates a membership from space member to space manager.
     * @param {string} memberName The resource name of the membership.
    */
    function updateMembershipToSpaceManager(memberName) {
      try {
        const body = {'role': 'ROLE_MANAGER'};
        Chat.Spaces.Members.patch(memberName, body);
      } catch (err) {
        // TODO (developer) - Handle exception
        console.log('Failed to create message with error %s', err.message);
      }
    }
    

Google Chat API, उस सदस्यता को स्पेस मैनेजर में बदल देता है और वापस आ जाता है Membership का एक इंस्टेंस जानकारी दी गई है.

स्पेस मैनेजर को सामान्य सदस्य बनाना

स्पेस मैनेजर को स्पेस का सामान्य सदस्य बनाने के लिए, नीचे दिए गए उदाहरण में बताया गया है: body में ROLE_MEMBER के तौर पर role, जो अपडेट की गई सदस्यता की जानकारी देता है विशेषताएं:

Python

  1. अपनी वर्किंग डायरेक्ट्री में, chat_membership_update.py नाम की फ़ाइल बनाएं.
  2. chat_membership_update.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.memberships"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then updates a specified space member to change
        it from a regular member to a space manager.
        '''
    
        # 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().members().patch(
    
            # The membership to update, and the updated role.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MEMBERSHIP with a membership name.
            # Obtain the membership name from the membership of Chat API.
            name='spaces/SPACE/members/MEMBERSHIP',
            updateMask='role',
            body={'role': 'ROLE_MEMBER'}
    
          ).execute()
    
        # Prints details about the updated membership.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.

    • MEMBERSHIP: सदस्यता का नाम, जो तो आपको यहां से spaces.members.list तरीका Chat API में.

  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    python3 chat_membership_update.py
    

Node.js

  1. अपनी वर्किंग डायरेक्ट्री में, chat_membership_update.js नाम की फ़ाइल बनाएं.
  2. chat_membership_update.js में यह कोड शामिल करें:

    const chat = require('@googleapis/chat');
    const {authenticate} = require('@google-cloud/local-auth');
    
    /**
    * Updates a membership in a Chat space to change it from
    * a space manager to a space member.
    * @return {!Promise<!Object>}
    */
    async function updateSpace() {
    
      /**
      * Authenticate with Google Workspace
      * and get user authorization.
      */
      const scopes = [
        'https://www.googleapis.com/auth/chat.memberships',
      ];
    
      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.spaces.patch({
    
        /**
        * The membership to update, and the updated role.
        *
        * Replace SPACE with a space name.
        * Obtain the space name from the spaces resource of Chat API,
        * or from a space's URL.
        *
        * Replace MEMBERSHIP with a membership name.
        * Obtain the membership name from the membership of Chat API.
        */
        name: 'spaces/SPACE/members/MEMBERSHIP',
        updateMask: 'role',
        requestBody: {
          role: 'ROLE_MEMBER'
        }
      });
    }
    
    /**
    * Use the service endpoint to call Chat API.
    */
    updateSpace().then(console.log);
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जो तो आपको यहां से spaces.list तरीका या स्पेस के यूआरएल से मिलेगी.

    • MEMBERSHIP: सदस्यता का नाम, जो तो आपको यहां से spaces.members.list तरीका Chat API में.

  4. अपनी वर्किंग डायरेक्ट्री में, सैंपल बनाएं और चलाएं:

    python3 chat_membership_update.js
    

Apps Script

इस उदाहरण में, Chat API को बेहतर चैट सेवा.

  1. chat.memberships की अनुमति का स्कोप जोड़ें Apps Script प्रोजेक्ट की appsscript.json फ़ाइल:

    "oauthScopes": [
      "https://www.googleapis.com/auth/chat.memberships"
    ]
    
  2. Apps Script प्रोजेक्ट के लिए, इस तरह का फ़ंक्शन जोड़ें कोड:

    /**
     * Updates a membership from space manager to space member.
     * @param {string} memberName The resource name of the membership.
    */
    function updateMembershipToSpaceMember(memberName) {
      try {
        const body = {'role': 'ROLE_MEMBER'};
        Chat.Spaces.Members.patch(memberName, body);
      } catch (err) {
        // TODO (developer) - Handle exception
        console.log('Failed to create message with error %s', err.message);
      }
    }
    

Google Chat API, उस सदस्यता को स्पेस मैनेजर में बदल देता है और वापस आ जाता है Membership का एक इंस्टेंस जानकारी दी गई है.