Search code examples
javabotsgoogle-cloud-pubsubgoogle-hangoutshangouts-api

Hangout chat to a bot doesn't post the message to pub/sub


I followed the steps in https://developers.google.com/hangouts/chat/how-tos/bots-publish

If I post to a topic through google console it received in java code for subscriber https://console.cloud.google.com/cloudpubsub/topics/

But chatting with the bot doesn't post the message to Pub/Sub

Help me around


Solution

  • Here are some common things that can go wrong if you aren't able to get your chat bot to send messages to Cloud Pub/Sub:

    1. Ensure that the serviceAccount:[email protected] 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 serviceAccount:[email protected] into the box under "Add members" on the right, selecting the "Pub/Sub Publisher permission," and clicking on the "Add" button. If you do not see this panel on the side, you may need to click on "Show Info Panel" in the upper righthand corner. Here is a screenshot of the page with the relevant pieces highlighted:

    Cloud Pub/Sub Console Page

    1. When proving the name of the topic in the bot configuration page, make sure you specify the full path, including the project name. The topic name should be of the form projects/<project name>/topics/<topicname>.

    2. Make sure the subscription exists before you attempt to chat with your bot. Messages published before a subscription is created will not be delivered to that subscription.

    If you've gotten this far and things are still not working, try sending messages to your bot and then pulling them via the gcloud command line tool with the command

     gcloud pubsub subscriptions pull <subscription name> --project <project name>
    

    You should see a table output with the messages received. If you can get this output, then messages are flowing correctly from the bot to the Cloud Pub/Sub topic and then to the subscription on that topic.