diff --git a/lib/line/bot/v2/webhook/.openapi-generator/FILES b/lib/line/bot/v2/webhook/.openapi-generator/FILES index 841acee2..84426df5 100644 --- a/lib/line/bot/v2/webhook/.openapi-generator/FILES +++ b/lib/line/bot/v2/webhook/.openapi-generator/FILES @@ -40,6 +40,7 @@ model/membership_event.rb model/mention.rb model/mentionee.rb model/message_content.rb +model/message_edited_event.rb model/message_event.rb model/module_content.rb model/module_event.rb diff --git a/lib/line/bot/v2/webhook/core.rb b/lib/line/bot/v2/webhook/core.rb index 3d91678a..cf44b05d 100644 --- a/lib/line/bot/v2/webhook/core.rb +++ b/lib/line/bot/v2/webhook/core.rb @@ -48,6 +48,7 @@ require_relative './model/mention' require_relative './model/mentionee' require_relative './model/message_content' +require_relative './model/message_edited_event' require_relative './model/message_event' require_relative './model/module_content' require_relative './model/module_event' diff --git a/lib/line/bot/v2/webhook/model/event.rb b/lib/line/bot/v2/webhook/model/event.rb index 283df2f8..3cf1d531 100644 --- a/lib/line/bot/v2/webhook/model/event.rb +++ b/lib/line/bot/v2/webhook/model/event.rb @@ -109,6 +109,7 @@ def self.detect_class(type:) memberJoined: Line::Bot::V2::Webhook::MemberJoinedEvent, memberLeft: Line::Bot::V2::Webhook::MemberLeftEvent, membership: Line::Bot::V2::Webhook::MembershipEvent, + messageEdited: Line::Bot::V2::Webhook::MessageEditedEvent, message: Line::Bot::V2::Webhook::MessageEvent, module: Line::Bot::V2::Webhook::ModuleEvent, delivery: Line::Bot::V2::Webhook::PnpDeliveryCompletionEvent, diff --git a/lib/line/bot/v2/webhook/model/message_edited_event.rb b/lib/line/bot/v2/webhook/model/message_edited_event.rb new file mode 100644 index 00000000..46b97469 --- /dev/null +++ b/lib/line/bot/v2/webhook/model/message_edited_event.rb @@ -0,0 +1,110 @@ +# Webhook Type Definition +# Webhook event definition of the LINE Messaging API +# +# The version of the OpenAPI document: 1.0.0 +# +# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). +# https://openapi-generator.tech +# Do not edit the class manually. + +require_relative './event' + +module Line + module Bot + module V2 + module Webhook + # Webhook event object which contains the edited message. This event is triggered when a user edits a text message. Currently, message editing is not available in one-on-one chats with LINE Official Accounts, so this event is only triggered in group chats. Multiple messageEdited webhook events may arrive out of order. The event with the largest timestamp represents the latest edit state. + # @see https://developers.line.biz/en/reference/messaging-api/#edit-event + class MessageEditedEvent < Event + # @!attribute [r] type + # @return [String] Type of the event + attr_reader :type + # @!attribute [rw] source + # @return [Source,nil] + attr_accessor :source + # @!attribute [rw] timestamp + # @return [Integer] Time of the event in milliseconds. + attr_accessor :timestamp + # @!attribute [rw] mode + # @return [String] ('active'|'standby') + attr_accessor :mode + # @!attribute [rw] webhook_event_id + # @return [String] Webhook Event ID. An ID that uniquely identifies a webhook event. This is a string in ULID format. + attr_accessor :webhook_event_id + # @!attribute [rw] delivery_context + # @return [DeliveryContext] + attr_accessor :delivery_context + # @!attribute [rw] reply_token + # @return [String,nil] + attr_accessor :reply_token + # @!attribute [rw] message + # @return [MessageContent] + attr_accessor :message + + # @param source [Source, Hash[Symbol, untyped], nil] + # @param timestamp [Integer] Time of the event in milliseconds. + # @param mode [String] ('active'|'standby') + # @param webhook_event_id [String] Webhook Event ID. An ID that uniquely identifies a webhook event. This is a string in ULID format. + # @param delivery_context [DeliveryContext, Hash[Symbol, untyped]] + # @param reply_token [String,nil] + # @param message [MessageContent, Hash[Symbol, untyped]] + def initialize( + source: nil, + timestamp:, + mode:, + webhook_event_id:, + delivery_context:, + reply_token: nil, + message:, + **dynamic_attributes + ) + @type = "messageEdited" + + @source = source.is_a?(Line::Bot::V2::Webhook::Source) || source.nil? ? source : Line::Bot::V2::Webhook::Source.create(**source) + @timestamp = timestamp + @mode = mode + @webhook_event_id = webhook_event_id + @delivery_context = delivery_context.is_a?(Line::Bot::V2::Webhook::DeliveryContext) ? delivery_context : Line::Bot::V2::Webhook::DeliveryContext.create(**delivery_context) + @reply_token = reply_token + @message = message.is_a?(Line::Bot::V2::Webhook::MessageContent) ? message : Line::Bot::V2::Webhook::MessageContent.create(**message) + + dynamic_attributes.each do |key, value| + self.class.attr_accessor key + + if value.is_a?(Hash) + struct_klass = Struct.new(*value.keys.map(&:to_sym)) + struct_values = value.map { |_k, v| v.is_a?(Hash) ? Line::Bot::V2::Utils.hash_to_struct(v) : v } + instance_variable_set("@#{key}", struct_klass.new(*struct_values)) + else + instance_variable_set("@#{key}", value) + end + end + end + + # Create an instance of the class from a hash + # @param args [Hash] Hash containing all the required attributes + # @return [Line::Bot::V2::Webhook::MessageEditedEvent] Instance of the class + def self.create(args) + symbolized_args = Line::Bot::V2::Utils.deep_symbolize(args) + return new(**symbolized_args) # steep:ignore InsufficientKeywordArguments + end + + # @param other [Object] Object to compare + # @return [Boolean] true if the objects are equal, false otherwise + def ==(other) + return false unless self.class == other.class + + instance_variables.all? do |var| + instance_variable_get(var) == other.instance_variable_get(var) + end + end + + # @return [Integer] Hash code of the object + def hash + [self.class, *instance_variables.map { |var| instance_variable_get(var) }].hash + end + end + end + end + end +end diff --git a/line-openapi b/line-openapi index 6e4c2a2a..99df56b7 160000 --- a/line-openapi +++ b/line-openapi @@ -1 +1 @@ -Subproject commit 6e4c2a2a1b7b059ea3920456d4f88d03fd8ef0bb +Subproject commit 99df56b76bf1b8a8268456fa36c2d1538b4c086c diff --git a/sig/line/bot/v2/webhook/.openapi-generator/FILES b/sig/line/bot/v2/webhook/.openapi-generator/FILES index 00f494d1..f1e11a82 100644 --- a/sig/line/bot/v2/webhook/.openapi-generator/FILES +++ b/sig/line/bot/v2/webhook/.openapi-generator/FILES @@ -39,6 +39,7 @@ model/membership_event.rbs model/mention.rbs model/mentionee.rbs model/message_content.rbs +model/message_edited_event.rbs model/message_event.rbs model/module_content.rbs model/module_event.rbs diff --git a/sig/line/bot/v2/webhook/model/message_edited_event.rbs b/sig/line/bot/v2/webhook/model/message_edited_event.rbs new file mode 100644 index 00000000..4a978a26 --- /dev/null +++ b/sig/line/bot/v2/webhook/model/message_edited_event.rbs @@ -0,0 +1,60 @@ +# Webhook Type Definition +# Webhook event definition of the LINE Messaging API +# +# The version of the OpenAPI document: 1.0.0 +# +# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). +# https://openapi-generator.tech +# Do not edit the class manually. + +module Line + module Bot + module V2 + module Webhook + # Webhook event object which contains the edited message. This event is triggered when a user edits a text message. Currently, message editing is not available in one-on-one chats with LINE Official Accounts, so this event is only triggered in group chats. Multiple messageEdited webhook events may arrive out of order. The event with the largest timestamp represents the latest edit state. + # @see https://developers.line.biz/en/reference/messaging-api/#edit-event + class MessageEditedEvent < Event + attr_reader type: String + attr_accessor source: Source? + attr_accessor timestamp: Integer + attr_accessor mode: 'active'|'standby' + attr_accessor webhook_event_id: String + attr_accessor delivery_context: DeliveryContext + attr_accessor reply_token: String? + attr_accessor message: MessageContent + + + # @param source [Source, Hash[Symbol, untyped], nil] + # @param timestamp [Integer] Time of the event in milliseconds. + # @param mode [String] ('active'|'standby') + # @param webhook_event_id [String] Webhook Event ID. An ID that uniquely identifies a webhook event. This is a string in ULID format. + # @param delivery_context [DeliveryContext, Hash[Symbol, untyped]] + # @param reply_token [String,nil] + # @param message [MessageContent, Hash[Symbol, untyped]] + def initialize: ( + ?source: Source?| Hash[Symbol, untyped]?, + timestamp: Integer, + mode: 'active'|'standby', + webhook_event_id: String, + delivery_context: DeliveryContext| Hash[Symbol, untyped], + ?reply_token: String?, + message: MessageContent| Hash[Symbol, untyped], + **untyped dynamic_attributes + ) -> void + + # Create an instance of the class from a hash + # @param args [Hash] Hash containing all the required attributes + # @return [Line::Bot::V2::Webhook::MessageEditedEvent] Instance of the class + def self.create: (Hash[Symbol, untyped]) -> MessageEditedEvent + + # @param other [Object] Object to compare + # @return [Boolean] true if the objects are equal, false otherwise + def ==: (untyped other) -> bool + + # @return [Integer] Hash code of the object + def hash: () -> Integer + end + end + end + end +end diff --git a/spec/line/bot/v2/webhook/parser_spec.rb b/spec/line/bot/v2/webhook/parser_spec.rb index abf9b5d1..5c02b1dd 100644 --- a/spec/line/bot/v2/webhook/parser_spec.rb +++ b/spec/line/bot/v2/webhook/parser_spec.rb @@ -1770,6 +1770,63 @@ end end + context 'with a MessageEditedEvent' do + let(:webhook) do + <<~JSON + { + "destination": "xxxxxxxxxx", + "events": [ + { + "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", + "type": "messageEdited", + "mode": "active", + "timestamp": 1462629479859, + "source": { + "type": "group", + "groupId": "Ca56f94637c...", + "userId": "U4af4980629..." + }, + "webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR", + "deliveryContext": { + "isRedelivery": false + }, + "message": { + "id": "444573844083572737", + "type": "text", + "quoteToken": "q3Plxr4AgKd...", + "text": "Hello, world! (edited)" + } + } + ] + } + JSON + end + + it 'parses the webhook as a MessageEditedEvent' do + events = parser.parse(body: webhook, signature: signature) + expect(events).not_to be_empty + + event = events.first + expect(event).to be_a(Line::Bot::V2::Webhook::MessageEditedEvent) + expect(event.reply_token).to eq('nHuyWiB7yP5Zw52FIkcQobQuGDXCTA') + expect(event.type).to eq('messageEdited') + expect(event.mode).to eq('active') + expect(event.timestamp).to eq(1462629479859) + expect(event.source).to be_a(Line::Bot::V2::Webhook::GroupSource) + expect(event.source.type).to eq('group') + expect(event.source.group_id).to eq('Ca56f94637c...') + expect(event.source.user_id).to eq('U4af4980629...') + expect(event.webhook_event_id).to eq('01FZ74A0TDDPYRVKNK77XKC3ZR') + expect(event.delivery_context).to be_a(Line::Bot::V2::Webhook::DeliveryContext) + expect(event.delivery_context.is_redelivery).to be false + expect(event.message).to be_a(Line::Bot::V2::Webhook::TextMessageContent) + expect(event.message.id).to eq('444573844083572737') + expect(event.message.type).to eq('text') + expect(event.message.quote_token).to eq('q3Plxr4AgKd...') + expect(event.message.text).to eq('Hello, world! (edited)') + end + end + context 'with a MembershioEvent' do let(:webhook) do <<~JSON