1- /*
2- * Copyright (C) 2017/2025 SNCF Connect & Tech
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
161package ai.tock.bot.connector.googlechat
172
18- import ai.tock.bot.connector.Connector
19- import ai.tock.bot.connector.ConnectorConfiguration
20- import ai.tock.bot.connector.ConnectorMessage
21- import ai.tock.bot.connector.ConnectorProvider
22- import ai.tock.bot.connector.ConnectorType
23- import ai.tock.bot.connector.ConnectorTypeConfiguration
24- import ai.tock.bot.connector.ConnectorTypeConfigurationField
3+ import ai.tock.bot.connector.*
254import ai.tock.bot.connector.googlechat.builder.googleChatConnectorType
265import ai.tock.shared.resourceAsStream
276import ai.tock.shared.resourceAsString
@@ -44,6 +23,7 @@ private const val SERVICE_CREDENTIAL_CONTENT_PARAMETER = "serviceCredentialConte
4423private const val BOT_PROJECT_NUMBER_PARAMETER = " botProjectNumber"
4524private const val CONDENSED_FOOTNOTES_PARAMETER = " useCondensedFootnotes"
4625private const val GSA_TO_IMPERSONATE_PARAMETER = " gsaToImpersonate"
26+ private const val INTRO_MESSAGE_PARAMETER = " introMessage"
4727
4828internal object GoogleChatConnectorProvider : ConnectorProvider {
4929
@@ -90,12 +70,16 @@ internal object GoogleChatConnectorProvider : ConnectorProvider {
9070 ? : error(" Parameter Bot project number not present" )
9171 )
9272
73+ val introMessage =
74+ connectorConfiguration.parameters[INTRO_MESSAGE_PARAMETER ]?.takeIf { it.isNotBlank() }
75+
9376 return GoogleChatConnector (
9477 connectorId,
9578 path,
9679 chatService,
9780 authorisationHandler,
98- useCondensedFootnotes
81+ useCondensedFootnotes,
82+ introMessage
9983 )
10084 }
10185 }
@@ -104,12 +88,7 @@ internal object GoogleChatConnectorProvider : ConnectorProvider {
10488 connectorConfiguration : ConnectorConfiguration ,
10589 targetServiceAccount : String
10690 ): GoogleCredentials {
107-
10891 val sourceCredentials = getSourceCredentials(connectorConfiguration)
109-
110- logger.info { " Source credentials: ${(sourceCredentials as ? ServiceAccountCredentials )?.clientEmail} " }
111- logger.info { " Impersonating target GSA = $targetServiceAccount with scopes = $CHAT_SCOPE " }
112-
11392 return ImpersonatedCredentials .create(
11493 sourceCredentials,
11594 targetServiceAccount,
@@ -123,14 +102,9 @@ internal object GoogleChatConnectorProvider : ConnectorProvider {
123102 private fun getSourceCredentials (connectorConfiguration : ConnectorConfiguration ): GoogleCredentials {
124103 return try {
125104 val credentialInputStream = getCredentialInputStream(connectorConfiguration)
126- val creds = ServiceAccountCredentials .fromStream(credentialInputStream)
105+ ServiceAccountCredentials .fromStream(credentialInputStream)
127106 .createScoped(" https://www.googleapis.com/auth/cloud-platform" )
128-
129- logger.info { " Loaded explicit service account: ${(creds as ServiceAccountCredentials ).clientEmail} " }
130-
131- creds
132107 } catch (e: Exception ) {
133- logger.info { " No explicit credentials found, using Application Default Credentials" }
134108 GoogleCredentials .getApplicationDefault()
135109 .createScoped(" https://www.googleapis.com/auth/cloud-platform" )
136110 }
@@ -181,6 +155,11 @@ internal object GoogleChatConnectorProvider : ConnectorProvider {
181155 " Use condensed footnotes (true = 1, false = 0)" ,
182156 CONDENSED_FOOTNOTES_PARAMETER ,
183157 false
158+ ),
159+ ConnectorTypeConfigurationField (
160+ " Introductory message (sent only once per new session)" ,
161+ INTRO_MESSAGE_PARAMETER ,
162+ false
184163 )
185164 ),
186165 svgIcon = resourceAsString(" /google_chat.svg" )
0 commit comments