Skip to content

Commit

Permalink
fix: Webhook urls (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay-google authored Nov 8, 2023
1 parent d25c3eb commit 107ae3e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apps-script/webhook/thread-reply.gs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

// [START google_chat_webhook]
function webhook() {
const url = "https://chat.googleapis.com/v1/spaces/{{'<var>SPACE_ID</var>'}}/messages?key={{'<var>KEY</var>'}}&token={{'<var>TOKEN</var>'}}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD";
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"
const options = {
"method": "post",
"headers": {"Content-Type": "application/json; charset=UTF-8"},
"payload": JSON.stringify({
"text": "Hello from Apps Script!",
"thread": {"threadKey": "{{'<var>THREAD_KEY_VALUE</var>'}}"}
"thread": {"threadKey": "THREAD_KEY_VALUE"}
})
};
const response = UrlFetchApp.fetch(url, options);
Expand Down
2 changes: 1 addition & 1 deletion apps-script/webhook/webhook.gs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// [START hangouts_chat_webhook]
function webhook() {
const url = "https://chat.googleapis.com/v1/spaces/{{'<var>SPACE_ID</var>'}}/messages?key={{'<var>KEY</var>'}}&token={{'<var>TOKEN</var>'}}";
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages"
const options = {
"method": "post",
"headers": {"Content-Type": "application/json; charset=UTF-8"},
Expand Down
2 changes: 1 addition & 1 deletion node/webhook/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @return {Object} response
*/
async function webhook() {
const url = "https://chat.googleapis.com/v1/spaces/{{'<var>SPACE_ID</var>'}}/messages?key={{'<var>KEY</var>'}}&token={{'<var>TOKEN</var>'}}";
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages"
const res = await fetch(url, {
method: "POST",
headers: {"Content-Type": "application/json; charset=UTF-8"},
Expand Down
4 changes: 2 additions & 2 deletions node/webhook/thread-reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
* @return {Object} response
*/
async function webhook() {
const url = "https://chat.googleapis.com/v1/spaces/{{'<var>SPACE_ID</var>'}}/messages?key={{'<var>KEY</var>'}}&token={{'<var>TOKEN</var>'}}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD";
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"
const res = await fetch(url, {
method: "POST",
headers: {"Content-Type": "application/json; charset=UTF-8"},
body: JSON.stringify({
text: "Hello from a Node script!",
thread: {threadKey: "{{'<var>THREAD_KEY_VALUE</var>'}}"}
thread: {threadKey: "THREAD_KEY_VALUE"}
})
});
return await res.json();
Expand Down
4 changes: 1 addition & 3 deletions python/webhook/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
from json import dumps
from httplib2 import Http

WEBHOOK_URL = "https://chat.googleapis.com/v1/spaces/{{'<var>SPACE_ID</var>'}}/messages?key={{'<var>KEY</var>'}}&token={{'<var>TOKEN</var>'}}"


def main():
"""Google Chat incoming webhook quickstart."""
url = WEBHOOK_URL
url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages"
app_message = {"text": "Hello from a Python script!"}
message_headers = {"Content-Type": "application/json; charset=UTF-8"}
http_obj = Http()
Expand Down
5 changes: 2 additions & 3 deletions python/webhook/thread-reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
#
# Then, append messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD to the
# webhook URL.
WEBHOOK_URL = "https://chat.googleapis.com/v1/spaces/{{'<var>SPACE_ID</var>'}}/messages?key={{'<var>KEY</var>'}}&token={{'<var>TOKEN</var>'}}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"


def main():
"""Google Chat incoming webhook that starts or replies to a message thread."""
url = WEBHOOK_URL
url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"
app_message = {
"text": "Hello from a Python script!",
# To start a thread, set threadKey to an arbitratry string.
# To reply to a thread, specify that thread's threadKey value.
"thread": {"threadKey": "{{'<var>THREAD_KEY_VALUE</var>'}}"},
"thread": {"threadKey": "THREAD_KEY_VALUE"},
}
message_headers = {"Content-Type": "application/json; charset=UTF-8"}
http_obj = Http()
Expand Down

0 comments on commit 107ae3e

Please sign in to comment.