Skip to content

Commit 906a6b3

Browse files
committed
Address latest comments
1 parent fe0b2c5 commit 906a6b3

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

apps-script/incident-response/ChatApi.gs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
* @return {string} The resource name of the new space.
2626
*/
2727
function handleIncident(formData) {
28-
console.log(formData)
2928
const isAppCredentials = formData.isAppCredentials; // Get the isAppCredentials element
3029
if(isAppCredentials){
3130
return handleIncidentWithAppCredentials(formData)

apps-script/incident-response/ChatApiAppCredentials.gs

+12-18
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,29 @@
2727
*/
2828
function handleIncidentWithAppCredentials(formData) {
2929
const users = formData.users.trim().length > 0 ? formData.users.split(',') : [];
30-
const service = _getService();
30+
const service = getService_();
3131
if (!service.hasAccess()) {
3232
console.error(service.getLastError());
3333
return;
3434
}
35-
const spaceName = _createChatSpaceWithAppCredentials(formData.title, service);
36-
_createHumanMembershipWithAppCredentials(spaceName, getUserEmail(),service);
35+
const spaceName = createChatSpaceWithAppCredentials_(formData.title, service);
36+
createHumanMembershipWithAppCredentials_(spaceName, getUserEmail(),service);
3737
for (const user of users ){
38-
_createHumanMembershipWithAppCredentials(spaceName, user, service);
38+
createHumanMembershipWithAppCredentials_(spaceName, user, service);
3939
}
40-
_createMessageWithAppCredentials(spaceName, formData.description, service);
40+
createMessageWithAppCredentials_(spaceName, formData.description, service);
4141
return spaceName;
4242
}
43-
4443
/**
4544
* Creates a chat space with application credentials.
4645
*
4746
* @param {string} displayName - The name of the chat space.
4847
* @param {object} service - The credentials of the service account.
4948
* @returns {string} The resource name of the new space.
50-
*/
51-
function _createChatSpaceWithAppCredentials(displayName, service) {
49+
*/
50+
function createChatSpaceWithAppCredentials_(displayName, service) {
5251
try {
53-
// for private apps, the alias can be used
52+
// For private apps, the alias can be used
5453
const my_customer_alias = "customers/my_customer"
5554
// Specify the space to create.
5655
const space = {
@@ -64,23 +63,21 @@ function _createChatSpaceWithAppCredentials(displayName, service) {
6463
{},
6564
// Authenticate with the service account token.
6665
{'Authorization': 'Bearer ' + service.getAccessToken()});
67-
// Log details about the created message.
68-
console.log(createdSpace);
6966
return createdSpace.name;
7067
} catch (err) {
7168
// TODO (developer) - Handle exception.
7269
console.log('Failed to create space with error %s', err.message);
7370
}
7471
}
75-
/*
72+
/*
7673
* Creates a chat message with application credentials.
7774
*
7875
* @param {string} spaceName - The resource name of the space.
7976
* @param {string} message - The text to be posted.
8077
* @param {object} service - The credentials of the service account.
8178
* @return {string} the resource name of the new space.
8279
*/
83-
function _createMessageWithAppCredentials(spaceName, message, service) {
80+
function createMessageWithAppCredentials_(spaceName, message, service) {
8481
try {
8582
const service = getService_();
8683
if (!service.hasAccess()) {
@@ -96,8 +93,6 @@ function _createMessageWithAppCredentials(spaceName, message, service) {
9693
// Authenticate with the service account token.
9794
{'Authorization': 'Bearer ' + service.getAccessToken()});
9895

99-
// Log details about the created message.
100-
console.log(result);
10196
} catch (err) {
10297
// TODO (developer) - Handle exception.
10398
console.log('Failed to create message with error %s', err.message);
@@ -110,7 +105,7 @@ function _createMessageWithAppCredentials(spaceName, message, service) {
110105
* @param {string} email - The email of the user to be added.
111106
* @param {object} service - The credentials of the service account.
112107
*/
113-
function _createHumanMembershipWithAppCredentials(spaceName, email, service){
108+
function createHumanMembershipWithAppCredentials_(spaceName, email, service){
114109
try{
115110
const service = getService_();
116111
if (!service.hasAccess()) {
@@ -130,7 +125,6 @@ function _createHumanMembershipWithAppCredentials(spaceName, email, service){
130125
{},
131126
{'Authorization': 'Bearer ' + service.getAccessToken()}
132127
);
133-
console.log(result)
134128
} catch (err){
135129
console.log('Failed to create membership with error %s', err.message)
136130
}
@@ -141,7 +135,7 @@ function _createHumanMembershipWithAppCredentials(spaceName, email, service){
141135
* Creates a service for the service account.
142136
* @return {object} - The credentials of the service account.
143137
*/
144-
function _getService() {
138+
function getService_() {
145139
return OAuth2.createService(APP_CREDENTIALS.client_email)
146140
.setTokenUrl('https://oauth2.googleapis.com/token')
147141
.setPrivateKey(APP_CREDENTIALS.private_key)

apps-script/incident-response/ChatApiHumanCredentials.gs

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
*/
2828
function handleIncidentWithHumanCredentials(formData) {
2929
const users = formData.users.trim().length > 0 ? formData.users.split(',') : [];
30-
const spaceName = _setUpSpaceWithHumanCredentials(formData.title, users);
31-
_addAppToSpaceWithHumanCredentials(spaceName);
32-
_createMessageWithHumanCredentials(spaceName, formData.description);
30+
const spaceName = setUpSpaceWithHumanCredentials_(formData.title, users);
31+
addAppToSpaceWithHumanCredentials_(spaceName);
32+
createMessageWithHumanCredentials_(spaceName, formData.description);
3333
return spaceName;
3434
}
3535

@@ -38,7 +38,7 @@ function handleIncidentWithHumanCredentials(formData) {
3838
*
3939
* @return {string} the resource name of the new space.
4040
*/
41-
function _setUpSpaceWithHumanCredentials(displayName, users) {
41+
function setUpSpaceWithHumanCredentials_(displayName, users) {
4242
const memberships = users.map(email => ({
4343
member: {
4444
name: `users/${email}`,
@@ -63,7 +63,7 @@ function _setUpSpaceWithHumanCredentials(displayName, users) {
6363
*
6464
* @return {string} the resource name of the new membership.
6565
*/
66-
function _addAppToSpaceWithHumanCredentials(spaceName) {
66+
function addAppToSpaceWithHumanCredentials_(spaceName) {
6767
const request = {
6868
member: {
6969
name: "users/app",
@@ -80,7 +80,7 @@ function _addAppToSpaceWithHumanCredentials(spaceName) {
8080
*
8181
* @return {string} the resource name of the new message.
8282
*/
83-
function _createMessageWithHumanCredentials(spaceName, text) {
83+
function createMessageWithHumanCredentials_(spaceName, text) {
8484
const request = {
8585
text: text
8686
};

apps-script/incident-response/GeminiApi.gs

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function summarizeChatHistory_(chatHistory) {
4949

5050
if (responseCode === 200) {
5151
var json = JSON.parse(responseBody);
52-
if (json.candidates && json.candidates.length > 0 && json.candidates[0].content && json.candidates[0].content.parts && json.candidates[0].content.parts.length > 0) {
52+
if (json.candidates && json.candidates.length > 0 &&
53+
json.candidates[0].content && json.candidates[0].content.parts &&
54+
json.candidates[0].content.parts.length > 0) {
5355
return json.candidates[0].content.parts[0].text;
5456
} else {
5557
return "Gemini API: Unexpected response structure.";

0 commit comments

Comments
 (0)