Skip to content

Commit 5ead81a

Browse files
github-actions[bot]github-actions
andauthored
Support new Membership API and Webhook (#542)
line/line-openapi#86 # Support new Membership API and Webhook We have implemented and supported new API and Webhook about Membership. ## API to get a list of users who joined the membership You can obtain a list of user IDs for users who have joined the membership of your LINE Official Account by calling `client.getJoinedMembershipUsers(...)`. Documents: https://developers.line.biz/en/reference/messaging-api/#get-membership-user-ids ## Membership Webhook We have introduced new Webhook events `MembershipEvent` that indicates that a user has joined, left or renewed a membership of your LINE Official Account. Documents: https://developers.line.biz/en/reference/messaging-api/#membership-event ## For more details For more details, check out the announcement: https://developers.line.biz/en/news/2025/02/13/membership-api/ Co-authored-by: github-actions <[email protected]>
1 parent 3c283b7 commit 5ead81a

File tree

11 files changed

+609
-1
lines changed

11 files changed

+609
-1
lines changed

line-openapi

linebot/messaging_api/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ model_gender_demographic_filter.go
6363
model_get_aggregation_unit_name_list_response.go
6464
model_get_aggregation_unit_usage_response.go
6565
model_get_followers_response.go
66+
model_get_joined_membership_users_response.go
6667
model_get_membership_subscription_response.go
6768
model_get_message_content_transcoding_response.go
6869
model_get_webhook_endpoint_response.go

linebot/messaging_api/api_messaging_api.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,98 @@ func (client *MessagingApiAPI) GetGroupSummaryWithHttpInfo(
11331133

11341134
}
11351135

1136+
// GetJoinedMembershipUsers
1137+
//
1138+
// Get a list of user IDs who joined the membership.
1139+
// Parameters:
1140+
// membershipId Membership plan ID.
1141+
// start A continuation token to get next remaining membership user IDs. Returned only when there are remaining user IDs that weren't returned in the userIds property in the previous request. The continuation token expires in 24 hours (86,400 seconds).
1142+
// limit The max number of items to return for this API call. The value is set to 300 by default, but the max acceptable value is 1000.
1143+
1144+
// https://developers.line.biz/en/reference/messaging-api/#get-membership-user-ids
1145+
func (client *MessagingApiAPI) GetJoinedMembershipUsers(
1146+
1147+
membershipId int32,
1148+
1149+
start string,
1150+
1151+
limit int32,
1152+
1153+
) (*GetJoinedMembershipUsersResponse, error) {
1154+
_, body, error := client.GetJoinedMembershipUsersWithHttpInfo(
1155+
1156+
membershipId,
1157+
1158+
start,
1159+
1160+
limit,
1161+
)
1162+
return body, error
1163+
}
1164+
1165+
// GetJoinedMembershipUsers
1166+
// If you want to take advantage of the HTTPResponse object for status codes and headers, use this signature.
1167+
//
1168+
// Get a list of user IDs who joined the membership.
1169+
// Parameters:
1170+
// membershipId Membership plan ID.
1171+
// start A continuation token to get next remaining membership user IDs. Returned only when there are remaining user IDs that weren't returned in the userIds property in the previous request. The continuation token expires in 24 hours (86,400 seconds).
1172+
// limit The max number of items to return for this API call. The value is set to 300 by default, but the max acceptable value is 1000.
1173+
1174+
// https://developers.line.biz/en/reference/messaging-api/#get-membership-user-ids
1175+
func (client *MessagingApiAPI) GetJoinedMembershipUsersWithHttpInfo(
1176+
1177+
membershipId int32,
1178+
1179+
start string,
1180+
1181+
limit int32,
1182+
1183+
) (*http.Response, *GetJoinedMembershipUsersResponse, error) {
1184+
path := "/v2/bot/membership/{membershipId}/users/ids"
1185+
1186+
path = strings.Replace(path, "{membershipId}", strconv.FormatInt(int64(membershipId), 10), -1)
1187+
1188+
req, err := http.NewRequest(http.MethodGet, client.Url(path), nil)
1189+
if err != nil {
1190+
return nil, nil, err
1191+
}
1192+
1193+
query := url.Values{}
1194+
if start != "" {
1195+
query.Add("start", start)
1196+
}
1197+
query.Add("limit", strconv.FormatInt(int64(limit), 10))
1198+
1199+
req.URL.RawQuery = query.Encode()
1200+
1201+
res, err := client.Do(req)
1202+
1203+
if err != nil {
1204+
return res, nil, err
1205+
}
1206+
1207+
if res.StatusCode/100 != 2 {
1208+
bodyBytes, err := io.ReadAll(res.Body)
1209+
bodyReader := bytes.NewReader(bodyBytes)
1210+
if err != nil {
1211+
return res, nil, fmt.Errorf("failed to read response body: %w", err)
1212+
}
1213+
res.Body = io.NopCloser(bodyReader)
1214+
return res, nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, string(bodyBytes))
1215+
}
1216+
1217+
defer res.Body.Close()
1218+
1219+
decoder := json.NewDecoder(res.Body)
1220+
result := GetJoinedMembershipUsersResponse{}
1221+
if err := decoder.Decode(&result); err != nil {
1222+
return res, nil, fmt.Errorf("failed to decode JSON: %w", err)
1223+
}
1224+
return res, &result, nil
1225+
1226+
}
1227+
11361228
// GetMembershipList
11371229
//
11381230
// Get a list of memberships.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* LINE Messaging API
3+
* This document describes LINE Messaging API.
4+
*
5+
* The version of the OpenAPI document: 0.0.1
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
/**
14+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
15+
* https://openapi-generator.tech
16+
* Do not edit the class manually.
17+
*/
18+
19+
//go:generate python3 ../../generate-code.py
20+
package messaging_api
21+
22+
// GetJoinedMembershipUsersResponse
23+
// List of users who have joined the membership
24+
// https://developers.line.biz/en/reference/messaging-api/#get-membership-user-ids
25+
type GetJoinedMembershipUsersResponse struct {
26+
27+
/**
28+
* A list of user IDs who joined the membership. Users who have not agreed to the bot user agreement, are not following the bot, or are not active will be excluded. If there are no users in the membership, an empty list will be returned. (Required)
29+
*/
30+
UserIds []string `json:"userIds"`
31+
32+
/**
33+
* A continuation token to get next remaining membership user IDs. Returned only when there are remaining user IDs that weren&#39;t returned in the userIds property in the previous request. The continuation token expires in 24 hours (86,400 seconds).
34+
*/
35+
Next string `json:"next,omitempty"`
36+
}

