Releases: line/line-bot-sdk-ruby
v2.0.0 Support All Messaging API Features and RBS
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.
-
Simple Echo Bot
- A straightforward example demonstrating an echo bot implementation.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/echobot
-
Rich Menu
- An example for implementing and managing rich menus as described in the Messaging API - Using Rich Menus.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/rich_menu
-
Channel Access Token
- An example of issuing and revoking channel access tokens.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/channel_access_token
-
Audience
- An example of using the API of the Audience feature to group users for delivery.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/audience
-
Webhook Handling
- A comprehensive example covering Webhook handling and various API capabilities.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/kitchensink
Feedbacks & Contributions
We welcome feedback and contributions.
v1.30.0 Transitional release for v2
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:
- Upgrade the
line-bot-api
gem to1.30.0
. - 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.
- Once all code is switched, upgrade
line-bot-api
to2.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.
-
Simple Echo Bot
- A straightforward example demonstrating an echo bot implementation.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/echobot
-
Rich Menu
- An example for implementing and managing rich menus as described in the Messaging API - Using Rich Menus.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/rich_menu
-
Channel Access Token
- An example of issuing and revoking channel access tokens.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/channel_access_token
-
Audience
- An example of using the API of the Audience feature to group users for delivery.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/audience
-
Webhook Handling
- A comprehensive example covering Webhook handling and various API capabilities.
- https://github.com/line/line-bot-sdk-ruby/tree/master/examples/v2/kitchensink
Feedbacks & Contributions
We welcome feedback and contributions.
v1.29.1 Update dependencies
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
v1.29.0 (2024-06-10)
Closed issues:
Merged pull requests:
- feat: Support LINE notification messages API #326 (@linhnv)
- chore(deps): update dependency rubocop to '~> 1.64.0' #325 (renovate[bot])
- chore(deps): update actions/checkout digest to a5ac7e5 #324 (renovate[bot])
- chore(deps): update actions/checkout digest to 0ad4b8f #322 (renovate[bot])
- chore(deps): update actions/checkout digest to 1d96c77 #321 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.63.0' #319 (renovate[bot])
- Delete unused travis-ci url from README.md #318 (@Yang-33)
- Drop Ruby 3.0 support #317 (@Yang-33)
- chore(deps): update dependency rubocop to '~> 1.62.0' #316 (renovate[bot])
- Remove unnecessary urls from README #315 (@Yang-33)
- Drop Ruby 2.7 and support Ruby 3.2 & 3.3 #313 (@Yang-33)
- chore(deps): update actions/stale action to v9 #310 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.60.0' #309 (renovate[bot])
- Import release.yml to generate release note automatically based on label #308 (@Yang-33)
- Enable merge queue #307 (@Yang-33)
- Close stale issue automatically #306 (@Yang-33)
- chore(deps): update dependency rubocop to '~> 1.57.0' #305 (renovate[bot])
- chore(deps): update actions/checkout digest to b4ffde6 #303 (renovate[bot])
- chore(deps): update actions/checkout action to v4 #300 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.56.0' #298 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.55.0' #297 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.54.0' #293 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.53.0' #290 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.52.0' #289 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.51.0' #288 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.50.0' #287 (renovate[bot])
- chore(deps): update dependency rubocop to '~> 1.49.0' #286 (renovate[bot])
Release v1.28.0
v1.28.0 (2023-03-14)
Merged pull requests:
- Release v1.28.0 #285 (@zenizh)
- feat: support the Audience Match API #284 (@Sean0628)
- Update dependency rubocop to '~> 1.48.0' #281 (@renovate[bot])
- Update dependency rubocop to '~> 1.47.0' #280 (@renovate[bot])
- Update dependency rubocop to '~> 1.46.0' #279 (@renovate[bot])
- Update dependency rubocop to '~> 1.45.0' #278 (@renovate[bot])
Release v1.27.0
v1.27.0 (2023-02-08)
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.27.0 #277 (@zenizh)
- Implement get_narrowcast_message_status #276 (@dlackty)
- Update dependency rubocop to '~> 1.44.0' #275 (@renovate[bot])
- Update dependency rubocop to '~> 1.43.0' #274 (@renovate[bot])
- Update dependency rubocop to '~> 1.40.0' #273 (@renovate[bot])
- Update dependency rubocop to '~> 1.39.0' #271 (@renovate[bot])
Release v1.26.0
Changelog
v1.26.0 (2022-11-09)
Closed issues:
- Validating message objects #267
- Validate rich menu object #256
- DateTimePicker Action is not working properly #250
Merged pull requests:
- Release v1.26.0 #270 (@zenizh)
- Update dependency rubocop to '~> 1.38.0' #269 (@renovate[bot])
- Add APIs to validate message objects #268 (@zenizh)
- Update dependency rubocop to '~> 1.37.0' #266 (@renovate[bot])
- Update CI target version of the ruby #265 (@tokuhirom)
- Update actions/checkout action to v3 #263 (@renovate[bot])
- Update dependency rubocop to '~> 1.36.0' #262 (@renovate[bot])
- Configure Renovate #261 (@renovate[bot])
v1.25.0
v1.25.0 (2022-07-13)
Closed issues:
- Incorrect description of types specifier list in Rdoc #257
Merged pull requests:
- create validate_rich_menu method #259 (@kenta-takeuchi)
- fix types specifier list in Rdoc #258 (@kenta-takeuchi)