Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

line-bot-sdk-ruby

> 编程语言
Open source

LINE Messaging API SDK for Ruby

493 stars0 likes2 views
WebsiteGitHub

About

LINE Messaging API SDK for Ruby

LINE Messaging API SDK for Ruby

Introduction

The LINE Messaging API SDK for Ruby makes it easy to develop bots using LINE Messaging API, and you can create a sample bot within minutes.

Documentation

See the official API documentation for more information

  • English: https://developers.line.biz/en/docs/messaging-api/overview/
  • Japanese: https://developers.line.biz/ja/docs/messaging-api/overview/

Also, generated documentation by YARD is available.

  • https://line.github.io/line-bot-sdk-ruby/
  • https://line.github.io/line-bot-sdk-ruby/_index.html

Requirements

This library requires Ruby 3.3 or later.

Installation

Add this line to your application's Gemfile:

ruby
gem 'line-bot-api'

And then execute:

bash
bundle

Or install it yourself as:

bash
gem install line-bot-api

Example projects

We provide examples to help you get started with the SDK. They work in your local environment if you have owned your bot account.

Go the examples directory for more examples.

Synopsis

RBS

This library provides RBS files for type checking.
You can code with type support in the corresponding IDE or editor.

Basic Usage

…

Main classes

You may use this classes to use LINE Messaging API features.

Webhook

  • Line::Bot::V2::WebhookParser (LINE Developers)
  • Line::Bot::V2::Webhook::Event (LINE Developers)

Clients

Class(YARD documentation) API EndPoint LINE Developers
Line::Bot::V2::ChannelAccessToken::ApiClient https://api.line.me/** (related to oauth) https://developers.line.biz/en/reference/messaging-api/#channel-access-token
Line::Bot::V2::Insight::ApiClient https://api.line.me/v2/bot/insight/** https://developers.line.biz/en/reference/messaging-api/#get-insight
Line::Bot::V2::Liff::ApiClient https://api.line.me/liff/** https://developers.line.biz/en/reference/liff-server/#server-api
Line::Bot::V2::ManageAudience::ApiClient https://api.line.me/v2/bot/audienceGroup/** https://developers.line.biz/en/reference/messaging-api/#manage-audience-group
Line::Bot::V2::ManageAudience::ApiBlobClient https://api-data.line.me/v2/bot/audienceGroup/** https://developers.line.biz/en/reference/messaging-api/#manage-audience-group
Line::Bot::V2::MessagingApi::ApiClient https://api.line.me/v2/bot/** https://developers.line.biz/en/reference/messaging-api/
https://developers.line.biz/en/reference/partner-docs/
Line::Bot::V2::MessagingApi::ApiBlobClient https://api-data.line.me/v2/bot/** https://developers.line.biz/en/reference/messaging-api/
Line::Bot::V2::Module::ApiClient https://api.line.me/v2/bot/** (related to module) https://developers.line.biz/en/reference/partner-docs/#module
Line::Bot::V2::ModuleAttach::ApiClient https://manager.line.biz/module/auth/v1/token/** https://developers.line.biz/en/reference/partner-docs/#module
Line::Bot::V2::Shop::ApiClient https://api.line.me/shop/** https://developers.line.biz/en/reference/partner-docs/#mission-stickers

Use HTTP Information

You may need to store the x-line-request-id header obtained as a response from several APIs.
In this case, please use *_with_http_info methods. You can get headers and status codes.
The x-line-accepted-request-id or content-type header can also be obtained in the same way. Note header name must be lowercase.

ruby
push_request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
  to: event.source.user_id,
  messages: [
    Line::Bot::V2::MessagingApi::TextMessage.new(text: "[^Request ID] #{headers['x-line-request-id']}")
  ]
)
_body, _status_code, headers = client.push_message_with_http_info(push_message_request: push_request)

puts headers['x-line-request-id']
puts headers['x-line-accepted-request-id']
puts headers['content-type']

Error handling

If an API call fails, the SDK does not generate an Error in Ruby; use the status code for proper error handling. Error details are stored in body.

…

Use with Hash / JSON

You can use Hash instead of the SDK classes. So you can also use Hash parsed from JSON as a parameter.

This is useful, for example, in migrating from v1 or building Flex Message.

But this is not recommended because you lose type checking by RBS.

…

Convert to SDK classes

You can convert Hash / JSON to SDK classes using #create method.

ruby
json = <<~JSON
  {
    "to": "U4af4980629...",
    "messages": [
      {
        "type": "flex",
        "alt_text": "This is a Flex Message",
        "contents": {
          "type": "bubble",
          "body": {
            "type": "box",
            "layout": "horizontal",
            "contents": [
              {
                "type": "text",
                "text": "Hello"
              }
            ]
          }
        }
      }
    ]
  }
JSON
request = Line::Bot::V2::MessagingApi::PushMessageRequest.create(
  JSON.parse(json)
)

Versioning

This project respects semantic versioning.

  • See https://semver.org/

However, if a feature that was publicly released is discontinued for business reasons and becomes completely unusable, we will release changes as a patch release.

v1 and v2

v1 and v2 are completely different implementations. Migration to v2 is strongly recommended. Please refer to Migration guide for migration procedure.

Media

News: https://developers.line.biz/en/news/

Contributing

Please check CONTRIBUTING before making a contribution.

License

Copyright (C) 2016 LINE Corp.
 
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
   http://www.apache.org/licenses/LICENSE-2.0
 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Issues· 2 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubybotlinelinebotruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言