5

We are implementing a Google hangout Chat Bot , Which will send proactive notification to the user in domain. To do this Google chat Bot API requires the space Id to send proactive notification to user.

Reference document: https://developers.google.com/hangouts/chat/reference/rest/v1/spaces/list

code :

jwtClient.authorize(function (err) {
                if (err) {
                    console.log(err);
                    return;
                }
                else {
                    chat.spaces.list({
                        auth: jwtClient
                    }, function (err, resp) {
                        if (err)
                            console.log(err);
                        else {
                            chat.spaces.list({
                                auth: jwtClient
                            }, function (err, resp) {
                                if (err)
                                    console.log(err);
                                else {
                                    var spaceList = resp.data.spaces;
                                    spaceList.forEach(element => {
                                        var spaceUrl = `https://chat.googleapis.com/v1/${element.name}/messages?key=${apiKey}`;
                                        request({
                                            url: spaceUrl,
                                            method: "POST",
                                            headers: {
                                                'Content-Type': 'application/json'
                                            },
                                            json: customMessage
                                        },
                                            function (error, response, body) {
                                                callback(error, body)
                                            }
                                        );
                                    })
                                };
                            });
                        }
                    });
                }
            });
        }
    }

But This API returns space list of only those user , who has added the Bot to their coversation.

Is their any work around to get/create space of/to every user in google domain?

Planet-Zoom
  • 1,005
  • 2
  • 9
  • 20

1 Answers1

2

Unfortunately there is no way to extract the Space ID without the user ever interacting with the bot. Allowing this would give the bot ability to spam any user whenever without consent.

I would suggest storing space IDs to a database. So once a user has started a conversation with a bot, you can later message them whenever you want. Adding the bot or interacting with it in a room is the "consent" that is needed for a bot to message a user.

Logan Cundiff
  • 479
  • 8
  • 13
  • Well space id , we get is from the domain of gsuite. so there should not be a case of spam. Bot can interact with the users in the domain only.. – Planet-Zoom Jul 19 '18 at 11:37
  • 2
    Yes, the bot can only interact with users in the domain, which I agree Google should provide a way of retrieving space id of all users in a domain. However this is only the first version of API, so this may be solved in future versions. – Logan Cundiff Jul 24 '18 at 20:53
  • Hoping Google adds a method to retrieve the Space ID. I am grabbing the Space ID on the ADDED_TO_SPACE event and storing it on their employee record. In my send message routine if I don't find the Space ID on their employee record I send an email asking them to interact with the bot. Only 1/3 of the employees have added the bot. – PLA Oct 24 '18 at 16:47
  • 1
    Even after a year this question puzzles us!! Same case with us - only 1/3 of the employees have added the bot – Darpan Sanghavi Apr 20 '20 at 10:35
  • Yep, I still have this problem as well. We need a way to know each user's space id. – Jason Jurotich Apr 25 '23 at 18:10