Search code examples
chatchatbothangouts-apigoogle-hangouts

hangouts-chat: hangouts chat bot unable to post messages to a Bot implementation https endpoint


I have developed a HTTPS Synchronous end point that responds to POST messages and configured the URL as "Bot URL" under Chat bot configuration for Hangouts Chat. It is deployed to an EC2 in amazon aws and added a route53 entry for the URL: https://mychatbot-implementation which redirects HTTPS POSTs to my ec2.

However, chat bot is not posting any messages to the https end point and there are no errors logged.

Link to screenshot of chat-bot configuration

Chat Bot Implementation Code Here:

from flask import Flask, request, json, render_template, make_response

app = Flask(__name__)

@app.route('/', methods=['POST'])

def on_event():
  event = request.get_json()
  resp = None


  if event['type'] == 'REMOVED_FROM_SPACE':
    logging.info('Bot removed from space...')
  if event['type'] == 'ADDED_TO_SPACE':
    text = 'Thanks for adding me to "%s"!' % event['space']['displayName']
  elif event['type'] == 'MESSAGE':
    text = 'You said: `%s`' % event['message']['text']
  else:
    return
  return json.jsonify({'text': text})


if __name__ == '__main__':
  app.run(port=8080, ssl_context='adhoc', debug=True, host='my host ip address')

Could someone please advise on the next steps?


Solution

  • Unfortunately, mychatbot-implementation isn't a valid Internet TLD, so Route53 will never be able to route your request (in fact, it won't get it). You have 2 issues to be concerned with (bot implementation, user-reachability) and need to tackle them separately (divide-n-conquer) rather than trying to solve everything at once.

    I suggest that to test your bot implementation, you keep your bot running on EC2 and get a reachable IP address (w.x.y.z) to your instance (plus port#) and change your configuration to point to that, i.e., https://w.x.y.z:8080/ and see if the Hangouts Chat service can reach your bot. Once you get this working and your bot debugged, then you can worry about getting a TLD and registering with DNS.