Skip to content

Commit

Permalink
Merge pull request #12 from a-company-jp/initial-logic-fixes
Browse files Browse the repository at this point in the history
initial logic fixes
  • Loading branch information
Shion1305 authored Oct 11, 2024
2 parents bb2522f + ebda223 commit 276ca9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
18 changes: 17 additions & 1 deletion pkg/handler/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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, "登録が完了しました!")
}
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 276ca9c

Please sign in to comment.