2020/06/21
VR勉強会 #3 / #study_in_vr
const token = PropertiesService.getScriptProperties()
.getProperty('SLACK_ACCESS_TOKEN');
const channel = PropertiesService.getScriptProperties()
.getProperty('SLACK_CHANNEL');
const json = JSON.parse(
e.postData.getDataAsString()
);
const event = json.event;
// 指定の顔文字リアクションでなければ無視
if (event.reaction !== 'lgtm') return;
Logger.log(event.reaction);
const slackParams = JSON.parse(
e.postData.getDataAsString()
).event;
const messageTs = slackParams.item.ts;
const messageTsDate = new Date(messageTs * 1000);
const baseUrl = 'https://slack.com/api/conversations.history';
const baseParams = [
'token=' + token,
'channel=' + channel,
'oldest=' + messageTs,
'latest=' + messageTs,
'inclusive=' + true
];
const latestMessage = '';
const params = baseParams.concat([latestMessage]).join('&');
const encodeType = 'application/x-www-form-urlencoded';
const res = postMessageToSlack(baseUrl + '?' + params, encodeType);
function postMessageToSlack(url, encodeType) {
const res = UrlFetchApp.fetch(url, {
method: 'GET',
headers: {
'Content-Type': encodeType
}
});
return JSON.parse(res);
}
const today = new Date();
const sheetName = Utilities.formatDate(
today,
'Asia/Tokyo',
'yyyyMM'
);
const sheet = SpreadsheetApp
.getActive()
.getSheetByName(sheetName);
// 存在していない場合新たに作る
if(!sheet) SpreadsheetApp.create(sheetName);
export interface TipForm {
title: string
url: string
description: string
tags: number[]
event: number
time: Date
}
https://github.com/grahamearley/FirestoreGoogleAppsScript
addDataToFirestore({
time: messageTsDate,
title: messageText,
url: matches[0]
});
function addDataToFirestore({ time, title, url }) {
const certification = initFirestore();
const firestore = FirestoreApp.getFirestore(
certification.email,
certification.key,
certification.projectId
);
try {
firestore.updateDocument('tips/' + getUuid(), {
time: time,
title: title,
url: url,
description: '',
event: 0,
tags: []
});
} catch (e) {
Logger.log(e);
}
}