Skip to content

Commit

Permalink
Merge pull request #21 from kkdai/new_flex_card
Browse files Browse the repository at this point in the history
feat: add new functionality for sending flex messages with a new image
  • Loading branch information
kkdai committed Jan 30, 2024
2 parents 556bba3 + 67a131d commit 3ed37dc
Showing 1 changed file with 91 additions and 3 deletions.
94 changes: 91 additions & 3 deletions flex.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package main

import "github.com/line/line-bot-sdk-go/v8/linebot/messaging_api"
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"

// getSingleCard: Send flex message to LINE server.
func getSingleCard(card Person) messaging_api.FlexBubble {

return messaging_api.FlexBubble{
Expand Down Expand Up @@ -31,7 +38,7 @@ func getSingleCard(card Person) messaging_api.FlexBubble {
AspectMode: "cover",
AspectRatio: "1:1",
Gravity: "center",
Url: "https://raw.githubusercontent.com/kkdai/linebot-smart-namecard/main/img/logo.jpeg",
Url: LogoImageUrl,
},
},
},
Expand Down Expand Up @@ -103,7 +110,7 @@ func getSingleCard(card Person) messaging_api.FlexBubble {
func SendFlexMsg(replyToken string, people []Person, msg string) error {
var cards []messaging_api.FlexBubble
for _, card := range people {
cards = append(cards, getSingleCard(card))
cards = append(cards, getNewSingleCard(card))
}

contents := &messaging_api.FlexCarousel{
Expand All @@ -128,3 +135,84 @@ func SendFlexMsg(replyToken string, people []Person, msg string) error {
}
return nil
}

// getNewSingleCard: Send flex message to LINE server.
func getNewSingleCard(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.PhoneNumber,
Action: &messaging_api.UriAction{
Uri: "tel:" + card.PhoneNumber,
},
},
&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",
},
},
},
},
},
},
}
}

0 comments on commit 3ed37dc

Please sign in to comment.