Skip to content

Commit

Permalink
Create getThreadID.gs
Browse files Browse the repository at this point in the history
  • Loading branch information
choraria committed Jul 11, 2019
1 parent 2edf668 commit 099c556
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Hangouts Chat/Bot/getThreadID.gs
@@ -0,0 +1,31 @@
/**
* Responds to a MESSAGE event in Hangouts Chat.
*
* @param {Object} event the event object from Hangouts Chat
*/
function onMessage(event) {
var thread = event.message.thread.name;
var threadRegex = /(spaces\/)(.*)(\/threads\/)(.*)/;
var spaceID = threadRegex.exec(thread)[2]
var threadID = threadRegex.exec(thread)[4]
var message = "Thread ID: " + threadID + "\nThread URL: https://chat.google.com/room/" + spaceID + "/" + threadID;
return { "text": message };
}

/**
* Responds to an ADDED_TO_SPACE event in Hangouts Chat.
*
* @param {Object} event the event object from Hangouts Chat
*/
function onAddToSpace(event) {
var message = "";
message = "Thank you for adding me to *" + event.space.displayName + "*. \nYou can now use `@getThreadID` command to get the URL of a specific conversation.";
if (event.message) {
var thread = event.message.thread.name;
var threadRegex = /(spaces\/)(.*)(\/threads\/)(.*)/;
var spaceID = threadRegex.exec(thread)[2]
var threadID = threadRegex.exec(thread)[4]
message = "Thank you for adding me to " + event.space.displayName + "\n" + "Thread ID: " + threadID + "\nThread URL: https://chat.google.com/room/" + spaceID + "/" + threadID;
}
return { "text": message };
}

0 comments on commit 099c556

Please sign in to comment.