27
27
*/
28
28
function handleIncidentWithAppCredentials ( formData ) {
29
29
const users = formData . users . trim ( ) . length > 0 ? formData . users . split ( ',' ) : [ ] ;
30
- const service = _getService ( ) ;
30
+ const service = getService_ ( ) ;
31
31
if ( ! service . hasAccess ( ) ) {
32
32
console . error ( service . getLastError ( ) ) ;
33
33
return ;
34
34
}
35
- const spaceName = _createChatSpaceWithAppCredentials ( formData . title , service ) ;
36
- _createHumanMembershipWithAppCredentials ( spaceName , getUserEmail ( ) , service ) ;
35
+ const spaceName = createChatSpaceWithAppCredentials_ ( formData . title , service ) ;
36
+ createHumanMembershipWithAppCredentials_ ( spaceName , getUserEmail ( ) , service ) ;
37
37
for ( const user of users ) {
38
- _createHumanMembershipWithAppCredentials ( spaceName , user , service ) ;
38
+ createHumanMembershipWithAppCredentials_ ( spaceName , user , service ) ;
39
39
}
40
- _createMessageWithAppCredentials ( spaceName , formData . description , service ) ;
40
+ createMessageWithAppCredentials_ ( spaceName , formData . description , service ) ;
41
41
return spaceName ;
42
42
}
43
-
44
43
/**
45
44
* Creates a chat space with application credentials.
46
45
*
47
46
* @param {string } displayName - The name of the chat space.
48
47
* @param {object } service - The credentials of the service account.
49
48
* @returns {string } The resource name of the new space.
50
- */
51
- function _createChatSpaceWithAppCredentials ( displayName , service ) {
49
+ */
50
+ function createChatSpaceWithAppCredentials_ ( displayName , service ) {
52
51
try {
53
- // for private apps, the alias can be used
52
+ // For private apps, the alias can be used
54
53
const my_customer_alias = "customers/my_customer"
55
54
// Specify the space to create.
56
55
const space = {
@@ -64,23 +63,21 @@ function _createChatSpaceWithAppCredentials(displayName, service) {
64
63
{ } ,
65
64
// Authenticate with the service account token.
66
65
{ 'Authorization' : 'Bearer ' + service . getAccessToken ( ) } ) ;
67
- // Log details about the created message.
68
- console . log ( createdSpace ) ;
69
66
return createdSpace . name ;
70
67
} catch ( err ) {
71
68
// TODO (developer) - Handle exception.
72
69
console . log ( 'Failed to create space with error %s' , err . message ) ;
73
70
}
74
71
}
75
- /*
72
+ /*
76
73
* Creates a chat message with application credentials.
77
74
*
78
75
* @param {string } spaceName - The resource name of the space.
79
76
* @param {string } message - The text to be posted.
80
77
* @param {object } service - The credentials of the service account.
81
78
* @return {string } the resource name of the new space.
82
79
*/
83
- function _createMessageWithAppCredentials ( spaceName , message , service ) {
80
+ function createMessageWithAppCredentials_ ( spaceName , message , service ) {
84
81
try {
85
82
const service = getService_ ( ) ;
86
83
if ( ! service . hasAccess ( ) ) {
@@ -96,8 +93,6 @@ function _createMessageWithAppCredentials(spaceName, message, service) {
96
93
// Authenticate with the service account token.
97
94
{ 'Authorization' : 'Bearer ' + service . getAccessToken ( ) } ) ;
98
95
99
- // Log details about the created message.
100
- console . log ( result ) ;
101
96
} catch ( err ) {
102
97
// TODO (developer) - Handle exception.
103
98
console . log ( 'Failed to create message with error %s' , err . message ) ;
@@ -110,7 +105,7 @@ function _createMessageWithAppCredentials(spaceName, message, service) {
110
105
* @param {string } email - The email of the user to be added.
111
106
* @param {object } service - The credentials of the service account.
112
107
*/
113
- function _createHumanMembershipWithAppCredentials ( spaceName , email , service ) {
108
+ function createHumanMembershipWithAppCredentials_ ( spaceName , email , service ) {
114
109
try {
115
110
const service = getService_ ( ) ;
116
111
if ( ! service . hasAccess ( ) ) {
@@ -130,7 +125,6 @@ function _createHumanMembershipWithAppCredentials(spaceName, email, service){
130
125
{ } ,
131
126
{ 'Authorization' : 'Bearer ' + service . getAccessToken ( ) }
132
127
) ;
133
- console . log ( result )
134
128
} catch ( err ) {
135
129
console . log ( 'Failed to create membership with error %s' , err . message )
136
130
}
@@ -141,7 +135,7 @@ function _createHumanMembershipWithAppCredentials(spaceName, email, service){
141
135
* Creates a service for the service account.
142
136
* @return {object } - The credentials of the service account.
143
137
*/
144
- function _getService ( ) {
138
+ function getService_ ( ) {
145
139
return OAuth2 . createService ( APP_CREDENTIALS . client_email )
146
140
. setTokenUrl ( 'https://oauth2.googleapis.com/token' )
147
141
. setPrivateKey ( APP_CREDENTIALS . private_key )
0 commit comments