From 64dcfea1640c46680b2a12f528bf24c595c1fb51 Mon Sep 17 00:00:00 2001 From: Shion Ichikawa Date: Sat, 12 Oct 2024 05:52:09 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20add=20update=20in=20each=20s?= =?UTF-8?q?teps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/handler/line.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/handler/line.go b/pkg/handler/line.go index c3005e1..51e8248 100644 --- a/pkg/handler/line.go +++ b/pkg/handler/line.go @@ -63,6 +63,7 @@ func (l *LINEWebhookHandler) Handle(c *gin.Context) { // memberLeft: When a user leaves a group chat or multi-person chat that your LINE Official Account is a member of. case "message": // message: When a user sends a message. You can reply to this event. + l.HandleMessageEvent(event.(webhook.MessageEvent)) case "module": // module: When a user interacts with a module. You can reply to this event. case "postback": @@ -94,7 +95,7 @@ func (l *LINEWebhookHandler) HandleFollowEvent(event webhook.FollowEvent) { l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "Failed to add you as a friend. Please try again later.") return } - l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "Thank you for adding me as a friend!") + l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "友達登録ありがとうございます!\n\nまずは電話対象者のニックネームを入力してください") } func (l *LINEWebhookHandler) HandleUnfollowEvent(event webhook.UnfollowEvent) { @@ -126,6 +127,11 @@ func (l *LINEWebhookHandler) HandleMessageEvent(event webhook.MessageEvent) { if userdata.Target.Nickname == "" { event.Message.GetType() userdata.Target.Nickname = txtMsg.Text + _, err := ref.Set(ctx, userdata) + if err != nil { + slog.Error("failed to set user", err) + return + } l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "次に電話番号を入力してください (例: 09012345678)") return } @@ -137,6 +143,11 @@ func (l *LINEWebhookHandler) HandleMessageEvent(event webhook.MessageEvent) { l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "電話番号の形式が正しくありません。もう一度入力してください。(例: 09012345678)") return } + _, err := ref.Set(ctx, userdata) + if err != nil { + slog.Error("failed to set user", err) + return + } l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "次に希望の通話時間を入力してください") return } @@ -148,6 +159,11 @@ func (l *LINEWebhookHandler) HandleMessageEvent(event webhook.MessageEvent) { l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "通話時間の形式が正しくありません") return } + _, err := ref.Set(ctx, userdata) + if err != nil { + slog.Error("failed to set user", err) + return + } l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "登録が完了しました!") } } From ebda22327054993f848f3c92428eb2956267595d Mon Sep 17 00:00:00 2001 From: Shion Ichikawa Date: Sat, 12 Oct 2024 05:59:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20Confirm=20param=20in=20user.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/model/user.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/model/user.go b/pkg/model/user.go index c1eafc3..95a5dfc 100644 --- a/pkg/model/user.go +++ b/pkg/model/user.go @@ -3,15 +3,16 @@ package model import "time" type User struct { - LINEID string `json:"line_id"` - Target Target `json:"target"` - AddDate time.Time `json:"add_date"` + LINEID string `firestore:"line_id"` + Target Target `firestore:"target"` + AddDate time.Time `firestore:"add_date"` } type PhoneNumber string type Target struct { - Nickname string `json:"nickname"` - Phone PhoneNumber `json:"phone_number"` - CallTime string `json:"call_time"` // 12:00 + Nickname string `firestore:"nickname"` + Phone PhoneNumber `firestore:"phone_number"` + CallTime string `firestore:"call_time"` // 12:00 + Confirm bool `firestore:"confirm"` }