Compare commits
No commits in common. "bc0f4b6b3717cd084df9f93f919efed92b48c21c" and "5e8ff48d34e25c870ed26469c12712fc21c2ded1" have entirely different histories.
bc0f4b6b37
...
5e8ff48d34
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,8 +0,0 @@
|
|||||||
# Configs
|
|
||||||
config/service-acct.json
|
|
||||||
|
|
||||||
# Logs
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# JetBrains stuff
|
|
||||||
.idea/
|
|
||||||
@ -1 +0,0 @@
|
|||||||
https://cloud.google.com/iam/docs/keys-create-delete
|
|
||||||
19
main.py
19
main.py
@ -21,11 +21,11 @@ Hangouts Chat bot that responds to events and messages from a room asynchronousl
|
|||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from os import environ
|
|
||||||
|
|
||||||
from flask import Flask, render_template, request, json
|
|
||||||
from google.oauth2 import service_account
|
|
||||||
from googleapiclient.discovery import build
|
from googleapiclient.discovery import build
|
||||||
|
from flask import Flask, render_template, request, json
|
||||||
|
import google.auth
|
||||||
|
from os import environ
|
||||||
|
from google.oauth2 import service_account
|
||||||
|
|
||||||
logging.basicConfig(filename='example.log', level=logging.DEBUG)
|
logging.basicConfig(filename='example.log', level=logging.DEBUG)
|
||||||
|
|
||||||
@ -34,8 +34,8 @@ application = Flask(__name__)
|
|||||||
logging.info(environ)
|
logging.info(environ)
|
||||||
|
|
||||||
scopes = ['https://www.googleapis.com/auth/chat.bot']
|
scopes = ['https://www.googleapis.com/auth/chat.bot']
|
||||||
credentials = service_account.Credentials.from_service_account_file('./config/service-acct.json')
|
credentials = service_account.Credentials.from_service_account_file('/home/benjamyntesting/chatbot/service-acct.json')
|
||||||
# credentials, project_id = google.auth.default()
|
#credentials, project_id = google.auth.default()
|
||||||
credentials = credentials.with_scopes(scopes=scopes)
|
credentials = credentials.with_scopes(scopes=scopes)
|
||||||
chat = build('chat', 'v1', credentials=credentials)
|
chat = build('chat', 'v1', credentials=credentials)
|
||||||
|
|
||||||
@ -62,10 +62,9 @@ def home_post():
|
|||||||
space_name = event_data['space']['name']
|
space_name = event_data['space']['name']
|
||||||
send_async_response(resp, space_name)
|
send_async_response(resp, space_name)
|
||||||
|
|
||||||
# Return empty jsom response since message already sent via REST API
|
# Return empty jsom respomse simce message already sent via REST API
|
||||||
return json.jsonify({})
|
return json.jsonify({})
|
||||||
|
|
||||||
|
|
||||||
# [START async-response]
|
# [START async-response]
|
||||||
|
|
||||||
def send_async_response(response, space_name):
|
def send_async_response(response, space_name):
|
||||||
@ -80,7 +79,6 @@ def send_async_response(response, space_name):
|
|||||||
parent=space_name,
|
parent=space_name,
|
||||||
body=response).execute()
|
body=response).execute()
|
||||||
|
|
||||||
|
|
||||||
# [END async-response]
|
# [END async-response]
|
||||||
|
|
||||||
def format_response(event):
|
def format_response(event):
|
||||||
@ -117,7 +115,6 @@ def format_response(event):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
# [END async-bot]
|
# [END async-bot]
|
||||||
|
|
||||||
@application.route('/', methods=['GET'])
|
@application.route('/', methods=['GET'])
|
||||||
@ -133,5 +130,5 @@ def home_get():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# This is used when running locally. Gunicorn is used to run the
|
# This is used when running locally. Gunicorn is used to run the
|
||||||
# application on Google application Engine. See entrypoint in application.yaml.
|
# applicationlication on Google application Engine. See entrypoint in application.yaml.
|
||||||
application.run(host='127.0.0.1', port=8080, debug=True)
|
application.run(host='127.0.0.1', port=8080, debug=True)
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
Flask~=2.2.3
|
Flask
|
||||||
google-api-python-client
|
google-api-python-client
|
||||||
google-auth
|
google-auth
|
||||||
google
|
|
||||||
Reference in New Issue
Block a user