Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

トレーニング投稿エンドポイント作成の例 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -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];
6 changes: 6 additions & 0 deletions functions/src/routes/trainings.ts
Original file line number Diff line number Diff line change
@@ -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();