Skip to content

Releases: line/line-bot-sdk-ruby

v2.0.0 Support All Messaging API Features and RBS

12 May 09:58
6e5663f
Compare
Choose a tag to compare

Overview

v2.0.0 is a completely new version.

  • The previous code released up to v1.29.1 will be called "v1",
  • The new code released as v2.0.0 and later versions will be called "v2".

v2 has significant breaking changes because it's a completely new implementation with an entirely different interface.
As a result, any implementation based on the previous codebase will no longer function.

If you already use v1, please use the transitional version v1.30.0 and do the migration.
Migration guide: https://github.com/line/line-bot-sdk-ruby/releases/tag/v1.30.0

New users should always use v2.
And we strongly recommend migrating to v2.

Why you should use v2

Support All Messaging API Features

v2 now supports every API endpoints and Webhook event types that were previously unimplemented.
Future API additions will be rapidly integrated, ensuring your application always stays up-to-date with the latest features by using line-bot-api gem.

Because v2 is automatically generated from https://github.com/line/line-openapi, same with SDKs provided for other programming languages.

RBS Support for Enhanced Development Experience

v2 comes with RBS (Ruby Signature) support, enabling you to leverage type checking and other type-based development features for a more robust coding experience.

Examples

There are several examples available for v2 to assist you in your implementation.

Feedbacks & Contributions

We welcome feedback and contributions.

v1.30.0 Transitional release for v2

12 May 04:14
f8da531
Compare
Choose a tag to compare

Overview

v1.30.0 is a transitional version for v2.0.0.

  • The previous code released up to v1.29.1 will be called "v1",
  • The new code released as v2.0.0 and later versions will be called "v2".

v1.30.0 includes both the v1 and v2 codebases.

v2 has significant breaking changes because it's a completely new implementation with an entirely different interface.
As a result, any implementation based on the previous codebase will no longer function.

New users should always use v2.
And we strongly recommend migrating to v2.

Why you should use v2

Support All Messaging API Features

v2 now supports every API endpoints and Webhook event types that were previously unimplemented.
Future API additions will be rapidly integrated, ensuring your application always stays up-to-date with the latest features by using line-bot-api gem.

Because v2 is automatically generated from https://github.com/line/line-openapi, same with SDKs provided for other programming languages.

RBS Support for Enhanced Development Experience

v2 comes with RBS (Ruby Signature) support, enabling you to leverage type checking and other type-based development features for a more robust coding experience.

Migration Guide: From v1 to v2

Users can perform the migration step at their own pace. Follow these steps:

  1. Upgrade the line-bot-api gem to 1.30.0.
  2. Migrate v1 code to v2 code. All v1 code issues deprecation warnings, so please migrate until they are gone. Since v1.30.0 includes all v1 and v2 code, you don't have to replace everything at once. You can switch gradually.
  3. Once all code is switched, upgrade line-bot-api to 2.0.0 or above.

Change all v1 implementations to v2 implementations in v1.30.0

v1.30.0 includes both the v1 and v2 codebases.

When you use the v1 code in v1.30.0, you will see deprecation warnings such as:

[DEPRECATION] Line::Bot::Client#push_message is deprecated. Please use Line::Bot::V2::MessagingApi::ApiClient#push_message instead.

These warnings indicate which methods to use in the new v2 code.

Alternatively, the YARD documentation/comments also clearly indicate where to migrate.

# https://github.com/line/line-bot-sdk-ruby/blob/fb449ba19201a57c5f58dcd19ea67c5a53b0a0fe/lib/line/bot/v1/client.rb#L277-L288

# @deprecated
# This is deprecated.
# Please use {Line::Bot::V2::MessagingApi::ApiClient#push_message} instead.
#
# Push messages to a user using user_id.
#
# @param user_id [String] User Id
# @param messages [Hash, Array] Message Objects
# @param headers [Hash] HTTP Headers
# @param payload [Hash] Additional request body
# @return [Net::HTTPResponse]
def push_message(user_id, messages, headers: {}, payload: {})

Once v1 code usage is completely removed in v1.30.0, please switch to v2.0.0 >= version immediately.
Starting with v2.0.0, v1 code is not included.

Suppress deprecation warnings

You can suppress the deprecation warning by setting any value to ENV['SUPRESS_V1_DEPRECATION_WARNINGS'].

However, it's not recommended to always use it as it could lead to migration errors.

Clients

There are several types of API clients.
Depending on the classification of the API, there are several types of clients.

  • MassagingAPI.
  • ManageAudience
  • Inshight
  • ChannelAccessToken
  • Liff
  • Shop
    and so on.

