Skip to content

Commit

Permalink
Merge pull request #18 from a-company-jp/new-flex-msg-time-picker
Browse files Browse the repository at this point in the history
FlexMessageによる時間の選択
  • Loading branch information
Shion1305 authored Oct 12, 2024
2 parents 766d9f0 + a709040 commit 63274d9
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 53 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ go 1.23.1

require (
cloud.google.com/go/firestore v1.17.0
github.com/PuerkitoBio/goquery v1.10.0
github.com/gin-gonic/gin v1.10.0
github.com/joho/godotenv v1.5.1
github.com/line/line-bot-sdk-go/v7 v7.21.0
github.com/line/line-bot-sdk-go/v8 v8.9.0
google.golang.org/api v0.200.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -19,7 +17,6 @@ require (
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
cloud.google.com/go/longrunning v0.6.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/bytedance/sonic v1.12.3 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
Expand Down
33 changes: 0 additions & 33 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ cloud.google.com/go/firestore v1.17.0/go.mod h1:69uPx1papBsY8ZETooc71fOhoKkD70Q1
cloud.google.com/go/longrunning v0.6.1 h1:lOLTFxYpr8hcRtcwWir5ITh1PAKUD/sG2lKrTSYjyMc=
cloud.google.com/go/longrunning v0.6.1/go.mod h1:nHISoOZpBcmlwbJmiVk5oDRz0qG/ZxPynEGs1iZ79s0=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PuerkitoBio/goquery v1.10.0 h1:6fiXdLuUvYs2OJSvNRqlNPoBm6YABE226xrbavY5Wv4=
github.com/PuerkitoBio/goquery v1.10.0/go.mod h1:TjZZl68Q3eGHNBA8CWaxAN7rOU1EbDz3CWuolcO5Yu4=
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU=
github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
Expand Down Expand Up @@ -102,8 +98,6 @@ github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZY
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/line/line-bot-sdk-go/v7 v7.21.0 h1:eeYMuAwaDV5DZNTRqDipNhzjT51HwEcM1PRPG+cqh4Y=
github.com/line/line-bot-sdk-go/v7 v7.21.0/go.mod h1:idpoxOZgtSd8JyhctMMpwg5LNgRAIL/QIxa5S0DXcMg=
github.com/line/line-bot-sdk-go/v8 v8.9.0 h1:YUoUAYAZGoOVhQ45F25mMEpdnv/BsdLhtO0GCMVpuWw=
github.com/line/line-bot-sdk-go/v8 v8.9.0/go.mod h1:9U4mY4kLAFSCSwPl1YxtqmG0Db19DnclpuYS5VOkOZY=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
Expand Down Expand Up @@ -132,7 +126,6 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 h1:r6I7RJCN86bpD/FQwedZ0vSixDpwuWREjW9oRMsmqDc=
Expand All @@ -151,26 +144,18 @@ golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -179,32 +164,18 @@ golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
Expand All @@ -214,10 +185,6 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.200.0 h1:0ytfNWn101is6e9VBoct2wrGDjOi5vn7jw5KtaQgDrU=
google.golang.org/api v0.200.0/go.mod h1:Tc5u9kcbjO7A8SwGlYj4IiVifJU01UqXtEgDMYmBmV8=
Expand Down
1 change: 1 addition & 0 deletions pkg/config/firestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package config

type Firestore struct {
ProjectID string `yaml:"project_id"`
DatabaseID string `yaml:"database_id"`
JsonCredentialFile string `yaml:"json_credential_file"`
}
1 change: 1 addition & 0 deletions pkg/config/setting.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ vonage:
agent_id:
firestore:
project_id: yorisoi
database_id:
json_credential_file:
48 changes: 33 additions & 15 deletions pkg/handler/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/a-company/yoriai-backend/pkg/model"
"github.com/a-company/yoriai-backend/pkg/service/line"
"github.com/gin-gonic/gin"
"github.com/line/line-bot-sdk-go/v8/linebot"
"github.com/line/line-bot-sdk-go/v8/linebot/webhook"
"log/slog"
"regexp"
Expand Down Expand Up @@ -68,6 +69,7 @@ func (l *LINEWebhookHandler) Handle(c *gin.Context) {
// module: When a user interacts with a module. You can reply to this event.
case "postback":
// postback: When a user triggers a postback action. You can reply to this event.
l.HandlePostbackEvent(event.(webhook.PostbackEvent))
case "things":
// things: When a user interacts with a LINE Things-compatible device. You can reply to this event.
case "unfollow":
Expand Down Expand Up @@ -159,23 +161,14 @@ func (l *LINEWebhookHandler) HandleMessageEvent(event webhook.MessageEvent) {
slog.Error("failed to set user", err)
return
}
l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "次に希望の通話時間を入力してください")
l.lineBotSvc.ReplyMessage(event.ReplyToken, []linebot.SendingMessage{line.CreateTimeSelectMessage()})
return
}
if userdata.Target.CallTime == "" {
userdata.Target.CallTime = txtMsg.Text
// 00:00形式
callTimeRgx := `^([01][0-9]|2[0-3]):00$`
if !regexp.MustCompile(callTimeRgx).MatchString(userdata.Target.CallTime) {
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, "最後にリマインドメッセージがある場合は入力してください。ない場合は「なし」と入力してください")
l.lineBotSvc.ReplyMessage(event.ReplyToken,
[]linebot.SendingMessage{
linebot.NewTextMessage("時間の指定方法が正しくありません。もう一度選択してください"),
line.CreateTimeSelectMessage()})
return
}
if userdata.Target.RemindMessage == "" && !userdata.Target.Confirm {
Expand All @@ -195,5 +188,30 @@ func (l *LINEWebhookHandler) HandleMessageEvent(event webhook.MessageEvent) {
l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "登録が完了しています!")
}

func (l *LINEWebhookHandler) HandleLeaveEvent(event webhook.UnfollowEvent) {
func (l *LINEWebhookHandler) HandlePostbackEvent(event webhook.PostbackEvent) {
userID := event.Source.(webhook.UserSource).UserId
ctx := context.Background()
userdata := model.User{}
ref := l.fs.Collection("users").Doc(userID)
doc, err := ref.Get(ctx)
if err != nil {
slog.Error("failed to get user", err)
return
}
if err := doc.DataTo(&userdata); err != nil {
slog.Error("failed to load user", err)
return
}
timeRgx := regexp.MustCompile(`call_time_picker_(\d{2}:00)`)
if userdata.Target.CallTime == "" && timeRgx.MatchString(event.Postback.Data) {
userdata.Target.CallTime = timeRgx.FindStringSubmatch(event.Postback.Data)[1]
_, err := ref.Set(ctx, userdata)
if err != nil {
slog.Error("failed to set user", err)
return
}
l.lineBotSvc.ReplyTextMessage(event.ReplyToken, "最後にリマインドメッセージがある場合は入力してください。ない場合は「なし」と入力してください")
return
}

}
76 changes: 75 additions & 1 deletion pkg/service/line/line_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package line
import (
"fmt"
"github.com/a-company/yoriai-backend/pkg/config"
"github.com/line/line-bot-sdk-go/v7/linebot"
"github.com/line/line-bot-sdk-go/v8/linebot"
"log/slog"
)

Expand All @@ -28,3 +28,77 @@ func (l *LINEBotService) ReplyTextMessage(replyToken, message string) {
slog.Error("failed to reply message", err)
}
}

func (l *LINEBotService) ReplyMessage(replyToken string, flexMessage []linebot.SendingMessage) {
if _, err := l.client.ReplyMessage(replyToken, flexMessage...).Do(); err != nil {
slog.Error("failed to reply flex message", err)
}
}

func CreateTimeSelectMessage() *linebot.FlexMessage {
bubble := &linebot.BubbleContainer{
Type: linebot.FlexContainerTypeBubble,
Body: &linebot.BoxComponent{
Type: linebot.FlexComponentTypeBox,
Layout: linebot.FlexBoxLayoutTypeVertical,
Contents: []linebot.FlexComponent{
&linebot.TextComponent{
Type: linebot.FlexComponentTypeText,
Text: "電話をかける時間を\n選択してください",
Weight: linebot.FlexTextWeightTypeBold,
Size: linebot.FlexTextSizeTypeLg,
Margin: linebot.FlexComponentMarginTypeMd,
Align: linebot.FlexComponentAlignTypeCenter,
Wrap: true,
},
createHourRow("09:00", "10:00", "11:00"),
createHourRow("12:00", "13:00", "14:00"),
createHourRow("15:00", "16:00", "17:00"),
createHourRow("18:00", "19:00", "20:00"),
},
},
}

flexMessage := linebot.NewFlexMessage("TimePicker", bubble)
return flexMessage
}

func createHourRow(hour1, hour2, hour3 string) *linebot.BoxComponent {
return &linebot.BoxComponent{
Type: linebot.FlexComponentTypeBox,
Layout: linebot.FlexBoxLayoutTypeHorizontal,
Contents: []linebot.FlexComponent{
&linebot.ButtonComponent{
Type: linebot.FlexComponentTypeButton,
Action: &linebot.PostbackAction{
Label: hour1,
Data: "call_time_picker_" + hour1,
DisplayText: hour1,
},
Flex: linebot.IntPtr(1),
Margin: linebot.FlexComponentMarginTypeSm,
},
&linebot.ButtonComponent{
Type: linebot.FlexComponentTypeButton,
Action: &linebot.PostbackAction{
Label: hour2,
Data: "call_time_picker_" + hour2,
DisplayText: hour2,
},
Flex: linebot.IntPtr(1),
Margin: linebot.FlexComponentMarginTypeSm,
},
&linebot.ButtonComponent{
Type: linebot.FlexComponentTypeButton,
Action: &linebot.PostbackAction{
Label: hour3,
Data: "call_time_picker_" + hour3,
DisplayText: hour3,
},
Flex: linebot.IntPtr(1),
Margin: linebot.FlexComponentMarginTypeSm,
},
},
Margin: linebot.FlexComponentMarginTypeSm,
}
}
6 changes: 5 additions & 1 deletion pkg/util/firestore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func New() *firestore.Client {
}
data, err := os.ReadFile(config.Config.Firestore.JsonCredentialFile)
options := option.WithCredentialsJSON(data)
client, err = firestore.NewClientWithDatabase(ctx, config.Config.Firestore.ProjectID, "(default)", options)
dbID := "(default)"
if config.Config.Firestore.DatabaseID != "" {
dbID = config.Config.Firestore.DatabaseID
}
client, err = firestore.NewClientWithDatabase(ctx, config.Config.Firestore.ProjectID, dbID, options)
if err != nil {
log.Fatalf("firebase.NewClient err: %v", err)
}
Expand Down

0 comments on commit 63274d9

Please sign in to comment.