Skip to content

Commit

Permalink
Merge pull request #286 from gotokatsuya/patch/richmenuaction
Browse files Browse the repository at this point in the history
Fix #285 Support rich menu switch action
  • Loading branch information
kkdai authored Jul 17, 2021
2 parents 81a4a47 + 5b3a012 commit 369271e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 17 deletions.
24 changes: 20 additions & 4 deletions examples/richmenu_helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,45 @@ 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/",
Text: "click me",
},
},
{
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!",
Expand Down
8 changes: 5 additions & 3 deletions linebot/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions linebot/richmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
RichMenuActionTypeMessage RichMenuActionType = "message"
RichMenuActionTypePostback RichMenuActionType = "postback"
RichMenuActionTypeDatetimePicker RichMenuActionType = "datetimepicker"
RichMenuActionTypeRichMenuSwitch RichMenuActionType = "richmenuswitch"
)

// RichMenuSize type
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions linebot/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 369271e

Please sign in to comment.