google-apps-script - 如何保存来自用户的任何输入消息,这些消息通过谷歌表和对话流发送到我的在线聊天机器人
问题描述
我想将用户输入的每条消息保存到我的在线聊天机器人中。我的聊天机器人的目的是接收有关 covid19 的信息,因为我所在国家/地区的人们通常通过在线消息向其他人发送 covid 19 信息。他们可以将信息分享给我的聊天机器人,我会将信息保存在 google sheet 中,因为我希望我的聊天机器人易于使用。所以,我使用 google sheet 作为数据库并使用 dialog-flow 。但我不知道如何接收我之前所说的信息。
解决方案
- 使用以下代码部署 Web 应用
- 在 LINE Developers / LINE Manager 中设置
web app URL
为Webhook URL
function doPost(e) {
const contents = e.postData.contents;
const json = JSON.parse(contents);
// console.log(json);
const event = json["events"][0];
if (!event["message"]) { return; }
const userId = event.source.userId;
const message = event.message.text;
const id = 'Spreadsheet ID';
const name = 'Sheet Name';
const ss = SpreadsheetApp.openById(id);
const sheet = ss.getSheetByName(name);
sheet.appendRow([userId, message]);
}
推荐阅读
- mysql - 用于匹配字符串的 SQL 查询“where 子句”
- xml - 如何设置 XML 命名空间的嵌套使用
- java - 按对象的边界将集合排序成链
- php - 在 PHP 中生成大于 2,147,483,647 的整数
- oozie - Oozie 命令行过滤器
- kubernetes - 如何使用 kubernetes go 客户端管理现有的自定义对象?
- typescript - 从泛型类型获取函数返回类型
- lotusscript - Domino Designer 中的代码和注释模板:如何格式化模板变量?
- git - Git,恢复到早期提交
- rest - 如何从 DSpace rest api 获取所有社区