Repository: line/line-bot-sdk-go (go)

Issue:
Support rich menu switch action
- Rich menu switch action has been added to action object
- postback.params object for rich menu switch action has been added to Postback event

https://developers.line.biz/en/news/2021/06/21/switch-between-multiple-rich-menus/

this is related to #284 .


Pull request:
Fix #285 Support rich menu switch action
#285 

Patch:
diff --git a/examples/richmenu_helper/main.go b/examples/richmenu_helper/main.go
index e2cad57..09a4936 100644
--- a/examples/richmenu_helper/main.go
+++ b/examples/richmenu_helper/main.go
@@ -132,14 +132,30 @@ func main() {
 			ChatBarText: "ChatText",
 			Areas: []linebot.AreaDetail{
 				{
-					Bounds: linebot.RichMenuBounds{X: 0, Y: 0, Width: 1250, Height: 843},
+					Bounds: linebot.RichMenuBounds{X: 0, Y: 0, Width: 1250, Height: 212},
+					Action: linebot.RichMenuAction{
+						Type:            linebot.RichMenuActionTypeRichMenuSwitch,
+						RichMenuAliasID: "richmenu-alias-a",
+						Data:            "action=richmenu-changed-to-a",
+					},
+				},
+				{
+					Bounds: linebot.RichMenuBounds{X: 1250, Y: 0, Width: 1250, Height: 212},
+					Action: linebot.RichMenuAction{
+						Type:            linebot.RichMenuActionTypeRichMenuSwitch,
+						RichMenuAliasID: "richmenu-alias-b",
+						Data:            "action=richmenu-changed-to-b",
+					},
+				},
+				{
+					Bounds: linebot.RichMenuBounds{X: 0, Y: 212, Width: 1250, Height: 737},
 					Action: linebot.RichMenuAction{
 						Type: linebot.RichMenuActionTypePostback,
 						Data: "action=buy&itemid=123",
 					},
 				},
 				{
-					Bounds: linebot.RichMenuBounds{X: 1250, Y: 0, Width: 1250, Height: 843},
+					Bounds: linebot.RichMenuBounds{X: 1250, Y: 212, Width: 1250, Height: 737},
 					Action: linebot.RichMenuAction{
 						Type: linebot.RichMenuActionTypeURI,
 						URI:  "https://developers.line.me/",
@@ -147,14 +163,14 @@ func main() {
 					},
 				},
 				{
-					Bounds: linebot.RichMenuBounds{X: 0, Y: 843, Width: 1250, Height: 843},
+					Bounds: linebot.RichMenuBounds{X: 0, Y: 949, Width: 1250, Height: 737},
 					Action: linebot.RichMenuAction{
 						Type: linebot.RichMenuActionTypeMessage,
 						Text: "hello world!",
 					},
 				},
 				{
-					Bounds: linebot.RichMenuBounds{X: 1250, Y: 843, Width: 1250, Height: 843},
+					Bounds: linebot.RichMenuBounds{X: 1250, Y: 949, Width: 1250, Height: 737},
 					Action: linebot.RichMenuAction{
 						Type: linebot.RichMenuActionTypeDatetimePicker,
 						Data: "datetime picker!",
diff --git a/linebot/event.go b/linebot/event.go
index 73d6488..145ac05 100644
--- a/linebot/event.go
+++ b/linebot/event.go
@@ -69,9 +69,11 @@ type EventSource struct {
 
 // Params type
 type Params struct {
-	Date     string `json:"date,omitempty"`
-	Time     string `json:"time,omitempty"`
-	Datetime string `json:"datetime,omitempty"`
+	Date               string `json:"date,omitempty"`
+	Time               string `json:"time,omitempty"`
+	Datetime           string `json:"datetime,omitempty"`
+	NewRichMenuAliasID string `json:"newRichMenuAliasId,omitempty"`
+	Status             string `json:"status,omitempty"`
 }
 
 // Members type
diff --git a/linebot/richmenu.go b/linebot/richmenu.go
index 6e786e8..a67af27 100644
--- a/linebot/richmenu.go
+++ b/linebot/richmenu.go
@@ -33,6 +33,7 @@ const (
 	RichMenuActionTypeMessage        RichMenuActionType = "message"
 	RichMenuActionTypePostback       RichMenuActionType = "postback"
 	RichMenuActionTypeDatetimePicker RichMenuActionType = "datetimepicker"
+	RichMenuActionTypeRichMenuSwitch RichMenuActionType = "richmenuswitch"
 )
 
 // RichMenuSize type
@@ -51,16 +52,17 @@ type RichMenuBounds struct {
 
 // RichMenuAction with type
 type RichMenuAction struct {
-	Type        RichMenuActionType `json:"type"`
-	URI         string             `json:"uri,omitempty"`
-	Text        string             `json:"text,omitempty"`
-	DisplayText string             `json:"displayText,omitempty"`
-	Label       string             `json:"label,omitempty"`
-	Data        string             `json:"data,omitempty"`
-	Mode        string             `json:"mode,omitempty"`
-	Initial     string             `json:"initial,omitempty"`
-	Max         string             `json:"max,omitempty"`
-	Min         string             `json:"min,omitempty"`
+	Type            RichMenuActionType `json:"type"`
+	URI             string             `json:"uri,omitempty"`
+	Text            string             `json:"text,omitempty"`
+	DisplayText     string             `json:"displayText,omitempty"`
+	Label           string             `json:"label,omitempty"`
+	Data            string             `json:"data,omitempty"`
+	Mode            string             `json:"mode,omitempty"`
+	Initial         string             `json:"initial,omitempty"`
+	Max             string             `json:"max,omitempty"`
+	Min             string             `json:"min,omitempty"`
+	RichMenuAliasID string             `json:"richMenuAliasId,omitempty"`
 }
 
 // AreaDetail type for areas array


Test patch:
diff --git a/linebot/webhook_test.go b/linebot/webhook_test.go
index dc6b028..c46e29d 100644
--- a/linebot/webhook_test.go
+++ b/linebot/webhook_test.go
@@ -292,6 +292,23 @@ var webhookTestRequestBody = `{
 				}
             }
         },
+        {
+            "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
+            "type": "postback",
+            "mode": "active",
+            "timestamp": 1462629479859,
+            "source": {
+                "type": "user",
+                "userId": "u206d25c2ea6bd87c17655609a1c37cb8"
+            },
+            "postback": {
+                "data": "action=richmenu-changed-to-a",
+								"params": {
+									"newRichMenuAliasId": "richmenu-alias-a",
+									"status": "SUCCESS"
+								}
+            }
+        },
         {
             "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
             "type": "beacon",
@@ -790,6 +807,23 @@ var webhookTestWantEvents = []*Event{
 			},
 		},
 	},
+	{
+		ReplyToken: "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
+		Type:       EventTypePostback,
+		Mode:       EventModeActive,
+		Timestamp:  time.Date(2016, time.May, 7, 13, 57, 59, int(859*time.Millisecond), time.UTC),
+		Source: &EventSource{
+			Type:   EventSourceTypeUser,
+			UserID: "u206d25c2ea6bd87c17655609a1c37cb8",
+		},
+		Postback: &Postback{
+			Data: "action=richmenu-changed-to-a",
+			Params: &Params{
+				NewRichMenuAliasID: "richmenu-alias-a",
+				Status:             "SUCCESS",
+			},
+		},
+	},
 	{
 		ReplyToken: "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
 		Type:       EventTypeBeacon,