Skip to content

Commit

Permalink
add:message card i18n code sample
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaomingqiang committed Mar 2, 2022
1 parent a789bd2 commit 8c7533e
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 18 deletions.
54 changes: 54 additions & 0 deletions sample/api/message_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func main() {
printMessageText()
printMessagePost()
printMessageCard()
printMessageCardI18n()
printMessageImage()
printMessageShareChat()
printMessageShareUser()
Expand Down Expand Up @@ -146,6 +147,59 @@ func printMessageCard() {
fmt.Println("-----------------------------------------")
}

func printMessageCardI18n() {
card := &lark.MessageCard{
CardLink: &lark.MessageCardURL{
URL: "https://www.feishu.cn",
AndroidURL: "https://www.feishu.cn",
IOSURL: "https://www.feishu.cn",
PCURL: "https://www.feishu.cn",
},
Config: &lark.MessageCardConfig{EnableForward: lark.BoolPtr(true)},
Header: &lark.MessageCardHeader{
Template: lark.StringPtr("blue"),
Title: &lark.MessageCardPlainText{
I18n: &lark.MessageCardPlainTextI18n{
ZhCN: "ZhCN Header title",
EnUS: "",
JaJP: "JaJP Header title",
},
},
},
I18nElements: &lark.MessageCardI18nElements{
ZhCN: []lark.MessageCardElement{
&lark.MessageCardMarkdown{
Content: "**ZhCN**",
},
&lark.MessageCardMarkdown{
Content: "**ZhCN-2**",
},
},
EnUS: []lark.MessageCardElement{
&lark.MessageCardMarkdown{
Content: "**EnUS**",
},
&lark.MessageCardMarkdown{
Content: "**EnUS-2**",
},
},
JaJP: []lark.MessageCardElement{
&lark.MessageCardMarkdown{
Content: "**JaJP**",
},
&lark.MessageCardMarkdown{
Content: "**JaJP-2**",
},
},
},
}
s, err := card.JSON()
if err != nil {
panic(err)
}
fmt.Println(s)
}

func printMessageImage() {
image := &lark.MessageImage{ImageKey: "img_v2_9221f258-db3e-4a40-b9cb-24decddee2bg"}
s, err := image.JSON()
Expand Down
92 changes: 75 additions & 17 deletions sample/api/message_model_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,88 @@ import (
)

func main() {
printMessageCard1()
printMessageCardWithAction()
//printMessageCardWithI18n()
}

func printMessageCard1() {
card := lark.MessageCard{
func printMessageCardWithAction() {
card := &lark.MessageCard{
CardLink: &lark.MessageCardURL{
URL: "https://www.feishu.cn",
AndroidURL: "https://www.feishu.cn",
IOSURL: "https://www.feishu.cn",
PCURL: "https://www.feishu.cn",
},
Config: &lark.MessageCardConfig{EnableForward: lark.BoolPtr(true)},
Header: &lark.MessageCardHeader{
Title: &lark.MessageCardPlainText{Content: "k8s ticket"},
Template: lark.StringPtr("indigo"),
Template: lark.StringPtr("blue"),
Title: &lark.MessageCardPlainText{
Content: "Header title",
},
},
}
element := &lark.MessageCardAction{}
cluster := &lark.MessageCardEmbedSelectMenuStatic{
MessageCardEmbedSelectMenuBase: &lark.MessageCardEmbedSelectMenuBase{
Placeholder: &lark.MessageCardPlainText{
Content: "choose cluster",
Elements: []lark.MessageCardElement{
&lark.MessageCardImage{
Alt: &lark.MessageCardPlainText{
Content: "img_v2_9221f258-db3e-4a40-b9cb-24decddee2bg",
Lines: nil,
},
Title: &lark.MessageCardPlainText{
Content: "img_v2_9221f258-db3e-4a40-b9cb-24decddee2bg",
},
ImgKey: "img_v2_9221f258-db3e-4a40-b9cb-24decddee2bg",
CustomWidth: lark.IntPtr(300),
CompactWidth: lark.BoolPtr(false),
},
&lark.MessageCardAction{
Actions: []lark.MessageCardActionElement{
&lark.MessageCardEmbedButton{
Text: &lark.MessageCardPlainText{
Content: "button",
},
Type: lark.MessageCardButtonTypeDanger.Ptr(),
Value: map[string]interface{}{"value": "1"},
Confirm: &lark.MessageCardActionConfirm{
Title: &lark.MessageCardPlainText{
Content: "Title",
},
Text: &lark.MessageCardPlainText{
Content: "Text",
},
},
},
},
Layout: lark.MessageCardActionLayoutFlow.Ptr(),
},
&lark.MessageCardMarkdown{
Content: "**Markdown**",
},
&lark.MessageCardDiv{
Text: &lark.MessageCardPlainText{
Content: "text",
},
Extra: &lark.MessageCardEmbedButton{
Text: &lark.MessageCardPlainText{
Content: "button",
},
Type: lark.MessageCardButtonTypeDanger.Ptr(),
Value: map[string]interface{}{"value": "1"},
Confirm: &lark.MessageCardActionConfirm{
Title: &lark.MessageCardPlainText{
Content: "Title",
},
Text: &lark.MessageCardPlainText{
Content: "Text",
},
},
},
},
InitialOption: "dev",
},
}
element.Actions = append(element.Actions, cluster)
card.Elements = append(card.Elements, element)
content, err := card.JSON()
s, err := card.JSON()
if err != nil {
fmt.Println(err)
panic(err)
}
fmt.Printf("card:%s\n", content)
fmt.Println("MessageCard: ----------------------------")
fmt.Println(s)
fmt.Println("-----------------------------------------")
}
2 changes: 1 addition & 1 deletion sample/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/go-redis/redis/v8 v8.11.4
github.com/larksuite/oapi-sdk-go/v2 v2.0.7
github.com/larksuite/oapi-sdk-go/v2 v2.0.10-0.20220302071802-a789bd255ddb
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.6.1 // indirect
)
2 changes: 2 additions & 0 deletions sample/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/larksuite/oapi-sdk-go/v2 v2.0.7 h1:4MLxG40DKhdDhHdf/Wd5SUIDipX3K3Vj0XV9aGaSh8Y=
github.com/larksuite/oapi-sdk-go/v2 v2.0.7/go.mod h1:ruCRr2wLAZJGJRugAgO70rbdpnIiLkz6sTlGQC38jcs=
github.com/larksuite/oapi-sdk-go/v2 v2.0.10-0.20220302071802-a789bd255ddb h1:HM9GIIaD4/b1Lt937k+/X0N3GiPCGR7iR7K9QOfGGuE=
github.com/larksuite/oapi-sdk-go/v2 v2.0.10-0.20220302071802-a789bd255ddb/go.mod h1:ruCRr2wLAZJGJRugAgO70rbdpnIiLkz6sTlGQC38jcs=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down

0 comments on commit 8c7533e

Please sign in to comment.