Skip to content

Commit e6a75f3

Browse files
author
pierrick
committed
feat: add chat webhook app
1 parent 748a7fb commit e6a75f3

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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": {"threadKey": "THREAD_KEY_VALUE"}
27+
})
28+
};
29+
const response = UrlFetchApp.fetch(url, options);
30+
console.log(response);
31+
}
32+
// [END chat_webhook_thread]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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"
21+
const options = {
22+
"method": "post",
23+
"headers": {"Content-Type": "application/json; charset=UTF-8"},
24+
"payload": JSON.stringify({"text": "Hello from Apps Script!"})
25+
};
26+
const response = UrlFetchApp.fetch(url, options);
27+
console.log(response);
28+
}
29+
// [END chat_webhook]

0 commit comments

Comments
 (0)