Google Chat bot

I did this months ago so almost forgot most of the details. I'm supposed to write this earlier but keep forgetting it, sigh.

So here I'll just write down all the resources I bumped into while doing it. I'll put the context if I can remember it.

developers.google.com/hangouts/chat/how-tos..

There are 3 approaches to implement the boat:-

The HTTP endpoints is the most straightforward but I'm not interested in that. My bot will run behind firewall and I don't want to open any new port for the bot. When writing Slack bot, we can use its RTM API and for Telegram bot we can use polling method. Basically our code will connect to the API endpoint and wait for new message to come.

When I first look into the docs for pub/sub endpoint I was a bit turned off with the amount of steps to do but it turns out that it's very straightforward actually.

stackoverflow.com/questions/52557347/hangou..

Ensure that the account has publisher permission on the topic. You can do this by going to the Cloud Pub/Sub dashboard in the cloud console, clicking on the check box next to the topic to which you wish to publish, typing

I stuck here and I think the permission name has changed or something. But the answer in SO above gave me some hint and I managed to to add the correct permission.

Ok, I found some notes in my messy git repo:-

+Need some setup on Google Clould Console.
+
+  1. Create new Services Account under IAM & Admin. Create new key and download the json file. This is now stored at /etc/x4-alpha-bot-415c40068e93.json.
+  1. Create new Topics in Big Data ==> Pub/Sub. In Permissions, Add Member - chat-api-push@system.gserviceaccount.com, attach Role Pub/Sub Publisher.
+  1. Still under Pub/Sub create Subscriptions and under Permissions Add Member - chat-api-push@system.gserviceaccount.com, attach Role Pub/Sub Subscriber.