linebot/webhook/.openapi-generator/FILES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ model_image_message_content.go
2525
model_image_set.go
2626
model_join_event.go
2727
model_joined_members.go
28+
model_joined_membership_content.go
2829
model_leave_event.go
2930
model_left_members.go
31+
model_left_membership_content.go
3032
model_link_content.go
3133
model_link_things_content.go
3234
model_location_message_content.go
3335
model_member_joined_event.go
3436
model_member_left_event.go
37+
model_membership_content.go
38+
model_membership_event.go
3539
model_mention.go
3640
model_mentionee.go
3741
model_message_content.go
@@ -42,6 +46,7 @@ model_pnp_delivery.go
4246
model_pnp_delivery_completion_event.go
4347
model_postback_content.go
4448
model_postback_event.go
49+
model_renewed_membership_content.go
4550
model_room_source.go
4651
model_scenario_result.go
4752
model_scenario_result_things_content.go

linebot/webhook/model_event.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ func setDiscriminatorPropertyEvent(r EventInterface) EventInterface {
164164
v.Type = "memberLeft"
165165
}
166166
return v
167+
case *MembershipEvent:
168+
if v.Type == "" {
169+
v.Type = "membership"
170+
}
171+
return v
172+
case MembershipEvent:
173+
if v.Type == "" {
174+
v.Type = "membership"
175+
}
176+
return v
167177
case *MessageEvent:
168178
if v.Type == "" {
169179
v.Type = "message"
@@ -347,6 +357,12 @@ func UnmarshalEvent(data []byte) (EventInterface, error) {
347357
return nil, fmt.Errorf("UnmarshalEvent: Cannot read memberLeft: %w", err)
348358
}
349359
return memberLeft, nil
360+
case "membership":
361+
var membership MembershipEvent
362+
if err := json.Unmarshal(data, &membership); err != nil {
363+
return nil, fmt.Errorf("UnmarshalEvent: Cannot read membership: %w", err)
364+
}
365+
return membership, nil
350366
case "message":
351367
var message MessageEvent
352368
if err := json.Unmarshal(data, &message); err != nil {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Webhook Type Definition
3+
* Webhook event definition of the LINE Messaging API
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
/**
14+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
15+
* https://openapi-generator.tech
16+
* Do not edit the class manually.
17+
*/
18+
19+
//go:generate python3 ../../generate-code.py
20+
package webhook
21+
22+
import (
23+
"encoding/json"
24+
)
25+
26+
// JoinedMembershipContent
27+
// JoinedMembershipContent
28+
29+
type JoinedMembershipContent struct {
30+
MembershipContent
31+
32+
/**
33+
* The ID of the membership that the user joined. This is defined for each membership. (Required)
34+
*/
35+
MembershipId int32 `json:"membershipId"`
36+
}
37+
38+
// MarshalJSON customizes the JSON serialization of the JoinedMembershipContent struct.
39+
func (r *JoinedMembershipContent) MarshalJSON() ([]byte, error) {
40+
41+
type Alias JoinedMembershipContent
42+
return json.Marshal(&struct {
43+
*Alias
44+
45+
Type string `json:"type"`
46+
}{
47+
Alias: (*Alias)(r),
48+
49+
Type: "joined",
50+
})
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Webhook Type Definition
3+
* Webhook event definition of the LINE Messaging API
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
/**
14+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
15+
* https://openapi-generator.tech
16+
* Do not edit the class manually.
17+
*/
18+
19+
//go:generate python3 ../../generate-code.py
20+
package webhook
21+
22+
import (
23+
"encoding/json"
24+
)
25+
26+
// LeftMembershipContent
27+
// LeftMembershipContent
28+
29+
type LeftMembershipContent struct {
30+
MembershipContent
31+
32+
/**
33+
* The ID of the membership that the user left. This is defined for each membership. (Required)
34+
*/
35+
MembershipId int32 `json:"membershipId"`
36+
}
37+
38+
// MarshalJSON customizes the JSON serialization of the LeftMembershipContent struct.
39+
func (r *LeftMembershipContent) MarshalJSON() ([]byte, error) {
40+
41+
type Alias LeftMembershipContent
42+
return json.Marshal(&struct {
43+
*Alias
44+
45+
Type string `json:"type"`
46+
}{
47+
Alias: (*Alias)(r),
48+
49+
Type: "left",
50+
})
51+
}

0 commit comments

Comments
 (0)