github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/flex.go (about) 1 // Copyright 2018 LINE Corporation 2 // 3 // LINE Corporation licenses this file to you under the Apache License, 4 // version 2.0 (the "License"); you may not use this file except in compliance 5 // with the License. You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package linebot 16 17 import "encoding/json" 18 19 // FlexContainerType type 20 type FlexContainerType string 21 22 // IntPtr is a helper function for using *int values 23 func IntPtr(v int) *int { 24 return &v 25 } 26 27 // FlexContainerType constants 28 const ( 29 FlexContainerTypeBubble FlexContainerType = "bubble" 30 FlexContainerTypeCarousel FlexContainerType = "carousel" 31 ) 32 33 // FlexComponentType type 34 type FlexComponentType string 35 36 // FlexComponentType constants 37 const ( 38 FlexComponentTypeBox FlexComponentType = "box" 39 FlexComponentTypeButton FlexComponentType = "button" 40 FlexComponentTypeFiller FlexComponentType = "filler" 41 FlexComponentTypeIcon FlexComponentType = "icon" 42 FlexComponentTypeImage FlexComponentType = "image" 43 FlexComponentTypeSeparator FlexComponentType = "separator" 44 FlexComponentTypeSpacer FlexComponentType = "spacer" 45 FlexComponentTypeSpan FlexComponentType = "span" 46 FlexComponentTypeText FlexComponentType = "text" 47 FlexComponentTypeVideo FlexComponentType = "video" 48 ) 49 50 // FlexBubbleSizeType type 51 type FlexBubbleSizeType string 52 53 // FlexBubbleSizeType constants 54 const ( 55 FlexBubbleSizeTypeNano FlexBubbleSizeType = "nano" 56 FlexBubbleSizeTypeMicro FlexBubbleSizeType = "micro" 57 FlexBubbleSizeTypeKilo FlexBubbleSizeType = "kilo" 58 FlexBubbleSizeTypeMega FlexBubbleSizeType = "mega" 59 FlexBubbleSizeTypeGiga FlexBubbleSizeType = "giga" 60 ) 61 62 // FlexBubbleDirectionType type 63 type FlexBubbleDirectionType string 64 65 // FlexBubbleDirectionType constants 66 const ( 67 FlexBubbleDirectionTypeLTR FlexBubbleDirectionType = "ltr" 68 FlexBubbleDirectionTypeRTL FlexBubbleDirectionType = "rtl" 69 ) 70 71 // FlexButtonStyleType type 72 type FlexButtonStyleType string 73 74 // FlexButtonStyleType constants 75 const ( 76 FlexButtonStyleTypeLink FlexButtonStyleType = "link" 77 FlexButtonStyleTypePrimary FlexButtonStyleType = "primary" 78 FlexButtonStyleTypeSecondary FlexButtonStyleType = "secondary" 79 ) 80 81 // FlexButtonHeightType type 82 type FlexButtonHeightType string 83 84 // FlexButtonHeightType constants 85 const ( 86 FlexButtonHeightTypeMd FlexButtonHeightType = "md" 87 FlexButtonHeightTypeSm FlexButtonHeightType = "sm" 88 ) 89 90 // FlexIconAspectRatioType type 91 type FlexIconAspectRatioType string 92 93 // FlexIconAspectRatioType constants 94 const ( 95 FlexIconAspectRatioType1to1 FlexIconAspectRatioType = "1:1" 96 FlexIconAspectRatioType2to1 FlexIconAspectRatioType = "2:1" 97 FlexIconAspectRatioType3to1 FlexIconAspectRatioType = "3:1" 98 ) 99 100 // FlexImageSizeType type 101 type FlexImageSizeType string 102 103 // FlexImageSizeType constants 104 const ( 105 FlexImageSizeTypeXxs FlexImageSizeType = "xxs" 106 FlexImageSizeTypeXs FlexImageSizeType = "xs" 107 FlexImageSizeTypeSm FlexImageSizeType = "sm" 108 FlexImageSizeTypeMd FlexImageSizeType = "md" 109 FlexImageSizeTypeLg FlexImageSizeType = "lg" 110 FlexImageSizeTypeXl FlexImageSizeType = "xl" 111 FlexImageSizeTypeXxl FlexImageSizeType = "xxl" 112 FlexImageSizeType3xl FlexImageSizeType = "3xl" 113 FlexImageSizeType4xl FlexImageSizeType = "4xl" 114 FlexImageSizeType5xl FlexImageSizeType = "5xl" 115 FlexImageSizeTypeFull FlexImageSizeType = "full" 116 ) 117 118 // FlexImageAspectRatioType type 119 type FlexImageAspectRatioType string 120 121 // FlexImageAspectRatioType constants 122 const ( 123 FlexImageAspectRatioType1to1 FlexImageAspectRatioType = "1:1" 124 FlexImageAspectRatioType1_51to1 FlexImageAspectRatioType = "1.51:1" 125 FlexImageAspectRatioType1_91to1 FlexImageAspectRatioType = "1.91:1" 126 FlexImageAspectRatioType4to3 FlexImageAspectRatioType = "4:3" 127 FlexImageAspectRatioType16to9 FlexImageAspectRatioType = "16:9" 128 FlexImageAspectRatioType20to13 FlexImageAspectRatioType = "20:13" 129 FlexImageAspectRatioType2to1 FlexImageAspectRatioType = "2:1" 130 FlexImageAspectRatioType3to1 FlexImageAspectRatioType = "3:1" 131 FlexImageAspectRatioType3to4 FlexImageAspectRatioType = "3:4" 132 FlexImageAspectRatioType9to16 FlexImageAspectRatioType = "9:16" 133 FlexImageAspectRatioType1to2 FlexImageAspectRatioType = "1:2" 134 FlexImageAspectRatioType1to3 FlexImageAspectRatioType = "1:3" 135 ) 136 137 // FlexImageAspectModeType type 138 type FlexImageAspectModeType string 139 140 // FlexImageAspectModeType constants 141 const ( 142 FlexImageAspectModeTypeCover FlexImageAspectModeType = "cover" 143 FlexImageAspectModeTypeFit FlexImageAspectModeType = "fit" 144 ) 145 146 // FlexVideoAspectRatioType type 147 type FlexVideoAspectRatioType string 148 149 // FlexVideoAspectRatioType constants 150 const ( 151 FlexVideoAspectRatioType1to1 FlexVideoAspectRatioType = "1:1" 152 FlexVideoAspectRatioType4to3 FlexVideoAspectRatioType = "4:3" 153 FlexVideoAspectRatioType16to9 FlexVideoAspectRatioType = "16:9" 154 FlexVideoAspectRatioType20to13 FlexVideoAspectRatioType = "20:13" 155 FlexVideoAspectRatioType21to9 FlexVideoAspectRatioType = "21:9" 156 FlexVideoAspectRatioType3to4 FlexVideoAspectRatioType = "3:4" 157 FlexVideoAspectRatioType9to16 FlexVideoAspectRatioType = "9:16" 158 FlexVideoAspectRatioType13to20 FlexVideoAspectRatioType = "13:20" 159 FlexVideoAspectRatioType9to21 FlexVideoAspectRatioType = "9:21" 160 ) 161 162 // FlexBoxLayoutType type 163 type FlexBoxLayoutType string 164 165 // FlexBoxLayoutType constants 166 const ( 167 FlexBoxLayoutTypeHorizontal FlexBoxLayoutType = "horizontal" 168 FlexBoxLayoutTypeVertical FlexBoxLayoutType = "vertical" 169 FlexBoxLayoutTypeBaseline FlexBoxLayoutType = "baseline" 170 ) 171 172 // FlexComponentPositionType type 173 type FlexComponentPositionType string 174 175 // FlexComponentPositionType constants 176 const ( 177 FlexComponentPositionTypeRelative FlexComponentPositionType = "relative" 178 FlexComponentPositionTypeAbsolute FlexComponentPositionType = "absolute" 179 ) 180 181 // FlexComponentSpacingType type 182 type FlexComponentSpacingType string 183 184 // FlexComponentSpacingType constants 185 const ( 186 FlexComponentSpacingTypeNone FlexComponentSpacingType = "none" 187 FlexComponentSpacingTypeXs FlexComponentSpacingType = "xs" 188 FlexComponentSpacingTypeSm FlexComponentSpacingType = "sm" 189 FlexComponentSpacingTypeMd FlexComponentSpacingType = "md" 190 FlexComponentSpacingTypeLg FlexComponentSpacingType = "lg" 191 FlexComponentSpacingTypeXl FlexComponentSpacingType = "xl" 192 FlexComponentSpacingTypeXxl FlexComponentSpacingType = "xxl" 193 ) 194 195 // FlexComponentMarginType type 196 type FlexComponentMarginType string 197 198 // FlexComponentMarginType constants 199 const ( 200 FlexComponentMarginTypeNone FlexComponentMarginType = "none" 201 FlexComponentMarginTypeXs FlexComponentMarginType = "xs" 202 FlexComponentMarginTypeSm FlexComponentMarginType = "sm" 203 FlexComponentMarginTypeMd FlexComponentMarginType = "md" 204 FlexComponentMarginTypeLg FlexComponentMarginType = "lg" 205 FlexComponentMarginTypeXl FlexComponentMarginType = "xl" 206 FlexComponentMarginTypeXxl FlexComponentMarginType = "xxl" 207 ) 208 209 // FlexComponentOffsetType type 210 type FlexComponentOffsetType string 211 212 // FlexComponentOffsetType constants 213 const ( 214 FlexComponentOffsetTypeNone FlexComponentOffsetType = "none" 215 FlexComponentOffsetTypeXs FlexComponentOffsetType = "xs" 216 FlexComponentOffsetTypeSm FlexComponentOffsetType = "sm" 217 FlexComponentOffsetTypeMd FlexComponentOffsetType = "md" 218 FlexComponentOffsetTypeLg FlexComponentOffsetType = "lg" 219 FlexComponentOffsetTypeXl FlexComponentOffsetType = "xl" 220 FlexComponentOffsetTypeXxl FlexComponentOffsetType = "xxl" 221 ) 222 223 // FlexComponentPaddingType type 224 type FlexComponentPaddingType string 225 226 // FlexComponentPaddingType constants 227 const ( 228 FlexComponentPaddingTypeNone FlexComponentPaddingType = "none" 229 FlexComponentPaddingTypeXs FlexComponentPaddingType = "xs" 230 FlexComponentPaddingTypeSm FlexComponentPaddingType = "sm" 231 FlexComponentPaddingTypeMd FlexComponentPaddingType = "md" 232 FlexComponentPaddingTypeLg FlexComponentPaddingType = "lg" 233 FlexComponentPaddingTypeXl FlexComponentPaddingType = "xl" 234 FlexComponentPaddingTypeXxl FlexComponentPaddingType = "xxl" 235 ) 236 237 // FlexComponentGravityType type 238 type FlexComponentGravityType string 239 240 // FlexComponentGravityType constants 241 const ( 242 FlexComponentGravityTypeTop FlexComponentGravityType = "top" 243 FlexComponentGravityTypeBottom FlexComponentGravityType = "bottom" 244 FlexComponentGravityTypeCenter FlexComponentGravityType = "center" 245 ) 246 247 // FlexComponentAlignType type 248 type FlexComponentAlignType string 249 250 // FlexComponentAlignType constants 251 const ( 252 FlexComponentAlignTypeStart FlexComponentAlignType = "start" 253 FlexComponentAlignTypeEnd FlexComponentAlignType = "end" 254 FlexComponentAlignTypeCenter FlexComponentAlignType = "center" 255 ) 256 257 // FlexComponentCornerRadiusType type 258 type FlexComponentCornerRadiusType string 259 260 // FlexComponentCornerRadius constants 261 const ( 262 FlexComponentCornerRadiusTypeNone FlexComponentCornerRadiusType = "none" 263 FlexComponentCornerRadiusTypeXs FlexComponentCornerRadiusType = "xs" 264 FlexComponentCornerRadiusTypeSm FlexComponentCornerRadiusType = "sm" 265 FlexComponentCornerRadiusTypeMd FlexComponentCornerRadiusType = "md" 266 FlexComponentCornerRadiusTypeLg FlexComponentCornerRadiusType = "lg" 267 FlexComponentCornerRadiusTypeXl FlexComponentCornerRadiusType = "xl" 268 FlexComponentCornerRadiusTypeXxl FlexComponentCornerRadiusType = "xxl" 269 ) 270 271 // FlexIconSizeType type 272 type FlexIconSizeType string 273 274 // FlexIconSizeType constants 275 const ( 276 FlexIconSizeTypeXxs FlexIconSizeType = "xxs" 277 FlexIconSizeTypeXs FlexIconSizeType = "xs" 278 FlexIconSizeTypeSm FlexIconSizeType = "sm" 279 FlexIconSizeTypeMd FlexIconSizeType = "md" 280 FlexIconSizeTypeLg FlexIconSizeType = "lg" 281 FlexIconSizeTypeXl FlexIconSizeType = "xl" 282 FlexIconSizeTypeXxl FlexIconSizeType = "xxl" 283 FlexIconSizeType3xl FlexIconSizeType = "3xl" 284 FlexIconSizeType4xl FlexIconSizeType = "4xl" 285 FlexIconSizeType5xl FlexIconSizeType = "5xl" 286 ) 287 288 // FlexSpacerSizeType type 289 type FlexSpacerSizeType string 290 291 // FlexSpacerSizeType constants 292 const ( 293 FlexSpacerSizeTypeXs FlexSpacerSizeType = "xs" 294 FlexSpacerSizeTypeSm FlexSpacerSizeType = "sm" 295 FlexSpacerSizeTypeMd FlexSpacerSizeType = "md" 296 FlexSpacerSizeTypeLg FlexSpacerSizeType = "lg" 297 FlexSpacerSizeTypeXl FlexSpacerSizeType = "xl" 298 FlexSpacerSizeTypeXxl FlexSpacerSizeType = "xxl" 299 ) 300 301 // FlexTextWeightType type 302 type FlexTextWeightType string 303 304 // FlexTextWeightType constants 305 const ( 306 FlexTextWeightTypeRegular FlexTextWeightType = "regular" 307 FlexTextWeightTypeBold FlexTextWeightType = "bold" 308 ) 309 310 // FlexTextSizeType type 311 type FlexTextSizeType string 312 313 // FlexTextSizeType constants 314 const ( 315 FlexTextSizeTypeXxs FlexTextSizeType = "xxs" 316 FlexTextSizeTypeXs FlexTextSizeType = "xs" 317 FlexTextSizeTypeSm FlexTextSizeType = "sm" 318 FlexTextSizeTypeMd FlexTextSizeType = "md" 319 FlexTextSizeTypeLg FlexTextSizeType = "lg" 320 FlexTextSizeTypeXl FlexTextSizeType = "xl" 321 FlexTextSizeTypeXxl FlexTextSizeType = "xxl" 322 FlexTextSizeType3xl FlexTextSizeType = "3xl" 323 FlexTextSizeType4xl FlexTextSizeType = "4xl" 324 FlexTextSizeType5xl FlexTextSizeType = "5xl" 325 ) 326 327 // FlexTextStyleType type 328 type FlexTextStyleType string 329 330 // FlexTextStyleType constants 331 const ( 332 FlexTextStyleTypeNormal FlexTextStyleType = "normal" 333 FlexTextStyleTypeItalic FlexTextStyleType = "italic" 334 ) 335 336 // FlexTextDecorationType type 337 type FlexTextDecorationType string 338 339 // FlexTextDecorationType constants 340 const ( 341 FlexTextDecorationTypeNone FlexTextDecorationType = "none" 342 FlexTextDecorationTypeUnderline FlexTextDecorationType = "underline" 343 FlexTextDecorationTypeLineThrough FlexTextDecorationType = "line-through" 344 ) 345 346 // FlexComponentJustifyContentType type 347 type FlexComponentJustifyContentType string 348 349 // FlexComponentJustifyContentType constants 350 const ( 351 FlexComponentJustifyContentTypeFlexStart FlexComponentJustifyContentType = "flex-start" 352 FlexComponentJustifyContentTypeFlexEnd FlexComponentJustifyContentType = "flex-end" 353 FlexComponentJustifyContentTypeCenter FlexComponentJustifyContentType = "center" 354 FlexComponentJustifyContentTypeSpaceBetween FlexComponentJustifyContentType = "space-between" 355 FlexComponentJustifyContentTypeSpaceAround FlexComponentJustifyContentType = "space-around" 356 FlexComponentJustifyContentTypeSpaceEvenly FlexComponentJustifyContentType = "space-evenly" 357 ) 358 359 // FlexComponentAlignItemsType type 360 type FlexComponentAlignItemsType string 361 362 // FlexComponentAlignItemsType constants 363 const ( 364 FlexComponentAlignItemsTypeFlexStart FlexComponentAlignItemsType = "flex-start" 365 FlexComponentAlignItemsTypeFlexEnd FlexComponentAlignItemsType = "flex-end" 366 FlexComponentAlignItemsTypeCenter FlexComponentAlignItemsType = "center" 367 ) 368 369 // FlexComponentAdjustModeType type 370 type FlexComponentAdjustModeType string 371 372 // FlexComponentAdjustModeType constants 373 const ( 374 FlexComponentAdjustModeTypeShrinkToFit FlexComponentAdjustModeType = "shrink-to-fit" 375 ) 376 377 // FlexBoxBackgroundType type 378 type FlexBoxBackgroundType string 379 380 // FlexBoxBackgroundType constants 381 const ( 382 FlexBoxBackgroundTypeLinearGradient FlexBoxBackgroundType = "linearGradient" 383 ) 384 385 // FlexContainer interface 386 type FlexContainer interface { 387 FlexContainer() 388 } 389 390 // BubbleContainer type 391 type BubbleContainer struct { 392 Type FlexContainerType 393 Size FlexBubbleSizeType 394 Direction FlexBubbleDirectionType 395 Header *BoxComponent 396 Hero FlexComponent 397 Body *BoxComponent 398 Footer *BoxComponent 399 Styles *BubbleStyle 400 } 401 402 // MarshalJSON method of BubbleContainer 403 func (c *BubbleContainer) MarshalJSON() ([]byte, error) { 404 return json.Marshal(&struct { 405 Type FlexContainerType `json:"type"` 406 Size FlexBubbleSizeType `json:"size,omitempty"` 407 Direction FlexBubbleDirectionType `json:"direction,omitempty"` 408 Header *BoxComponent `json:"header,omitempty"` 409 Hero FlexComponent `json:"hero,omitempty"` 410 Body *BoxComponent `json:"body,omitempty"` 411 Footer *BoxComponent `json:"footer,omitempty"` 412 Styles *BubbleStyle `json:"styles,omitempty"` 413 }{ 414 Type: FlexContainerTypeBubble, 415 Size: c.Size, 416 Direction: c.Direction, 417 Header: c.Header, 418 Hero: c.Hero, 419 Body: c.Body, 420 Footer: c.Footer, 421 Styles: c.Styles, 422 }) 423 } 424 425 // UnmarshalJSON method of BubbleContainer 426 func (c *BubbleContainer) UnmarshalJSON(b []byte) error { 427 type alias BubbleContainer 428 a := struct { 429 Hero json.RawMessage `json:"hero,omitempty"` 430 *alias 431 }{ 432 alias: (*alias)(c), 433 } 434 if err := json.Unmarshal(b, &a); err != nil { 435 return err 436 } 437 438 if a.Hero == nil { 439 return nil 440 } 441 442 var raw rawFlexComponent 443 if err := json.Unmarshal(a.Hero, &raw); err != nil { 444 return err 445 } 446 c.Hero = raw.Component 447 448 return nil 449 } 450 451 // CarouselContainer type 452 type CarouselContainer struct { 453 Type FlexContainerType 454 Contents []*BubbleContainer 455 } 456 457 // MarshalJSON method of CarouselContainer 458 func (c *CarouselContainer) MarshalJSON() ([]byte, error) { 459 return json.Marshal(&struct { 460 Type FlexContainerType `json:"type"` 461 Contents []*BubbleContainer `json:"contents"` 462 }{ 463 Type: FlexContainerTypeCarousel, 464 Contents: c.Contents, 465 }) 466 } 467 468 // FlexContainer implements FlexContainer interface 469 func (*BubbleContainer) FlexContainer() {} 470 471 // FlexContainer implements FlexContainer interface 472 func (*CarouselContainer) FlexContainer() {} 473 474 // BubbleStyle type 475 type BubbleStyle struct { 476 Header *BlockStyle `json:"header,omitempty"` 477 Hero *BlockStyle `json:"hero,omitempty"` 478 Body *BlockStyle `json:"body,omitempty"` 479 Footer *BlockStyle `json:"footer,omitempty"` 480 } 481 482 // BlockStyle type 483 type BlockStyle struct { 484 BackgroundColor string `json:"backgroundColor,omitempty"` 485 Separator bool `json:"separator,omitempty"` 486 SeparatorColor string `json:"separatorColor,omitempty"` 487 } 488 489 // FlexComponent interface 490 type FlexComponent interface { 491 FlexComponent() 492 } 493 494 // BoxComponent type 495 type BoxComponent struct { 496 Type FlexComponentType 497 Layout FlexBoxLayoutType 498 Position FlexComponentPositionType 499 Contents []FlexComponent 500 Flex *int 501 Spacing FlexComponentSpacingType 502 Margin FlexComponentMarginType 503 Width string 504 MaxWidth string 505 Height string 506 MaxHeight string 507 CornerRadius FlexComponentCornerRadiusType 508 BackgroundColor string 509 BorderColor string 510 BorderWidth string 511 Action TemplateAction 512 JustifyContent FlexComponentJustifyContentType 513 AlignItems FlexComponentAlignItemsType 514 Background *BoxBackground 515 OffsetTop FlexComponentOffsetType 516 OffsetBottom FlexComponentOffsetType 517 OffsetStart FlexComponentOffsetType 518 OffsetEnd FlexComponentOffsetType 519 PaddingAll FlexComponentPaddingType 520 PaddingTop FlexComponentPaddingType 521 PaddingBottom FlexComponentPaddingType 522 PaddingStart FlexComponentPaddingType 523 PaddingEnd FlexComponentPaddingType 524 } 525 526 // MarshalJSON method of BoxComponent 527 func (c *BoxComponent) MarshalJSON() ([]byte, error) { 528 return json.Marshal(&struct { 529 Type FlexComponentType `json:"type"` 530 Layout FlexBoxLayoutType `json:"layout"` 531 Position FlexComponentPositionType `json:"position,omitempty"` 532 Contents []FlexComponent `json:"contents"` 533 Flex *int `json:"flex,omitempty"` 534 Spacing FlexComponentSpacingType `json:"spacing,omitempty"` 535 Margin FlexComponentMarginType `json:"margin,omitempty"` 536 Width string `json:"width,omitempty"` 537 MaxWidth string `json:"maxWidth,omitempty"` 538 Height string `json:"height,omitempty"` 539 MaxHeight string `json:"maxHeight,omitempty"` 540 CornerRadius FlexComponentCornerRadiusType `json:"cornerRadius,omitempty"` 541 BackgroundColor string `json:"backgroundColor,omitempty"` 542 BorderColor string `json:"borderColor,omitempty"` 543 BorderWidth string `json:"borderWidth,omitempty"` 544 Action TemplateAction `json:"action,omitempty"` 545 JustifyContent FlexComponentJustifyContentType `json:"justifyContent,omitempty"` 546 AlignItems FlexComponentAlignItemsType `json:"alignItems,omitempty"` 547 Background *BoxBackground `json:"background,omitempty"` 548 OffsetTop FlexComponentOffsetType `json:"offsetTop,omitempty"` 549 OffsetBottom FlexComponentOffsetType `json:"offsetBottom,omitempty"` 550 OffsetStart FlexComponentOffsetType `json:"offsetStart,omitempty"` 551 OffsetEnd FlexComponentOffsetType `json:"offsetEnd,omitempty"` 552 PaddingAll FlexComponentPaddingType `json:"paddingAll,omitempty"` 553 PaddingTop FlexComponentPaddingType `json:"paddingTop,omitempty"` 554 PaddingBottom FlexComponentPaddingType `json:"paddingBottom,omitempty"` 555 PaddingStart FlexComponentPaddingType `json:"paddingStart,omitempty"` 556 PaddingEnd FlexComponentPaddingType `json:"paddingEnd,omitempty"` 557 }{ 558 Type: FlexComponentTypeBox, 559 Layout: c.Layout, 560 Position: c.Position, 561 Contents: c.Contents, 562 Flex: c.Flex, 563 Spacing: c.Spacing, 564 Margin: c.Margin, 565 Width: c.Width, 566 MaxWidth: c.MaxWidth, 567 Height: c.Height, 568 MaxHeight: c.MaxHeight, 569 CornerRadius: c.CornerRadius, 570 BackgroundColor: c.BackgroundColor, 571 BorderColor: c.BorderColor, 572 BorderWidth: c.BorderWidth, 573 Action: c.Action, 574 JustifyContent: c.JustifyContent, 575 AlignItems: c.AlignItems, 576 Background: c.Background, 577 OffsetTop: c.OffsetTop, 578 OffsetBottom: c.OffsetBottom, 579 OffsetStart: c.OffsetStart, 580 OffsetEnd: c.OffsetEnd, 581 PaddingAll: c.PaddingAll, 582 PaddingTop: c.PaddingTop, 583 PaddingBottom: c.PaddingBottom, 584 PaddingStart: c.PaddingStart, 585 PaddingEnd: c.PaddingEnd, 586 }) 587 } 588 589 // BoxBackground type 590 type BoxBackground struct { 591 Type FlexBoxBackgroundType `json:"type,omitempty"` 592 Angle string `json:"angle,omitempty"` 593 StartColor string `json:"startColor,omitempty"` 594 EndColor string `json:"endColor,omitempty"` 595 CenterColor string `json:"centerColor,omitempty"` 596 CenterPosition string `json:"centerPosition,omitempty"` 597 } 598 599 // ButtonComponent type 600 type ButtonComponent struct { 601 Type FlexComponentType 602 Action TemplateAction 603 Position FlexComponentPositionType 604 Flex *int 605 Margin FlexComponentMarginType 606 Height FlexButtonHeightType 607 Style FlexButtonStyleType 608 Color string 609 Gravity FlexComponentGravityType 610 AdjustMode FlexComponentAdjustModeType 611 OffsetTop FlexComponentOffsetType 612 OffsetBottom FlexComponentOffsetType 613 OffsetStart FlexComponentOffsetType 614 OffsetEnd FlexComponentOffsetType 615 } 616 617 // MarshalJSON method of ButtonComponent 618 func (c *ButtonComponent) MarshalJSON() ([]byte, error) { 619 return json.Marshal(&struct { 620 Type FlexComponentType `json:"type"` 621 Action TemplateAction `json:"action"` 622 Position FlexComponentPositionType `json:"position,omitempty"` 623 Flex *int `json:"flex,omitempty"` 624 Margin FlexComponentMarginType `json:"margin,omitempty"` 625 Height FlexButtonHeightType `json:"height,omitempty"` 626 Style FlexButtonStyleType `json:"style,omitempty"` 627 Color string `json:"color,omitempty"` 628 Gravity FlexComponentGravityType `json:"gravity,omitempty"` 629 AdjustMode FlexComponentAdjustModeType `json:"adjustMode,omitempty"` 630 OffsetTop FlexComponentOffsetType `json:"offsetTop,omitempty"` 631 OffsetBottom FlexComponentOffsetType `json:"offsetBottom,omitempty"` 632 OffsetStart FlexComponentOffsetType `json:"offsetStart,omitempty"` 633 OffsetEnd FlexComponentOffsetType `json:"offsetEnd,omitempty"` 634 }{ 635 Type: FlexComponentTypeButton, 636 Action: c.Action, 637 Position: c.Position, 638 Flex: c.Flex, 639 Margin: c.Margin, 640 Height: c.Height, 641 Style: c.Style, 642 Color: c.Color, 643 Gravity: c.Gravity, 644 AdjustMode: c.AdjustMode, 645 OffsetTop: c.OffsetTop, 646 OffsetBottom: c.OffsetBottom, 647 OffsetStart: c.OffsetStart, 648 OffsetEnd: c.OffsetEnd, 649 }) 650 } 651 652 // FillerComponent type 653 type FillerComponent struct { 654 Type FlexComponentType 655 Flex *int 656 } 657 658 // MarshalJSON method of FillerComponent 659 func (c *FillerComponent) MarshalJSON() ([]byte, error) { 660 return json.Marshal(&struct { 661 Type FlexComponentType `json:"type"` 662 Flex *int `json:"flex,omitempty"` 663 }{ 664 Type: FlexComponentTypeFiller, 665 Flex: c.Flex, 666 }) 667 } 668 669 // IconComponent type 670 type IconComponent struct { 671 Type FlexComponentType 672 URL string 673 Margin FlexComponentMarginType 674 Size FlexIconSizeType 675 AspectRatio FlexIconAspectRatioType 676 } 677 678 // MarshalJSON method of IconComponent 679 func (c *IconComponent) MarshalJSON() ([]byte, error) { 680 return json.Marshal(&struct { 681 Type FlexComponentType `json:"type"` 682 URL string `json:"url"` 683 Margin FlexComponentMarginType `json:"margin,omitempty"` 684 Size FlexIconSizeType `json:"size,omitempty"` 685 AspectRatio FlexIconAspectRatioType `json:"aspectRatio,omitempty"` 686 }{ 687 Type: FlexComponentTypeIcon, 688 URL: c.URL, 689 Margin: c.Margin, 690 Size: c.Size, 691 AspectRatio: c.AspectRatio, 692 }) 693 } 694 695 // ImageComponent type 696 type ImageComponent struct { 697 Type FlexComponentType 698 URL string 699 Position FlexComponentPositionType 700 Flex *int 701 Margin FlexComponentMarginType 702 Align FlexComponentAlignType 703 Gravity FlexComponentGravityType 704 Size FlexImageSizeType 705 AspectRatio FlexImageAspectRatioType 706 AspectMode FlexImageAspectModeType 707 BackgroundColor string 708 Action TemplateAction 709 Animated bool 710 OffsetTop FlexComponentOffsetType 711 OffsetBottom FlexComponentOffsetType 712 OffsetStart FlexComponentOffsetType 713 OffsetEnd FlexComponentOffsetType 714 } 715 716 // MarshalJSON method of ImageComponent 717 func (c *ImageComponent) MarshalJSON() ([]byte, error) { 718 return json.Marshal(&struct { 719 Type FlexComponentType `json:"type"` 720 URL string `json:"url"` 721 Position FlexComponentPositionType `json:"position,omitempty"` 722 Flex *int `json:"flex,omitempty"` 723 Margin FlexComponentMarginType `json:"margin,omitempty"` 724 Align FlexComponentAlignType `json:"align,omitempty"` 725 Gravity FlexComponentGravityType `json:"gravity,omitempty"` 726 Size FlexImageSizeType `json:"size,omitempty"` 727 AspectRatio FlexImageAspectRatioType `json:"aspectRatio,omitempty"` 728 AspectMode FlexImageAspectModeType `json:"aspectMode,omitempty"` 729 BackgroundColor string `json:"backgroundColor,omitempty"` 730 Action TemplateAction `json:"action,omitempty"` 731 Animated bool `json:"animated,omitempty"` 732 OffsetTop FlexComponentOffsetType `json:"offsetTop,omitempty"` 733 OffsetBottom FlexComponentOffsetType `json:"offsetBottom,omitempty"` 734 OffsetStart FlexComponentOffsetType `json:"offsetStart,omitempty"` 735 OffsetEnd FlexComponentOffsetType `json:"offsetEnd,omitempty"` 736 }{ 737 Type: FlexComponentTypeImage, 738 URL: c.URL, 739 Position: c.Position, 740 Flex: c.Flex, 741 Margin: c.Margin, 742 Align: c.Align, 743 Gravity: c.Gravity, 744 Size: c.Size, 745 AspectRatio: c.AspectRatio, 746 AspectMode: c.AspectMode, 747 BackgroundColor: c.BackgroundColor, 748 Action: c.Action, 749 Animated: c.Animated, 750 OffsetTop: c.OffsetTop, 751 OffsetBottom: c.OffsetBottom, 752 OffsetStart: c.OffsetStart, 753 OffsetEnd: c.OffsetEnd, 754 }) 755 } 756 757 // SeparatorComponent type 758 type SeparatorComponent struct { 759 Type FlexComponentType 760 Margin FlexComponentMarginType 761 Color string 762 } 763 764 // MarshalJSON method of SeparatorComponent 765 func (c *SeparatorComponent) MarshalJSON() ([]byte, error) { 766 return json.Marshal(&struct { 767 Type FlexComponentType `json:"type"` 768 Margin FlexComponentMarginType `json:"margin,omitempty"` 769 Color string `json:"color,omitempty"` 770 }{ 771 Type: FlexComponentTypeSeparator, 772 Margin: c.Margin, 773 Color: c.Color, 774 }) 775 } 776 777 // SpacerComponent type 778 type SpacerComponent struct { 779 Type FlexComponentType 780 Size FlexSpacerSizeType 781 } 782 783 // MarshalJSON method of SpacerComponent 784 func (c *SpacerComponent) MarshalJSON() ([]byte, error) { 785 return json.Marshal(&struct { 786 Type FlexComponentType `json:"type"` 787 Size FlexSpacerSizeType `json:"size,omitempty"` 788 }{ 789 Type: FlexComponentTypeSpacer, 790 Size: c.Size, 791 }) 792 } 793 794 // SpanComponent type 795 type SpanComponent struct { 796 Type FlexComponentType 797 Text string 798 Size FlexTextSizeType 799 Weight FlexTextWeightType 800 Color string 801 Style FlexTextStyleType 802 Decoration FlexTextDecorationType 803 } 804 805 // MarshalJSON method of SpanComponent 806 func (c *SpanComponent) MarshalJSON() ([]byte, error) { 807 return json.Marshal(&struct { 808 Type FlexComponentType `json:"type"` 809 Text string `json:"text,omitempty"` 810 Size FlexTextSizeType `json:"size,omitempty"` 811 Weight FlexTextWeightType `json:"weight,omitempty"` 812 Color string `json:"color,omitempty"` 813 Style FlexTextStyleType `json:"style,omitempty"` 814 Decoration FlexTextDecorationType `json:"decoration,omitempty"` 815 }{ 816 Type: FlexComponentTypeSpan, 817 Text: c.Text, 818 Size: c.Size, 819 Weight: c.Weight, 820 Color: c.Color, 821 Style: c.Style, 822 Decoration: c.Decoration, 823 }) 824 } 825 826 // TextComponent type 827 type TextComponent struct { 828 Type FlexComponentType 829 Text string 830 Position FlexComponentPositionType 831 Contents []*SpanComponent 832 Flex *int 833 Margin FlexComponentMarginType 834 Size FlexTextSizeType 835 Align FlexComponentAlignType 836 Gravity FlexComponentGravityType 837 Wrap bool 838 LineSpacing string 839 Weight FlexTextWeightType 840 Color string 841 Action TemplateAction 842 Style FlexTextStyleType 843 Decoration FlexTextDecorationType 844 MaxLines *int 845 AdjustMode FlexComponentAdjustModeType 846 OffsetTop FlexComponentOffsetType 847 OffsetBottom FlexComponentOffsetType 848 OffsetStart FlexComponentOffsetType 849 OffsetEnd FlexComponentOffsetType 850 } 851 852 // MarshalJSON method of TextComponent 853 func (c *TextComponent) MarshalJSON() ([]byte, error) { 854 return json.Marshal(&struct { 855 Type FlexComponentType `json:"type"` 856 Text string `json:"text,omitempty"` 857 Position FlexComponentPositionType `json:"position,omitempty"` 858 Contents []*SpanComponent `json:"contents,omitempty"` 859 Flex *int `json:"flex,omitempty"` 860 Margin FlexComponentMarginType `json:"margin,omitempty"` 861 Size FlexTextSizeType `json:"size,omitempty"` 862 Align FlexComponentAlignType `json:"align,omitempty"` 863 Gravity FlexComponentGravityType `json:"gravity,omitempty"` 864 Wrap bool `json:"wrap,omitempty"` 865 LineSpacing string `json:"lineSpacing,omitempty"` 866 Weight FlexTextWeightType `json:"weight,omitempty"` 867 Color string `json:"color,omitempty"` 868 Action TemplateAction `json:"action,omitempty"` 869 Style FlexTextStyleType `json:"style,omitempty"` 870 Decoration FlexTextDecorationType `json:"decoration,omitempty"` 871 MaxLines *int `json:"maxLines,omitempty"` 872 AdjustMode FlexComponentAdjustModeType `json:"adjustMode,omitempty"` 873 OffsetTop FlexComponentOffsetType `json:"offsetTop,omitempty"` 874 OffsetBottom FlexComponentOffsetType `json:"offsetBottom,omitempty"` 875 OffsetStart FlexComponentOffsetType `json:"offsetStart,omitempty"` 876 OffsetEnd FlexComponentOffsetType `json:"offsetEnd,omitempty"` 877 }{ 878 Type: FlexComponentTypeText, 879 Text: c.Text, 880 Position: c.Position, 881 Contents: c.Contents, 882 Flex: c.Flex, 883 Margin: c.Margin, 884 Size: c.Size, 885 Align: c.Align, 886 Gravity: c.Gravity, 887 Wrap: c.Wrap, 888 LineSpacing: c.LineSpacing, 889 Weight: c.Weight, 890 Color: c.Color, 891 Action: c.Action, 892 Style: c.Style, 893 Decoration: c.Decoration, 894 MaxLines: c.MaxLines, 895 AdjustMode: c.AdjustMode, 896 OffsetTop: c.OffsetTop, 897 OffsetBottom: c.OffsetBottom, 898 OffsetStart: c.OffsetStart, 899 OffsetEnd: c.OffsetEnd, 900 }) 901 } 902 903 // VideoComponent type 904 type VideoComponent struct { 905 Type FlexComponentType 906 URL string 907 PreviewURL string 908 AltContent FlexComponent 909 AspectRatio FlexVideoAspectRatioType 910 Action *URIAction 911 } 912 913 // MarshalJSON method of VideoComponent 914 func (c *VideoComponent) MarshalJSON() ([]byte, error) { 915 return json.Marshal(&struct { 916 Type FlexComponentType `json:"type"` 917 URL string `json:"url"` 918 PreviewURL string `json:"previewUrl"` 919 AltContent FlexComponent `json:"altContent"` 920 AspectRatio FlexVideoAspectRatioType `json:"aspectRatio,omitempty"` 921 Action *URIAction `json:"action,omitempty"` 922 }{ 923 Type: FlexComponentTypeVideo, 924 URL: c.URL, 925 PreviewURL: c.PreviewURL, 926 AltContent: c.AltContent, 927 AspectRatio: c.AspectRatio, 928 Action: c.Action, 929 }) 930 } 931 932 // FlexComponent implements FlexComponent interface 933 func (*BoxComponent) FlexComponent() {} 934 935 // FlexComponent implements FlexComponent interface 936 func (*ButtonComponent) FlexComponent() {} 937 938 // FlexComponent implements FlexComponent interface 939 func (*FillerComponent) FlexComponent() {} 940 941 // FlexComponent implements FlexComponent interface 942 func (*IconComponent) FlexComponent() {} 943 944 // FlexComponent implements FlexComponent interface 945 func (*ImageComponent) FlexComponent() {} 946 947 // FlexComponent implements FlexComponent interface 948 func (*SeparatorComponent) FlexComponent() {} 949 950 // FlexComponent implements FlexComponent interface 951 func (*SpacerComponent) FlexComponent() {} 952 953 // FlexComponent implements FlexComponent interface 954 func (*SpanComponent) FlexComponent() {} 955 956 // FlexComponent implements FlexComponent interface 957 func (*TextComponent) FlexComponent() {} 958 959 // FlexComponent implements FlexComponent interface 960 func (*VideoComponent) FlexComponent() {}