From 0f6c33528c0c30e8c83471771d9fdf71e8361eb8 Mon Sep 17 00:00:00 2001 From: Nicholas C Date: Thu, 2 Mar 2023 22:20:51 +1100 Subject: [PATCH] feat: small clean up --- .gitignore | 8 ++++++++ config/service-acct.json.sample | 1 + main.py | 17 ++++++++++------- requirements.txt | 3 ++- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 config/service-acct.json.sample diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1da188f --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Configs +config/service-acct.json + +# Logs +*.log + +# JetBrains stuff +.idea/ diff --git a/config/service-acct.json.sample b/config/service-acct.json.sample new file mode 100644 index 0000000..a54c9f5 --- /dev/null +++ b/config/service-acct.json.sample @@ -0,0 +1 @@ +https://cloud.google.com/iam/docs/keys-create-delete \ No newline at end of file diff --git a/main.py b/main.py index 03c516d..ac2b4ee 100644 --- a/main.py +++ b/main.py @@ -21,11 +21,11 @@ Hangouts Chat bot that responds to events and messages from a room asynchronousl import logging -from googleapiclient.discovery import build -from flask import Flask, render_template, request, json -import google.auth from os import environ + +from flask import Flask, render_template, request, json from google.oauth2 import service_account +from googleapiclient.discovery import build logging.basicConfig(filename='example.log', level=logging.DEBUG) @@ -34,8 +34,8 @@ application = Flask(__name__) logging.info(environ) scopes = ['https://www.googleapis.com/auth/chat.bot'] -credentials = service_account.Credentials.from_service_account_file('/home/benjamyntesting/chatbot/service-acct.json') -#credentials, project_id = google.auth.default() +credentials = service_account.Credentials.from_service_account_file('./config/service-acct.json') +# credentials, project_id = google.auth.default() credentials = credentials.with_scopes(scopes=scopes) chat = build('chat', 'v1', credentials=credentials) @@ -62,9 +62,10 @@ def home_post(): space_name = event_data['space']['name'] send_async_response(resp, space_name) - # Return empty jsom respomse simce message already sent via REST API + # Return empty jsom response since message already sent via REST API return json.jsonify({}) + # [START async-response] def send_async_response(response, space_name): @@ -79,6 +80,7 @@ def send_async_response(response, space_name): parent=space_name, body=response).execute() + # [END async-response] def format_response(event): @@ -115,6 +117,7 @@ def format_response(event): return response + # [END async-bot] @application.route('/', methods=['GET']) @@ -130,5 +133,5 @@ def home_get(): if __name__ == '__main__': # This is used when running locally. Gunicorn is used to run the - # applicationlication on Google application Engine. See entrypoint in application.yaml. + # application on Google application Engine. See entrypoint in application.yaml. application.run(host='127.0.0.1', port=8080, debug=True) diff --git a/requirements.txt b/requirements.txt index ec5cc4a..ed472ea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -Flask +Flask~=2.2.3 google-api-python-client google-auth +google \ No newline at end of file