In addition, the same MessagingApi is divided into ApiBlobClient for APIs that use https://api-data.line.me to upload and download files.

  • Line::Bot::V2::MessagingApi::ApiClient.
  • Line::Bot::V2::MessagingApi::ApiBlobClient.

These are planned to be integrated in the future, but this has not yet been accomplished.

Migration examples

Only typical examples are shown here.
Please refer to Examples in the next chapter for more examples.

Calling API

v1

client = Line::Bot::Client.new do |config|
  config.channel_token = ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
end

response = client.push_message(
  'U1234567890abcdef1234567890abcdef',
  [
    {
      type: 'text',
      text: 'Hello, this is a test message!'
    }
  ]
)

puts response.class # => Net::HTTPResponse

v2 (with class)

client = Line::Bot::V2::MessagingApi::ApiClient.new(
  channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
)

message = Line::Bot::V2::MessagingApi::TextMessage.new( # No need to pass `type: "text"`
  text: 'Hello, this is a test message!'
)

request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
  to: 'U1234567890abcdef1234567890abcdef',
  messages: [
    message
  ]
)

response, status_code, response_headers = client.push_message_with_http_info(
  push_message_request: request
)

puts response.class # => Line::Bot::V2::MessagingApi::PushMessageResponse

v2 (with Hash)

This is not a recommended way.
Please use one of the above methods if possible.

However, this method makes migration from v1 easier.

client = Line::Bot::V2::MessagingApi::ApiClient.new(
  channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
)

request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
  to: 'U1234567890abcdef1234567890abcdef',
  messages: [
    {
      type: 'text',
      text: 'Hello, this is a test message!'
    }
  ]
)

response, status_code, response_headers = client.push_message_with_http_info(
  push_message_request: request
)

puts response.class # => Line::Bot::V2::MessagingApi::PushMessageResponse

Handling Webhook

v1

require 'sinatra' 
require 'line/bot' 

def client
  @client ||= Line::Bot::Client.new { |config|
    config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
    config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
  }
end

post '/callback' do
  body = request.body.read

  signature = request.env['HTTP_X_LINE_SIGNATURE']
  unless client.validate_signature(body, signature)
    halt 400, {'Content-Type' => 'text/plain'}, 'Bad Request'
  end

  events = client.parse_events_from(body)

  events.each do |event|
    case event
    when Line::Bot::Event::Message
      case event.type
      when Line::Bot::Event::MessageType::Text
        message = {
          type: 'text',
          text: event.message['text']
        }
        client.reply_message(event['replyToken'], message)
      end
    end
  end

  "OK"
end

v2

require 'sinatra'
require 'line-bot-api'

set :environment, :production

def client
  @client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
    channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
  )
end

def parser
  @parser ||= Line::Bot::V2::WebhookParser.new(channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"))
end

post '/callback' do
  body = request.body.read
  signature = request.env['HTTP_X_LINE_SIGNATURE']

  begin
    events = parser.parse(body: body, signature: signature)
  rescue Line::Bot::V2::WebhookParser::InvalidSignatureError
    halt 400, { 'Content-Type' => 'text/plain' }, 'Bad Request'
  end

  events.each do |event|
    case event
    when Line::Bot::V2::Webhook::MessageEvent
      case event.message
      when Line::Bot::V2::Webhook::TextMessageContent
        message = event.message.text
        request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
          reply_token: event.reply_token,
          messages: [
            Line::Bot::V2::MessagingApi::TextMessage.new(text: message)
          ]
        )
        client.reply_message(reply_message_request: request)
      end
    end
  end

  "OK"
end

Examples

There are several examples available for v2 to assist you in your implementation.

Feedbacks & Contributions

We welcome feedback and contributions.

v1.29.1 Update dependencies

15 Nov 05:15
Compare
Choose a tag to compare

What's Changed

Library(line-bot-api) itself is not changed.

Dependency updates

  • chore(deps): update dependency rubocop to '~> 1.65.0' by @renovate in #330
  • chore(deps): update dependency rubocop to '~> 1.66.0' by @renovate in #331
  • chore(deps): update actions/checkout digest to eef6144 by @renovate in #334
  • chore(deps): update dependency rubocop to '~> 1.67.0' by @renovate in #335
  • chore(deps): update actions/checkout digest to 11bd719 by @renovate in #336
  • chore(deps): update dependency rubocop to '~> 1.68.0' by @renovate in #338

