From f3b58389dfc44d84ab3f23fc2f14f09b7fec6d97 Mon Sep 17 00:00:00 2001 From: kouhei ueno Date: Thu, 18 Jul 2019 23:34:10 +0900 Subject: [PATCH] explanation --- .../src/linebot/handler/handleMessage.ts | 23 +++++++++++++++++++ functions/src/routes/trainings.ts | 6 +++++ 2 files changed, 29 insertions(+) diff --git a/functions/src/linebot/handler/handleMessage.ts b/functions/src/linebot/handler/handleMessage.ts index c5d5df1..29f681c 100644 --- a/functions/src/linebot/handler/handleMessage.ts +++ b/functions/src/linebot/handler/handleMessage.ts @@ -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, @@ -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]; diff --git a/functions/src/routes/trainings.ts b/functions/src/routes/trainings.ts index 5f7090c..ec2ed74 100644 --- a/functions/src/routes/trainings.ts +++ b/functions/src/routes/trainings.ts @@ -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();