【发布时间】:2018-07-11 07:19:11
【问题描述】:
我们正在实施一个 Google 环聊聊天机器人,它将主动向域中的用户发送通知。为此,Google 聊天机器人 API 需要空间 ID 才能向用户发送主动通知。
参考文档:https://developers.google.com/hangouts/chat/reference/rest/v1/spaces/list
代码:
jwtClient.authorize(function (err) {
if (err) {
console.log(err);
return;
}
else {
chat.spaces.list({
auth: jwtClient
}, function (err, resp) {
if (err)
console.log(err);
else {
chat.spaces.list({
auth: jwtClient
}, function (err, resp) {
if (err)
console.log(err);
else {
var spaceList = resp.data.spaces;
spaceList.forEach(element => {
var spaceUrl = `https://chat.googleapis.com/v1/${element.name}/messages?key=${apiKey}`;
request({
url: spaceUrl,
method: "POST",
headers: {
'Content-Type': 'application/json'
},
json: customMessage
},
function (error, response, body) {
callback(error, body)
}
);
})
};
});
}
});
}
});
}
}
但是这个 API 只返回那些用户的空间列表,这些用户已经将机器人添加到他们的覆盖中。
他们是否有任何解决办法来获取/创建谷歌域中每个用户的空间?
【问题讨论】:
标签: google-api chatbot google-hangouts hangouts-api hangouts-chat