Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Permission issues with Google Chat API

Hello Everyone!

I created a chatbot that is connected to an AI model using a cloud run function. Because the model tends to be slow I used async messages using the chat API endpoint. It uses the following code:

 

 

def send_asynchronous_chat_message(thread_id, body, message_id=None):
    space_id = thread_id.split(",")[1]
    logging.info("space id %s" % space_id)
    space_name = f"spaces/{space_id}"

    SCOPES = ['https://www.googleapis.com/auth/chat.bot']
    credentials, project = google.auth.default(scopes=SCOPES)
    chat = build('chat', 'v1', credentials=credentials)

    # update content of an existing message
    if message_id:
        response_obj = chat.spaces().messages().update(
            name=message_id,
            updateMask='text',
            body=body
        ).execute()

    # create a new message
    else:
        response_obj = chat.spaces().messages().create(
            parent=space_name,
            body=body
        ).execute()

    return response_obj.get("name")

 

This works fine when I am using with the Google Chat API that is created in the same project as the cloud run function but when I put the Trigger URL to a Google Chat API that is in another organisation/project I get the following error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://chat.googleapis.com/v1/spaces/XXXXXXXXXXX/messages?alt=json returned "This Chat app is not a member of this space.". Details: "This Chat app is not a member of this space.">

Is there a solution to this? Without putting my app on the marketplace.

 

0 1 215
1 REPLY 1

Hi @Taki224

Welcome to Google Cloud Community!

It appears that a more thorough investigation of your project is necessary. For more detailed insights you may reach out to Google Workspace Support for assistance.

Top Labels in this Space
Top Solution Authors