Google Chat Apps Script机器人已连接但无法接收事件求助
Google Chat Apps Script机器人无响应问题排查
已完成的配置步骤
- 创建包含
onMessage、onAddToSpace、onRemoveFromSpace处理器的Apps Script项目 - 将项目部署为Google Chat应用并复制Deployment ID
- 在Google Cloud Console的Google Chat API配置页面,设置连接类型为Apps Script,关联正确的Deployment ID,并将应用状态设为Live
问题现象
- 添加机器人或在空间中提及它时无任何响应:Chat中无回复(甚至没有默认的“Thanks for adding me”提示)
- Apps Script的Executions标签页无新运行记录
- 手动运行
onMessage时因event对象未定义失败(此为正常情况)
已确认信息
- Deployment ID、Chat API配置、项目编号均匹配,但Google Chat从未调用脚本
- HTTP连接方式可正常工作,但需使用Apps Script实现更多功能
已尝试的排查操作
- 创建新部署并重新关联到Chat API配置
- 将机器人添加到全新空间以触发
onAddToSpace - 确认使用的是Workspace账户而非个人Gmail
使用的代码与配置文件
第一个appsscript.json
{ "timeZone": "Asia/Karachi", "exceptionLogging": "STACKDRIVER", "runtimeVersion": "V8", "oauthScopes": [ "https://www.googleapis.com/auth/chat.bot" ], "chat": {} }
code.gs代码
// Learn more about Chat apps at https://developers.google.com/workspace/chat/overview /** * Responds to a MESSAGE event in Google Chat. * * @param {Object} event the event object from Google 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 Google Chat. * * @param {Object} event the event object from Google Chat */ function onAddToSpace(event) { var message = ""; if (event.space.singleUserBotDm) { message = "Thank you for adding me to a DM, " + event.user.displayName + "!"; } else { message = "Thank you for adding me to " + (event.space.displayName ? event.space.displayName : "this chat"); } 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 Google Chat. * * @param {Object} event the event object from Google Chat */ function onRemoveFromSpace(event) { console.info("Bot removed from ", (event.space.name ? event.space.name : "this chat")); } // Used the given google code.gs file with out any changes
第二个appsscript.json
{ "timeZone": "Asia/Karachi", "dependencies": {}, "exceptionLogging": "STACKDRIVER", "runtimeVersion": "V8", "chat": {} }
内容的提问来源于stack exchange,提问作者Ahamd YAR
相关产品推荐
相关产品推荐

