Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions functions/src/linebot/handler/handleMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MessageEvent } from '@line/bot-sdk';
import { lineToken } from '../config';
import { usersRef } from '../../firestore';

// TODO: とりあえずこのメソッドに全部書いて、あとでファイル分割しましょう
export const handleMessage = async (
client: line.Client,
profile: line.Profile,
Expand All @@ -15,6 +16,28 @@ export const handleMessage = async (

let text = '';

// 従来の文法(例↓)
// トレキャン1
// オリエン10
if (event.message.text.includes('トレキャン')) {
// 文字列解析

// こんなデータを作る
// const postData = {
// uid: 1,
// date: Date.now(), // 書式決めちゃおう(timestamp or string ...)
// type: 1,
// value: 10
// }

// APIエンドポイントにリクエストを投げる
// こんな感じ(曖昧だから調べて><)
// uri: http://localhost:5000/trecamp-server/us-central1/api/trainings
// json: postData
// request.post(...)
return;
}

if (event.message.text === '連携') {
const snapshot = await usersRef.where('lineId', '==', event.source.userId).get();
const user = snapshot.docs.map(doc => doc.data())[0];
Expand Down
6 changes: 6 additions & 0 deletions functions/src/routes/trainings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ router.get('/', async (req, res, next) => {
res.json(trainings);
});

// params(req.bodyの内容)
// uid: トレキャンID(今の所LINE IDではない(要検討))
// date:
// type: typeを表すnumber(ex: runnning -> 1)
// value: 距離などのnumber
// comment
router.post('/', async (req, res, next) => {
const typeIndex = req.body.type;
const snapshot = await typesRef.doc(`${typeIndex}`).get();
Expand Down