Class RichMenuClient
Facade for the Rich Menu use case. Rich Menu spans both Messaging hosts — control operations
on api.line.me and image upload/download on api-data.line.me — so this facade
wraps a MessagingClient (which already solves the host split / BaseUrl handling)
and exposes the common create → image → set-default → link flow through thin convenience
methods.
The generated builders remain available via Messaging (.Api for control,
.Blob for image data plane) for the less common operations (alias CRUD, bulk link/unlink,
batch) that are intentionally not surfaced here.
The image helpers are the main ergonomic value: SetImageFromFileAsync(string, string, CancellationToken) infers the
required image/png / image/jpeg content type from the file extension, which LINE
mandates for the upload (the generated builder requires it as an explicit argument).
Usage: var rich = RichMenuClient.CreateWithStaticToken("CHANNEL_ACCESS_TOKEN"); var id = await rich.CreateAsync(new RichMenuRequest { /* ... */ }); await rich.SetImageFromFileAsync(id!, "menu.png"); await rich.SetDefaultAsync(id!);
public sealed class RichMenuClient
- Inheritance
-
RichMenuClient
- Inherited Members
Constructors
RichMenuClient(MessagingClient)
Wraps an existing MessagingClient.
public RichMenuClient(MessagingClient messaging)
Parameters
messagingMessagingClient
RichMenuClient(IAuthenticationProvider, HttpClient?)
public RichMenuClient(IAuthenticationProvider authProvider, HttpClient? httpClient = null)
Parameters
authProviderIAuthenticationProviderAuthentication provider (static or refreshing, either works).
httpClientHttpClientThe HttpClient shared by the adapters. Supplied by
IHttpClientFactoryvia DI. When null, a default HttpClient is created (for quick use).
Properties
Messaging
The underlying Messaging client (exposed for low-level operations: alias / bulk / batch).
public MessagingClient Messaging { get; }
Property Value
Methods
CancelDefaultAsync(CancellationToken)
Cancels the default rich menu (DELETE /v2/bot/user/all/richmenu).
public Task CancelDefaultAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
CreateWithStaticToken(string)
Helper to quickly construct from a long-lived channel access token.
public static RichMenuClient CreateWithStaticToken(string channelAccessToken)
Parameters
channelAccessTokenstring
Returns
DeleteAsync(string, CancellationToken)
Deletes a rich menu (DELETE /v2/bot/richmenu/{richMenuId}).
public Task DeleteAsync(string richMenuId, CancellationToken cancellationToken = default)
Parameters
richMenuIdstringcancellationTokenCancellationToken
Returns
GetAsync(string, CancellationToken)
Gets a rich menu by id (GET /v2/bot/richmenu/{richMenuId}). Returns null if the id does not exist.
public Task<RichMenuResponse?> GetAsync(string richMenuId, CancellationToken cancellationToken = default)
Parameters
richMenuIdstringcancellationTokenCancellationToken
Returns
- Task<RichMenuResponse>
GetDefaultIdAsync(CancellationToken)
Gets the default rich menu id (GET /v2/bot/user/all/richmenu). Returns null if none is set (LINE returns 404).
public Task<string?> GetDefaultIdAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
GetIdOfUserAsync(string, CancellationToken)
Gets the rich menu id linked to a user (GET /v2/bot/user/{userId}/richmenu). Returns null if none (LINE returns 404).
public Task<string?> GetIdOfUserAsync(string userId, CancellationToken cancellationToken = default)
Parameters
userIdstringcancellationTokenCancellationToken
Returns
GetImageAsync(string, CancellationToken)
Downloads the rich menu image (GET /v2/bot/richmenu/{richMenuId}/content, data plane).
public Task<Stream?> GetImageAsync(string richMenuId, CancellationToken cancellationToken = default)
Parameters
richMenuIdstringcancellationTokenCancellationToken
Returns
InferImageContentType(string)
Maps a rich menu image file extension to its required content type.
public static string InferImageContentType(string filePath)
Parameters
filePathstring
Returns
LinkToUserAsync(string, string, CancellationToken)
Links a rich menu to a user (POST /v2/bot/user/{userId}/richmenu/{richMenuId}).
public Task LinkToUserAsync(string userId, string richMenuId, CancellationToken cancellationToken = default)
Parameters
userIdstringrichMenuIdstringcancellationTokenCancellationToken
Returns
ListAsync(CancellationToken)
Lists the channel's rich menus (GET /v2/bot/richmenu/list).
public Task<RichMenuListResponse?> ListAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
- Task<RichMenuListResponse>
SetDefaultAsync(string, CancellationToken)
Sets the default rich menu for all users (POST /v2/bot/user/all/richmenu/{richMenuId}).
public Task SetDefaultAsync(string richMenuId, CancellationToken cancellationToken = default)
Parameters
richMenuIdstringcancellationTokenCancellationToken
Returns
SetImageAsync(string, Stream, string, CancellationToken)
Uploads the rich menu image (POST /v2/bot/richmenu/{richMenuId}/content, data plane).
contentType must be image/png or image/jpeg.
public Task SetImageAsync(string richMenuId, Stream image, string contentType, CancellationToken cancellationToken = default)
Parameters
richMenuIdstringimageStreamcontentTypestringcancellationTokenCancellationToken
Returns
SetImageFromFileAsync(string, string, CancellationToken)
Uploads the rich menu image from a file, inferring the content type from the extension
(.png → image/png, .jpg/.jpeg → image/jpeg). Other extensions are rejected.
public Task SetImageFromFileAsync(string richMenuId, string filePath, CancellationToken cancellationToken = default)
Parameters
richMenuIdstringfilePathstringcancellationTokenCancellationToken
Returns
UnlinkFromUserAsync(string, CancellationToken)
Unlinks the rich menu from a user (DELETE /v2/bot/user/{userId}/richmenu).
public Task UnlinkFromUserAsync(string userId, CancellationToken cancellationToken = default)
Parameters
userIdstringcancellationTokenCancellationToken