Skip to content

Commit

Permalink
✨ NotifyText generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shion1305 committed Oct 12, 2024
1 parent ee315d8 commit 42728e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
lineWHandler := handler.NewLINEWebhookHandler(lineBotSvc, fs)
e.Any("/line/webhook", lineWHandler.Handle)

vonageWHService := handler.NewVonageWebhook(*lineBotSvc)
vonageWHService := handler.NewVonageWebhook(lineBotSvc, fs)
e.Any("/vonage/webhook", vonageWHService.Handle)
port := 8080
if config.Config.General.Port != "" {
Expand Down
40 changes: 36 additions & 4 deletions pkg/handler/vonage.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package handler

import (
"cloud.google.com/go/firestore"
"fmt"
"github.com/a-company/yoriai-backend/pkg/model"
"github.com/a-company/yoriai-backend/pkg/service/line"
"github.com/gin-gonic/gin"
"log/slog"
)

type VonageWebhookRequest struct {
Expand All @@ -17,11 +21,16 @@ type VonageWebhookRequest struct {

type VonageWebhook struct {
line *line.LINEBotService
fs *firestore.Client
}

func NewVonageWebhook(svc line.LINEBotService) *VonageWebhook {
func NewVonageWebhook(
svc *line.LINEBotService,
fs *firestore.Client,
) *VonageWebhook {
return &VonageWebhook{
line: &svc,
line: svc,
fs: fs,
}
}

Expand All @@ -31,9 +40,32 @@ func (v *VonageWebhook) Handle(c *gin.Context) {
c.JSON(400, gin.H{"error": err.Error()})
return
}
// TODO: forward the request to LINE
v.line.ReplyTextMessage(req.ConversationID, req.Message)

userdata := model.User{}
doc, err := v.fs.Collection("users").
Where("phone_number", "==", req.PhoneNumber).
Documents(c).Next()
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}
doc.DataTo(&userdata)

//気分: Feeling
//今日の通話のサマリー: TodayActivity
//伝言: Message

notifyText := "本日の通話が終了しました\n\n"
notifyText += fmt.Sprintf("気分: %s\n", req.Feeling)
notifyText += fmt.Sprintf("今日の通話のサマリー: %s\n", req.TodayActivity)
notifyText += fmt.Sprintf("伝言: %s\n", req.Message)

slog.Info("notifyText", slog.String("notifyText", notifyText))
if err := v.line.PushTextMessage(userdata.LINEID, notifyText); err != nil {
slog.Error("failed to push message", err)
c.JSON(500, gin.H{"error": err.Error()})
return
}
c.JSON(200, gin.H{
"message": "success",
})
Expand Down

0 comments on commit 42728e6

Please sign in to comment.