Skip to content

Commit 6cea3e6

Browse files
PierrickVouletpierrick
andauthored
feat: Chat webhook (#605)
* feat: add chat webhook app * improve indentation --------- Co-authored-by: pierrick <pierrick@google.com>
1 parent 748a7fb commit 6cea3e6

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Google Chat App Webhook
2+
3+
Please see related guide on how to
4+
[send messages to Google Chat with incoming webhooks](https://developers.google.com/workspace/chat/quickstart/webhooks).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2023 Google LLC
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+
*/
16+
17+
18+
// [START chat_webhook_thread]
19+
function webhook() {
20+
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"
21+
const options = {
22+
"method": "post",
23+
"headers": {"Content-Type": "application/json; charset=UTF-8"},
24+
"payload": JSON.stringify({
25+
"text": "Hello from Apps Script!",
26+
"thread": {
27+
"threadKey": "THREAD_KEY_VALUE"
28+
}
29+
})
30+
};
31+
const response = UrlFetchApp.fetch(url, options);
32+
console.log(response);
33+
}
34+
// [END chat_webhook_thread]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright 2022 Google LLC
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+
*/
16+
17+
18+
// [START chat_webhook]
19+
function webhook() {
20+
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN"
21+
const options = {
22+
"method": "post",
23+
"headers": {"Content-Type": "application/json; charset=UTF-8"},
24+
"payload": JSON.stringify({
25+
"text": "Hello from Apps Script!"
26+
})
27+
};
28+
const response = UrlFetchApp.fetch(url, options);
29+
console.log(response);
30+
}
31+
// [END chat_webhook]

0 commit comments

Comments
 (0)