Search code examples
google-hangouts

Hangouts Chat - Authorizing access to third party services when using Pub/Sub


The documentation (https://developers.google.com/hangouts/chat/how-tos/auth-3p) suggests to send a direct message (with 'REQUEST_CONFIG' type) to the user:

Bots that use Cloud Pub/Sub endpoints cannot use this method that involves an HTTP response, because they aren't able to respond synchronously. Instead, they should implement a similar flow, but by asynchronously sending a direct message back to the user using Message.create.

Message.create requires a space name. How would I find out the space name for a direct message to the user if the original message I'm replying to was posted in a room?


Solution

  • As of now, the only way to directly DM a user is to have the user add the bot first. To dm a user when the original message was in a room, the workflow could look something like this:

    1. Users who would like to use the bot must directly message the bot ahead of time
    2. You can store the space_id as well as the user.displayName to a database
    3. Bot can see message in space and directly message the user querying the database for their space_id with the bot.
    4. If user is not in database, bot can @mention a user to prompt him to directly dm the bot using