Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flex Template Align Error #505

Open
FawenYo opened this issue Nov 14, 2024 · 1 comment
Open

Flex Template Align Error #505

FawenYo opened this issue Nov 14, 2024 · 1 comment
Labels

Comments

@FawenYo
Copy link

FawenYo commented Nov 14, 2024

System Informations

  • Go version: 1.23.2-alpine3.20
  • OS: alpine
  • Package version: github.com/line/line-bot-sdk-go/v8 v8.10.0

Expected Behavior

Here is a simple Flex message I design with the Flex Message Simulator tool

{
  "type": "bubble",
  "body": {
    "type": "box",
    "layout": "vertical",
    "contents": [
      {
        "type": "box",
        "layout": "horizontal",
        "contents": [
          {
            "type": "text",
            "text": "測試",
            "size": "sm",
            "color": "#555555",
            "flex": 0
          },
          {
            "type": "text",
            "text": "123",
            "size": "sm",
            "color": "#111111",
            "align": "end"
          }
        ]
      }
    ]
  },
  "styles": {
    "footer": {
      "separator": true
    }
  }
}

and the message should look like this

image

Current Behavior

Here is part of my Golang code

jsonString := fmt.Sprintf(`{
"type": "bubble",
"body": {
	"type": "box",
	"layout": "vertical",
	"contents": [
	{
		"type": "box",
		"layout": "horizontal",
		"contents": [
		{
			"type": "text",
			"text": "測試",
			"size": "sm",
			"color": "#555555",
			"flex": 0
		},
		{
			"type": "text",
			"text": "123",
			"size": "sm",
			"color": "#111111",
			"align": "end"
		}
		]
	}
	]
},
"styles": {
	"footer": {
	"separator": true
	}
}
}`)
		  
contents, err := messaging_api.UnmarshalFlexContainer([]byte(jsonString))
if err != nil {
	log.WithField("userName", displayName).WithField("userID", userID).Errorf("Failed to unmarshal flex container: %s", err)
	replyMessage = &messaging_api.TextMessage{
		Text: "Failed to unmarshal",
	}
}

replyMessage = &messaging_api.FlexMessage{
	AltText:  "Test",
	Contents: contents,
}
if _, err := bot.ReplyMessage(
	&messaging_api.ReplyMessageRequest{
		ReplyToken: replyToken,
		Messages:   []messaging_api.MessageInterface{replyMessage},
	},
); err != nil {
	log.WithField("userName", displayName).WithField("userID", userID).Errorf("Failed to reply message: %s", err)
}

and the sent image looks like this

image

The align format is quite different from the expected one.

Steps to Reproduce

  1. Follow the example flex message JSON above to test to send with the SDK

Logs

No obvious error log

@FawenYo FawenYo added the bug label Nov 14, 2024
@FawenYo
Copy link
Author

FawenYo commented Nov 15, 2024

So I just found where the problem is...

For content without the flex key, the SDK automatically adds flex: 0 to the component attribute. However, flex:0 could break the design.
I don't know if the behavior in the SDK is a bug or if it was added out of kindness, but I suggest not adding this key.

(FYI, until the fixed build comes out, you can add flex: 999 to those components without flex as a temporary solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant