-
Notifications
You must be signed in to change notification settings - Fork 9
/
flex.go
120 lines (112 loc) · 3.04 KB
/
flex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"net/url"
"github.com/line/line-bot-sdk-go/v8/linebot/messaging_api"
)
const LogoImageUrl = "https://raw.githubusercontent.com/kkdai/linebot-smart-namecard/main/img/logo.jpeg"
// SendFlexMsg: Send flex message to LINE server.
func SendFlexMsg(replyToken string, people []Person, msg string) error {
var cards []messaging_api.FlexBubble
for _, card := range people {
cards = append(cards, getCardFlex(card))
}
contents := &messaging_api.FlexCarousel{
Contents: cards,
}
if _, err := bot.ReplyMessage(
&messaging_api.ReplyMessageRequest{
ReplyToken: replyToken,
Messages: []messaging_api.MessageInterface{
&messaging_api.TextMessage{
Text: msg,
},
&messaging_api.FlexMessage{
Contents: contents,
AltText: "請到手機上查看名片資訊",
},
},
},
); err != nil {
return err
}
return nil
}
// getCardFlex: Send flex message to LINE server.
func getCardFlex(card Person) messaging_api.FlexBubble {
// Get URL encode for company name and address
companyEncode := url.QueryEscape(card.Company)
addressEncode := url.QueryEscape(card.Address)
return messaging_api.FlexBubble{
Size: messaging_api.FlexBubbleSIZE_GIGA,
Body: &messaging_api.FlexBox{
Layout: messaging_api.FlexBoxLAYOUT_HORIZONTAL,
Spacing: "md",
Contents: []messaging_api.FlexComponentInterface{
&messaging_api.FlexImage{
AspectMode: "cover",
AspectRatio: "1:1",
Flex: 1,
Size: "full",
Url: LogoImageUrl,
},
&messaging_api.FlexBox{
Flex: 4,
Layout: messaging_api.FlexBoxLAYOUT_VERTICAL,
Contents: []messaging_api.FlexComponentInterface{
&messaging_api.FlexText{
Align: "end",
Size: "xxl",
Text: card.Name,
Weight: "bold",
},
&messaging_api.FlexText{
Align: "end",
Size: "sm",
Text: card.Title,
},
&messaging_api.FlexText{
Align: "end",
Margin: "xxl",
Size: "lg",
Text: card.Company,
Weight: "bold",
Action: &messaging_api.UriAction{
Uri: "https://www.google.com/maps/search/?api=1&query=" + companyEncode + "&openExternalBrowser=1",
},
},
&messaging_api.FlexText{
Align: "end",
Size: "sm",
Text: card.Address,
Action: &messaging_api.UriAction{
Uri: "https://www.google.com/maps/search/?api=1&query=" + addressEncode + "&openExternalBrowser=1",
},
},
&messaging_api.FlexText{
Align: "end",
Margin: "xxl",
Text: card.Phone,
Action: &messaging_api.UriAction{
Uri: "tel:" + card.Phone,
},
},
&messaging_api.FlexText{
Align: "end",
Text: card.Email,
Action: &messaging_api.UriAction{
Uri: "mailto:" + card.Email,
},
},
&messaging_api.FlexText{
Align: "end",
Text: "更多資訊",
Action: &messaging_api.UriAction{
Uri: "https://github.com/kkdai/linebot-smart-namecard",
},
},
},
},
},
},
}
}