Skip to content

Commit

Permalink
✨ trigger phone call
Browse files Browse the repository at this point in the history
  • Loading branch information
Shion1305 committed Oct 11, 2024
1 parent d076482 commit 6e0b4cf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/handler/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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/vonage"
"github.com/gin-gonic/gin"
"log/slog"
"time"
Expand All @@ -22,21 +24,32 @@ func NewInvokeHandler(

func (h *CallInvoke) Handle(c *gin.Context) {
// get time
timeVal := fmt.Sprintf("%2d:%2d", time.Now().Hour(), 0)
timeVal := fmt.Sprintf("%02d:%02d", time.Now().Hour(), 0)
slog.Info("invoke call", slog.String("time", timeVal))
res := h.fs.Collection("users").Where("call_time", "==", timeVal).Documents(c)
if res == nil {
c.JSON(400, gin.H{"error": "no data"})
return
}

v := vonage.NewVonage()
for {
doc, err := res.Next()
if err != nil {
break
}
userdata := doc.Data()
userdata := model.User{}
doc.DataTo(&userdata)
slog.Info("invoke call on user", slog.Any("data", userdata))

// vonage callを発火
v.CallPhoneAPI(
vonage.PhoneAPIInput{
PhoneNumber: string(userdata.Phone),
ReceiverName: userdata.Nickname,
CallerName: "Yoriai",
RemindMessage: "今日の通話の時間です",
})
}
c.JSON(200, gin.H{
"message": "success",
Expand Down

0 comments on commit 6e0b4cf

Please sign in to comment.