Search code examples
google-chat

Google Chat Bot doesn't receive non-mention message event in space


I recently joined a team that uses Google Chat for notifications. The manager has asked me to research Google Chat Bot. In the future, we can add it to our space, and the chatbot can help us handle some issues.

After setting up the bot, I am in the debug mode, I add the Bot into a space, my backend successfully receives ADDED_TO_SPACE event, and so do a REMOVED_FROM_SPACE event when I remove the bot from space.

If someone send non-mention(to the bot) message to the space, the bot doesn't make any reply to the message. Also I even found that, backend didn't receive any incoming request. But if someone send mention the bot message, like @BotName hi, my backend and the bot do receive the message.

I think I might have missed some configurations that caused the Google Chat service to not send incoming requests to backend.

This is my test code

SCOPES = ['https://www.googleapis.com/auth/chat.bot']

creds = Credentials.from_service_account_file('service_account.json', scopes=SCOPES)
chat = build('chat', 'v1', credentials=creds)


app = Flask(__name__)

@app.route('/', methods=['POST'])
def handle_bot_event():
    event_data = request.get_json()
    evt = event_data.get('type', None)
    space = event_data.get('space', None)
    
    if evt == 'MESSAGE':
        # handle MESSAGE event and make reply
    elif evt == 'ADDED_TO_SPACE' and space.get('type', None) == 'ROOM':
        # handle ADDED_TO_SPACE event

I run the dev server on localhost, and use ngrok to map the port, fill the ngrok URL into Google Chat like the following picture

GoogleChatSetting

I want the bot to receive all message event in the space. Is it possible? What should I do more?

I have read so many documents, but I think most of them apply to Hangouts, not apply for Google Chat.


Solution

  • No, it is not possible. Google chat doesn't support that feature.

    You can check the supported event here:

    https://developers.google.com/chat/api/guides/message-formats/events

    So only mention message events that are sent to your app URL. Here is the flow enter image description here

    If you want to read all message, you can call message list endpoint periodically. That endpoint will show all messages from users, including non-mentioned message.

    https://developers.google.com/chat/api/reference/rest/v1/spaces.messages/list