Other Changes

  • chore(deps): update dependency rubocop to '~> 1.49.0' by @renovate in #286
  • chore(deps): update dependency rubocop to '~> 1.50.0' by @renovate in #287
  • chore(deps): update dependency rubocop to '~> 1.51.0' by @renovate in #288
  • chore(deps): update dependency rubocop to '~> 1.52.0' by @renovate in #289
  • chore(deps): update dependency rubocop to '~> 1.53.0' by @renovate in #290
  • chore(deps): update dependency rubocop to '~> 1.54.0' by @renovate in #293
  • chore(deps): update dependency rubocop to '~> 1.55.0' by @renovate in #297
  • chore(deps): update actions/checkout action to v4 by @renovate in #300
  • chore(deps): update dependency rubocop to '~> 1.56.0' by @renovate in #298
  • chore(deps): update dependency rubocop to '~> 1.57.0' by @renovate in #305
  • chore(deps): update actions/checkout digest to b4ffde6 by @renovate in #303
  • Close stale issue automatically by @Yang-33 in #306
  • Enable merge queue by @Yang-33 in #307
  • Import release.yml to generate release note automatically based on label by @Yang-33 in #308
  • chore(deps): update actions/stale action to v9 by @renovate in #310
  • Drop Ruby 2.7 and support Ruby 3.2 & 3.3 by @Yang-33 in #313
  • chore(deps): update dependency rubocop to '~> 1.60.0' by @renovate in #309
  • Remove unnecessary urls from README by @Yang-33 in #315
  • chore(deps): update dependency rubocop to '~> 1.62.0' by @renovate in #316
  • Drop Ruby 3.0 support by @Yang-33 in #317
  • Delete unused travis-ci url from README.md by @Yang-33 in #318
  • chore(deps): update dependency rubocop to '~> 1.63.0' by @renovate in #319
  • chore(deps): update actions/checkout digest to 1d96c77 by @renovate in #321
  • chore(deps): update actions/checkout digest to 0ad4b8f by @renovate in #322
  • chore(deps): update actions/checkout digest to a5ac7e5 by @renovate in #324
  • chore(deps): update dependency rubocop to '~> 1.64.0' by @renovate in #325
  • feat: Support LINE notification messages API by @linhnv in #326
  • v1.29.0 by @zenizh in #327
  • chore(deps): update actions/checkout digest to 692973e by @renovate in #328
  • Update renovate.json by @Yang-33 in #329
  • Automate publish by @Yang-33 in #339

New Contributors

Full Changelog: v1.28.0...v1.29.1

Release v1.29.0

10 Jun 22:52
Compare
Choose a tag to compare

v1.29.0 (2024-06-10)

Full Changelog

Closed issues:

  • Write supported ruby version explicitly #311
  • Bug Report #291

Merged pull requests:

Release v1.28.0

14 Mar 03:58
43e6102
Compare
Choose a tag to compare

v1.28.0 (2023-03-14)

Full Changelog

Merged pull requests:

Release v1.27.0

08 Feb 05:25
7beb5bc
Compare
Choose a tag to compare

v1.27.0 (2023-02-08)

Full Changelog

Closed issues:

  • Create chat bot with conversation loop and save message to database #272
  • Messaging API - January 2021 update #215

Merged pull requests:

Release v1.26.0

09 Nov 06:41
821977b
Compare
Choose a tag to compare

Changelog

v1.26.0 (2022-11-09)

Full Changelog

Closed issues:

  • Validating message objects #267
  • Validate rich menu object #256
  • DateTimePicker Action is not working properly #250

Merged pull requests:

v1.25.0

13 Jul 02:28
3ea3f31
Compare
Choose a tag to compare

v1.25.0 (2022-07-13)

Full Changelog

Closed issues:

  • Incorrect description of types specifier list in Rdoc #257

Merged pull requests:

v1.24.0

30 May 06:39
88b7701
Compare
Choose a tag to compare

v1.24.0 (2022-05-30)

Full Changelog

Merged pull requests:

  • Add ID token verification endpoint #253 (yskkin)

v1.23.0

27 Jan 06:09
8760add
Compare
Choose a tag to compare

v1.23.0 (2022-01-27)

Full Changelog

Closed issues:

  • Support get statistics per aggregation unit #219

Merged pull requests:

  • Add custom aggregation units API #247 (yskkin)
  • Get the follower ids with a limit #246 (zenizh)
  • additional request body for push_message and multicast #245 (yskkin)
  • add kitchensink README.md #243 (4geru)
  • add rich menu sample code #241 (4geru)