Skip to content

Instantly share code, notes, and snippets.

@kkdai
Created June 16, 2023 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkdai/dd0fa35461dba10ebb1cdf5c42a08f81 to your computer and use it in GitHub Desktop.
Save kkdai/dd0fa35461dba10ebb1cdf5c42a08f81 to your computer and use it in GitHub Desktop.
func getPOIsFlexBubble(records ResponsePOI) []*linebot.BubbleContainer {
log.Println("getPOIsFlexBubble")
if len(records.Pois) == 0 {
log.Println("err1")
return nil
}
var columnList []*linebot.BubbleContainer
for _, result := range records.Pois {
log.Println("Add flex:", result.Name, result.CoverPhoto, result.PoiURL)
name := linebot.TextComponent{
Type: linebot.FlexComponentTypeText,
Text: result.Name,
Weight: linebot.FlexTextWeightTypeBold,
Size: linebot.FlexTextSizeTypeSm,
Wrap: true,
}
nickN := result.Name
if len(result.Nickname) > 0 {
nickN = result.Nickname[0]
}
nickName := linebot.TextComponent{
Type: linebot.FlexComponentTypeText,
Text: nickN,
Weight: linebot.FlexTextWeightTypeBold,
Size: linebot.FlexTextSizeTypeSm,
Wrap: true,
}
btn := linebot.ButtonComponent{
Type: linebot.FlexComponentTypeButton,
Action: &linebot.URIAction{
Label: "帶我去",
URI: result.PoiURL,
},
}
var boxBody []linebot.FlexComponent
boxBody = append(boxBody, &name, &nickName, &btn)
// Title's hard limit by Line
coverPhoto := IMG_NOT_FOUND
if result.CoverPhoto != "" {
coverPhoto = result.CoverPhoto
}
tmpColumn := linebot.BubbleContainer{
Type: linebot.FlexContainerTypeBubble,
Size: linebot.FlexBubbleSizeTypeMicro,
Hero: &linebot.ImageComponent{
Type: linebot.FlexComponentTypeImage,
URL: coverPhoto,
Size: linebot.FlexImageSizeTypeFull,
AspectRatio: linebot.FlexImageAspectRatioType1to1,
AspectMode: linebot.FlexImageAspectModeTypeCover,
},
Body: &linebot.BoxComponent{
Type: linebot.FlexComponentTypeBox,
Layout: linebot.FlexBoxLayoutTypeVertical,
Contents: boxBody,
},
}
columnList = append(columnList, &tmpColumn)
}
return columnList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment