如何保存任何输入消息从用户发送到我的线聊天机器人与谷歌表和对话流



我想保存用户输入到我的在线聊天机器人的每条消息。我的聊天机器人的目的是接收有关covid - 19的信息,因为在我的国家,人们通常通过在线消息向其他人发送covid - 19信息。他们可以分享我的聊天机器人的信息,我会保存在谷歌表的信息,因为我想我的聊天机器人是易于使用。所以,我使用谷歌表作为数据库,我使用对话流。但是我不知道如何接收我之前说过的信息。

  1. 使用以下代码部署web应用
  2. 在LINE Developers/LINE Manager
  3. 中将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]);
}

最新更新