我们的组织在Google Hangouts聊天(新聊天室)上谈论它的“事件”,作为其中的一部分,我们要将对话记录到另一个系统中
现在,我要做的是搜索特定的关键字,然后通过搜索结果找到这些会话,然后单击“转到主题”以获取会话URL。
我使用的是在Hangouts Chat API的“指南”部分下找到的以下代码,但仍然无法提供对话的网址-
/**
* Responds to a MESSAGE event in Hangouts Chat.
*
* @param {Object} event the event object from Hangouts Chat
*/
function onMessage(event) {
var name = "";
if (event.space.type == "DM") {
name = "You";
} else {
name = event.user.displayName;
}
var message = name + " said \"" + event.message.text + "\"";
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 = "";
if (event.space.type == "DM") {
message = "Thank you for adding me to a DM, " + event.user.displayName + "!";
} else {
message = "Thank you for adding me to " + event.space.displayName;
}
if (event.message) {
// Bot added through @mention.
message = message + " and you said: \"" + event.message.text + "\"";
}
return { "text": message };
}
/**
* Responds to a REMOVED_FROM_SPACE event in Hangouts Chat.
*
* @param {Object} event the event object from Hangouts Chat
*/
function onRemoveFromSpace(event) {
console.info("Bot removed from ", event.space.name);
}
我打算构建一个机器人,当调用该机器人时,它会直接吐出指向特定对话的链接。有人可以帮我获取对话的网址吗?
答案 0 :(得分:4)
因此,我也为此在webapps.stackexchange.com上发布了答案,这就是我所建立的-
/**
* 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 };
}
有关此问题的更详细信息,请参见here,但我假设您已经了解如何使用Apps Script托管和部署环聊聊天机器人。