I think the steps are as follows:
- Create a service account in order to use the
https://www.googleapis.com/auth/chat.bot
scope.
Only supports service accounts. You can't authenticate user credentials using this scope.
- Use the Service Account Auth Flow within
googleauth
.
scope = 'https://www.googleapis.com/auth/androidpublisher'
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('/path/to/service_account_json_key.json'),
scope: scope)
authorizer.fetch_access_token!
3- Use the google-apis-chat_v1
for performing the request.
In any case, I strongly review the documentation for Google Chats API, for a full understanding on how the authorization flow works.
Updated
Sample ruby client send message
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'google/apis/chat_v1'
scope = 'https://www.googleapis.com/auth/chat.bot'
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('./credentials.json'),
scope: scope)
chat = Google::Apis::ChatV1::HangoutsChatService.new
msg = Google::Apis::ChatV1::Message.new(text: 'test')
chat.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('./credentials.json'),
scope: scope)
chat.create_space_message('spaces/XXXXXXXX', msg)