Skip to content

Commit d3c885b

Browse files
github-actions[bot]github-actions
andauthored
Support mark as read by token API (#697)
line/line-openapi#115 ## Support for "Mark as Read" by Token API We have released a new **Mark as Read API** that allows developers to mark a user’s messages as read. Previously, this functionality was available only to partners, but it is now publicly available. When your server receives a user message via Webhook, the `MessageEvent` will include a new field: `markAsReadToken`. By calling the Mark as Read API with this token, all messages in the chat room **up to and including** that message will be marked as read. > **Note:** This feature assumes that your service uses the chat feature through Official Account Manager. > If chat is not enabled, messages from users are automatically marked as read, making this API unnecessary. For more details, please refer to the release note: https://developers.line.biz/en/news/2025/11/05/mark-as-read/ Co-authored-by: github-actions <[email protected]>
1 parent bb0914f commit d3c885b

22 files changed

+264
-4
lines changed

lib/line/bot/v2/messaging_api/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ model/location_action.rb
120120
model/location_message.rb
121121
model/lottery_acquisition_condition_request.rb
122122
model/lottery_acquisition_condition_response.rb
123+
model/mark_messages_as_read_by_token_request.rb
123124
model/mark_messages_as_read_request.rb
124125
model/members_ids_response.rb
125126
model/membership.rb

lib/line/bot/v2/messaging_api/api/messaging_api_client.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,59 @@ def mark_messages_as_read(
25272527
response_body
25282528
end
25292529

2530+
# Mark messages from users as read by token
2531+
# This requests to <code>POST https://api.line.me/v2/bot/chat/markAsRead</code>
2532+
# This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
2533+
#
2534+
# @param mark_messages_as_read_by_token_request [MarkMessagesAsReadByTokenRequest]
2535+
# @see https://developers.line.biz/en/reference/messaging-api/#mark-as-read
2536+
# @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 200
2537+
# @return [Array(Line::Bot::V2::MessagingApi::ErrorResponse, Integer, Hash{String => String})] when HTTP status code is 400
2538+
# @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
2539+
def mark_messages_as_read_by_token_with_http_info( # steep:ignore MethodBodyTypeMismatch
2540+
mark_messages_as_read_by_token_request:
2541+
)
2542+
path = "/v2/bot/chat/markAsRead"
2543+
2544+
response = @http_client.post(
2545+
path: path,
2546+
body_params: mark_messages_as_read_by_token_request,
2547+
)
2548+
2549+
case response.code.to_i
2550+
when 200
2551+
[response.body, 200, response.each_header.to_h]
2552+
when 400
2553+
json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
2554+
json.transform_keys! do |key|
2555+
Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
2556+
end
2557+
response_body = Line::Bot::V2::MessagingApi::ErrorResponse.create(json) # steep:ignore InsufficientKeywordArguments
2558+
[response_body, 400, response.each_header.to_h]
2559+
else
2560+
[response.body, response.code.to_i, response.each_header.to_h]
2561+
end
2562+
end
2563+
2564+
# Mark messages from users as read by token
2565+
# This requests to <code>POST https://api.line.me/v2/bot/chat/markAsRead</code>
2566+
# When you want to get HTTP status code or response headers, use {#mark_messages_as_read_by_token_with_http_info} instead of this.
2567+
#
2568+
# @param mark_messages_as_read_by_token_request [MarkMessagesAsReadByTokenRequest]
2569+
# @see https://developers.line.biz/en/reference/messaging-api/#mark-as-read
2570+
# @return [String, nil] when HTTP status code is 200
2571+
# @return [Line::Bot::V2::MessagingApi::ErrorResponse] when HTTP status code is 400
2572+
# @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
2573+
def mark_messages_as_read_by_token(
2574+
mark_messages_as_read_by_token_request:
2575+
)
2576+
response_body, _status_code, _headers = mark_messages_as_read_by_token_with_http_info(
2577+
mark_messages_as_read_by_token_request: mark_messages_as_read_by_token_request
2578+
)
2579+
2580+
response_body
2581+
end
2582+
25302583
# An API that efficiently sends the same message to multiple user IDs. You can't send messages to group chats or multi-person chats.
25312584
# This requests to <code>POST https://api.line.me/v2/bot/message/multicast</code>
25322585
# This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

lib/line/bot/v2/messaging_api/core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
require_relative './model/location_message'
128128
require_relative './model/lottery_acquisition_condition_request'
129129
require_relative './model/lottery_acquisition_condition_response'
130+
require_relative './model/mark_messages_as_read_by_token_request'
130131
require_relative './model/mark_messages_as_read_request'
131132
require_relative './model/members_ids_response'
132133
require_relative './model/membership'
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# LINE Messaging API
2+
# This document describes LINE Messaging API.
3+
#
4+
# The version of the OpenAPI document: 0.0.1
5+
#
6+
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
7+
# https://openapi-generator.tech
8+
# Do not edit the class manually.
9+
10+
module Line
11+
module Bot
12+
module V2
13+
module MessagingApi
14+
# @see https://developers.line.biz/en/reference/messaging-api/#mark-as-read-request-body
15+
class MarkMessagesAsReadByTokenRequest
16+
# @!attribute [rw] mark_as_read_token
17+
# @return [String] Token used to mark messages as read.
18+
attr_accessor :mark_as_read_token
19+
20+
# @param mark_as_read_token [String] Token used to mark messages as read.
21+
def initialize(
22+
mark_as_read_token:,
23+
**dynamic_attributes
24+
)
25+
26+
@mark_as_read_token = mark_as_read_token
27+
28+
dynamic_attributes.each do |key, value|
29+
self.class.attr_accessor key
30+
31+
if value.is_a?(Hash)
32+
struct_klass = Struct.new(*value.keys.map(&:to_sym))
33+
struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v }
34+
instance_variable_set("@#{key}", struct_klass.new(*struct_values))
35+
else
36+
instance_variable_set("@#{key}", value)
37+
end
38+
end
39+
end
40+
41+
# Create an instance of the class from a hash
42+
# @param args [Hash] Hash containing all the required attributes
43+
# @return [Line::Bot::V2::MessagingApi::MarkMessagesAsReadByTokenRequest] Instance of the class
44+
def self.create(args) # steep:ignore
45+
symbolized_args = Line::Bot::V2::Utils.deep_symbolize(args)
46+
return new(**symbolized_args) # steep:ignore
47+
end
48+
49+
# @param other [Object] Object to compare
50+
# @return [Boolean] true if the objects are equal, false otherwise
51+
def ==(other)
52+
return false unless self.class == other.class
53+
54+
instance_variables.all? do |var|
55+
instance_variable_get(var) == other.instance_variable_get(var)
56+
end
57+
end
58+
59+
# @return [Integer] Hash code of the object
60+
def hash
61+
[self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash
62+
end
63+
end
64+
end
65+
end
66+
end
67+
end

lib/line/bot/v2/webhook/model/audio_message_content.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,27 @@ class AudioMessageContent < MessageContent
2626
# @!attribute [rw] duration
2727
# @return [Integer,nil] Length of audio file (milliseconds)
2828
attr_accessor :duration
29+
# @!attribute [rw] mark_as_read_token
30+
# @return [String,nil] Token used to mark the message as read.
31+
attr_accessor :mark_as_read_token
2932

3033
# @param id [String] Message ID
3134
# @param content_provider [ContentProvider, Hash[Symbol, untyped]]
3235
# @param duration [Integer,nil] Length of audio file (milliseconds)
36+
# @param mark_as_read_token [String,nil] Token used to mark the message as read.
3337
def initialize(
3438
id:,
3539
content_provider:,
3640
duration: nil,
41+
mark_as_read_token: nil,
3742
**dynamic_attributes
3843
)
3944
@type = "audio"
4045

4146
@id = id
4247
@content_provider = content_provider.is_a?(Line::Bot::V2::Webhook::ContentProvider) ? content_provider : Line::Bot::V2::Webhook::ContentProvider.create(**content_provider) # steep:ignore
4348
@duration = duration
49+
@mark_as_read_token = mark_as_read_token
4450

4551
dynamic_attributes.each do |key, value|
4652
self.class.attr_accessor key

lib/line/bot/v2/webhook/model/file_message_content.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,27 @@ class FileMessageContent < MessageContent
2626
# @!attribute [rw] file_size
2727
# @return [Integer] File size in bytes
2828
attr_accessor :file_size
29+
# @!attribute [rw] mark_as_read_token
30+
# @return [String,nil] Token used to mark the message as read.
31+
attr_accessor :mark_as_read_token
2932

3033
# @param id [String] Message ID
3134
# @param file_name [String] File name
3235
# @param file_size [Integer] File size in bytes
36+
# @param mark_as_read_token [String,nil] Token used to mark the message as read.
3337
def initialize(
3438
id:,
3539
file_name:,
3640
file_size:,
41+
mark_as_read_token: nil,
3742
**dynamic_attributes
3843
)
3944
@type = "file"
4045

4146
@id = id
4247
@file_name = file_name
4348
@file_size = file_size
49+
@mark_as_read_token = mark_as_read_token
4450

4551
dynamic_attributes.each do |key, value|
4652
self.class.attr_accessor key

lib/line/bot/v2/webhook/model/image_message_content.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ class ImageMessageContent < MessageContent
2929
# @!attribute [rw] quote_token
3030
# @return [String] Quote token to quote this message.
3131
attr_accessor :quote_token
32+
# @!attribute [rw] mark_as_read_token
33+
# @return [String,nil] Token used to mark the message as read.
34+
attr_accessor :mark_as_read_token
3235

3336
# @param id [String] Message ID
3437
# @param content_provider [ContentProvider, Hash[Symbol, untyped]]
3538
# @param image_set [ImageSet, Hash[Symbol, untyped], nil]
3639
# @param quote_token [String] Quote token to quote this message.
40+
# @param mark_as_read_token [String,nil] Token used to mark the message as read.
3741
def initialize(
3842
id:,
3943
content_provider:,
4044
image_set: nil,
4145
quote_token:,
46+
mark_as_read_token: nil,
4247
**dynamic_attributes
4348
)
4449
@type = "image"
@@ -47,6 +52,7 @@ def initialize(
4752
@content_provider = content_provider.is_a?(Line::Bot::V2::Webhook::ContentProvider) ? content_provider : Line::Bot::V2::Webhook::ContentProvider.create(**content_provider) # steep:ignore
4853
@image_set = image_set.is_a?(Line::Bot::V2::Webhook::ImageSet) || image_set.nil? ? image_set : Line::Bot::V2::Webhook::ImageSet.create(**image_set) # steep:ignore
4954
@quote_token = quote_token
55+
@mark_as_read_token = mark_as_read_token
5056

5157
dynamic_attributes.each do |key, value|
5258
self.class.attr_accessor key

lib/line/bot/v2/webhook/model/location_message_content.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,23 @@ class LocationMessageContent < MessageContent
3232
# @!attribute [rw] longitude
3333
# @return [Float] Longitude
3434
attr_accessor :longitude
35+
# @!attribute [rw] mark_as_read_token
36+
# @return [String,nil] Token used to mark the message as read.
37+
attr_accessor :mark_as_read_token
3538

3639
# @param id [String] Message ID
3740
# @param title [String,nil] Title
3841
# @param address [String,nil] Address
3942
# @param latitude [Float] Latitude
4043
# @param longitude [Float] Longitude
44+
# @param mark_as_read_token [String,nil] Token used to mark the message as read.
4145
def initialize(
4246
id:,
4347
title: nil,
4448
address: nil,
4549
latitude:,
4650
longitude:,
51+
mark_as_read_token: nil,
4752
**dynamic_attributes
4853
)
4954
@type = "location"
@@ -53,6 +58,7 @@ def initialize(
5358
@address = address
5459
@latitude = latitude
5560
@longitude = longitude
61+
@mark_as_read_token = mark_as_read_token
5662

5763
dynamic_attributes.each do |key, value|
5864
self.class.attr_accessor key

lib/line/bot/v2/webhook/model/sticker_message_content.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ class StickerMessageContent < MessageContent
4040
# @return [String] Quote token to quote this message.
4141
attr_accessor :quote_token
4242
# @!attribute [rw] quoted_message_id
43-
# @return [String,nil] Message ID of a quoted message. Only included when the received message quotes a past message.
43+
# @return [String,nil] Message ID of a quoted message. Only included when the received message quotes a past message.
4444
attr_accessor :quoted_message_id
45+
# @!attribute [rw] mark_as_read_token
46+
# @return [String,nil] Token used to mark the message as read.
47+
attr_accessor :mark_as_read_token
4548

4649
# @param id [String] Message ID
4750
# @param package_id [String] Package ID
@@ -50,7 +53,8 @@ class StickerMessageContent < MessageContent
5053
# @param keywords [Array[String],nil] Array of up to 15 keywords describing the sticker. If a sticker has 16 or more keywords, a random selection of 15 keywords will be returned. The keyword selection is random for each event, so different keywords may be returned for the same sticker.
5154
# @param text [String,nil] Any text entered by the user. This property is only included for message stickers. Max character limit: 100
5255
# @param quote_token [String] Quote token to quote this message.
53-
# @param quoted_message_id [String,nil] Message ID of a quoted message. Only included when the received message quotes a past message.
56+
# @param quoted_message_id [String,nil] Message ID of a quoted message. Only included when the received message quotes a past message.
57+
# @param mark_as_read_token [String,nil] Token used to mark the message as read.
5458
def initialize(
5559
id:,
5660
package_id:,
@@ -60,6 +64,7 @@ def initialize(
6064
text: nil,
6165
quote_token:,
6266
quoted_message_id: nil,
67+
mark_as_read_token: nil,
6368
**dynamic_attributes
6469
)
6570
@type = "sticker"
@@ -72,6 +77,7 @@ def initialize(
7277
@text = text
7378
@quote_token = quote_token
7479
@quoted_message_id = quoted_message_id
80+
@mark_as_read_token = mark_as_read_token
7581

7682
dynamic_attributes.each do |key, value|
7783
self.class.attr_accessor key

lib/line/bot/v2/webhook/model/text_message_content.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ class TextMessageContent < MessageContent
3535
# @!attribute [rw] quoted_message_id
3636
# @return [String,nil] Message ID of a quoted message. Only included when the received message quotes a past message.
3737
attr_accessor :quoted_message_id
38+
# @!attribute [rw] mark_as_read_token
39+
# @return [String,nil] Token used to mark the message as read.
40+
attr_accessor :mark_as_read_token
3841

3942
# @param id [String] Message ID
4043
# @param text [String] Message text.
4144
# @param emojis [Array[Emoji, Hash[Symbol, untyped]],nil] Array of one or more LINE emoji objects. Only included in the message event when the text property contains a LINE emoji.
4245
# @param mention [Mention, Hash[Symbol, untyped], nil]
4346
# @param quote_token [String] Quote token to quote this message.
4447
# @param quoted_message_id [String,nil] Message ID of a quoted message. Only included when the received message quotes a past message.
48+
# @param mark_as_read_token [String,nil] Token used to mark the message as read.
4549
def initialize(
4650
id:,
4751
text:,
4852
emojis: nil,
4953
mention: nil,
5054
quote_token:,
5155
quoted_message_id: nil,
56+
mark_as_read_token: nil,
5257
**dynamic_attributes
5358
)
5459
@type = "text"
@@ -65,6 +70,7 @@ def initialize(
6570
@mention = mention.is_a?(Line::Bot::V2::Webhook::Mention) || mention.nil? ? mention : Line::Bot::V2::Webhook::Mention.create(**mention) # steep:ignore
6671
@quote_token = quote_token
6772
@quoted_message_id = quoted_message_id
73+
@mark_as_read_token = mark_as_read_token
6874

6975
dynamic_attributes.each do |key, value|
7076
self.class.attr_accessor key

0 commit comments

Comments
 (0)