-1

I have setup a fully operational chat bot in Hangouts Chat orchestrated by a tailored webserver. I would like now to be able to have this webserver to interact with other Hangouts bots that I created and to route some requests to some of my other servers that will have to know which bots initiated the event. With other provider, such as Slack, the app_id is provided in the event request data. But with hangouts, this is not the case. I could not find any data in the request body or headers that represent either project_id or client_id. In a more simple way my question is : "How to identify the Hangouts bot that send me an event request?" :)

Watchoutman
  • 37
  • 1
  • 10

2 Answers2

0

An event request's response will contain an Event instance in its body, which one of its fields will be an User object. That User object will contain a name field that will represent the user's id (whether it's a human or a bot).

It will look like this:

{
  "name": "users/<id>",
  "displayName": "<name that appears in the chat>",
  "type": "BOT" 
}
alberto vielma
  • 2,302
  • 2
  • 8
  • 15
  • Thx for your reply. This is true when the bot send a message but in most of the case, we want to be noticed when the user talks to our bots. And when this is the cas (ie, a user that causes the event "MESSAGE" to be emitted) the message.sender User instance refers to the "HUMAN" user and not the bot. So I cannot know to which of my bots the user is talking to. But thanks to you I found the solution, because your reply made me dive again in this issue and found my answer in headers... see my own reply ;) – Watchoutman Jan 20 '20 at 11:29
  • Hey! I'm glad you could find the solution by yourself and with a little help from my answer, please consider post your solution as an answer with an explanation so other people which have the same problem could solve it, too – alberto vielma Jan 20 '20 at 11:35
0

One month later, I finally found the time to answer my question :)

In order to identify the Hangouts project that is calling your server, when you receive an event from Hangouts Chat, you'll find in the incoming request the header Authorization whose value is something like Bearer abcd1234. If you decode this JWToken (ie, abcd1234 in our example), in the resulting data, you'll have a field aud which is exactly the "project number" of your Hangouts app. This "project number" can be found at "https://console.cloud.google.com/home/dashboard?project=referenceofyourprojecthere".

Watchoutman
  • 37
  • 1
  • 10