line-bot-api 1.30.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +49 -1
- data/README.md +250 -26
- data/lib/line/bot/v2/messaging_api/api/messaging_api_client.rb +269 -0
- data/lib/line/bot/v2/messaging_api/core.rb +39 -0
- data/lib/line/bot/v2/messaging_api/model/acquisition_condition_request.rb +77 -0
- data/lib/line/bot/v2/messaging_api/model/acquisition_condition_response.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_request.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_response.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_request.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_response.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/cash_back_price_info_request.rb +77 -0
- data/lib/line/bot/v2/messaging_api/model/cash_back_price_info_response.rb +77 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_cash_back_reward_request.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_cash_back_reward_response.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_create_request.rb +139 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_create_response.rb +67 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_discount_reward_request.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_discount_reward_response.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_free_reward_request.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_free_reward_response.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_gift_reward_request.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_gift_reward_response.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_list_response.rb +73 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_message.rb +91 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_others_reward_request.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_others_reward_response.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_response.rb +169 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_reward_request.rb +80 -0
- data/lib/line/bot/v2/messaging_api/model/coupon_reward_response.rb +80 -0
- data/lib/line/bot/v2/messaging_api/model/discount_explicit_price_info_request.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/discount_explicit_price_info_response.rb +84 -0
- data/lib/line/bot/v2/messaging_api/model/discount_fixed_price_info_request.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/discount_fixed_price_info_response.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/discount_percentage_price_info_request.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/discount_percentage_price_info_response.rb +72 -0
- data/lib/line/bot/v2/messaging_api/model/discount_price_info_request.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/discount_price_info_response.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/lottery_acquisition_condition_request.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/lottery_acquisition_condition_response.rb +78 -0
- data/lib/line/bot/v2/messaging_api/model/message.rb +1 -0
- data/lib/line/bot/v2/messaging_api/model/messaging_api_pager_coupon_list_response.rb +79 -0
- data/lib/line/bot/v2/messaging_api/model/normal_acquisition_condition_request.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/normal_acquisition_condition_response.rb +66 -0
- data/lib/line/bot/v2/messaging_api/model/referral_acquisition_condition_response.rb +66 -0
- data/lib/line/bot/version.rb +1 -1
- data/lib/line/bot.rb +0 -9
- data/line-bot-api.gemspec +1 -1
- data/sig/line/bot/v2/messaging_api/api/messaging_api_client.rbs +156 -0
- data/sig/line/bot/v2/messaging_api/model/acquisition_condition_request.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/acquisition_condition_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_request.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/cash_back_fixed_price_info_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_request.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/cash_back_percentage_price_info_response.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/cash_back_price_info_request.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/cash_back_price_info_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_cash_back_reward_request.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_cash_back_reward_response.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_create_request.rbs +76 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_create_response.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_discount_reward_request.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_discount_reward_response.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_free_reward_request.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_free_reward_response.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_gift_reward_request.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_gift_reward_response.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_list_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_message.rbs +50 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_others_reward_request.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_others_reward_response.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_response.rbs +91 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_reward_request.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/coupon_reward_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/discount_explicit_price_info_request.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/discount_explicit_price_info_response.rbs +46 -0
- data/sig/line/bot/v2/messaging_api/model/discount_fixed_price_info_request.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/discount_fixed_price_info_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/discount_percentage_price_info_request.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/discount_percentage_price_info_response.rbs +40 -0
- data/sig/line/bot/v2/messaging_api/model/discount_price_info_request.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/discount_price_info_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/lottery_acquisition_condition_request.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/lottery_acquisition_condition_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/messaging_api_pager_coupon_list_response.rbs +43 -0
- data/sig/line/bot/v2/messaging_api/model/normal_acquisition_condition_request.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/normal_acquisition_condition_response.rbs +37 -0
- data/sig/line/bot/v2/messaging_api/model/referral_acquisition_condition_response.rbs +37 -0
- metadata +81 -24
- data/lib/line/bot/v1/api/errors.rb +0 -23
- data/lib/line/bot/v1/api/version.rb +0 -23
- data/lib/line/bot/v1/api.rb +0 -33
- data/lib/line/bot/v1/client.rb +0 -1936
- data/lib/line/bot/v1/event/account_link.rb +0 -38
- data/lib/line/bot/v1/event/base.rb +0 -39
- data/lib/line/bot/v1/event/beacon.rb +0 -43
- data/lib/line/bot/v1/event/follow.rb +0 -30
- data/lib/line/bot/v1/event/join.rb +0 -29
- data/lib/line/bot/v1/event/leave.rb +0 -31
- data/lib/line/bot/v1/event/member_joined.rb +0 -29
- data/lib/line/bot/v1/event/member_left.rb +0 -31
- data/lib/line/bot/v1/event/message.rb +0 -51
- data/lib/line/bot/v1/event/postback.rb +0 -29
- data/lib/line/bot/v1/event/things.rb +0 -49
- data/lib/line/bot/v1/event/unfollow.rb +0 -31
- data/lib/line/bot/v1/event/unsend.rb +0 -31
- data/lib/line/bot/v1/event/video_play_complete.rb +0 -29
- data/lib/line/bot/v1/event.rb +0 -28
- data/lib/line/bot/v1/httpclient.rb +0 -91
- data/lib/line/bot/v1/util.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d6263a9bbf4c4a5a3d6a18965c1d81b96b91aeb88bcfd7edf4a1dbdeed1d16e
|
4
|
+
data.tar.gz: ed03051dcdd9b5bdd24382113758ae84d12e7ce42b900f75ced07efae11358c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5eb071cae7e4db290c9a6e8248cd6e288ae9881fb08c2be18811aa083bab6b11636e6e57ec96b662baa0163e50da68274c6a173f1a88af27da82eb4aa660632
|
7
|
+
data.tar.gz: c7e60c5813c0201f172f373b85d937a93f134b80044710a8289886da635ee0b95fe0ac5b56ca5c6a06acec8697152415f54516ac474898687d3a675913e64094
|
data/CONTRIBUTING.md
CHANGED
@@ -9,6 +9,54 @@ It will be amazing if you could help us by doing any of the following:
|
|
9
9
|
- Contribute your work by sending [a pull request](https://github.com/line/line-bot-sdk-ruby/pulls).
|
10
10
|
|
11
11
|
## Development
|
12
|
+
### Install dependencies
|
13
|
+
Run `bundle install` to install all dependencies for development.
|
14
|
+
|
15
|
+
### Understand the project structure
|
16
|
+
The project structure is as follows:
|
17
|
+
- `lib`: The main library code.
|
18
|
+
- `sig`: The RBS code.
|
19
|
+
- `sig-vendor`: The RBS code outside this repository.
|
20
|
+
- `spec`: The test code.
|
21
|
+
- `examples`: Example projects that use the library.
|
22
|
+
- `generator`: The code generator for the library.
|
23
|
+
|
24
|
+
### Edit pebble template
|
25
|
+
Almost all code are generated with [pebble template](https://pebbletemplates.io/), based on [line-openapi](https://github.com/line/line-openapi)'s yaml.
|
26
|
+
Thus, you can't edit almost all code under `lib/line/bot/v2/<dir>.rb` and `sig/line/bot/v2/<dir>.rbs` directly.
|
27
|
+
|
28
|
+
You need to edit the pebble template under [resources](generator/src/main/resources) instead.
|
29
|
+
|
30
|
+
After editing the templates, run `generate-code.py` to generate the code, and then commit all affected files.
|
31
|
+
If not, CI status will be red.
|
32
|
+
|
33
|
+
When you update code, be sure to check consistencies between `lib/**.rb` and `sig/**.rbs`.
|
34
|
+
|
35
|
+
### Add unit tests
|
36
|
+
We use [RSpec](https://rspec.info/) for unit tests.
|
37
|
+
Please add tests to the `spec` directory to verify your changes continuously.
|
38
|
+
|
39
|
+
Especially for bug fixes, please follow this flow for testing and development:
|
40
|
+
1. Write a test before making changes to the library and confirm that the test fails.
|
41
|
+
2. Modify the code of the library.
|
42
|
+
3. Run the test again and confirm that it passes thanks to (2).
|
43
|
+
|
44
|
+
### Run your code in your local
|
45
|
+
[Example projects](examples/v2) depend on this repository directly.
|
46
|
+
You can use new or fixed gem in example projects before submitting a pull request.
|
47
|
+
|
48
|
+
### Run all CI tasks in your local
|
49
|
+
`Rakefile` defines almost all tasks.
|
50
|
+
|
51
|
+
You can run all tasks in your local by running `bundle exec rake ci` command.
|
52
|
+
|
53
|
+
### Upgrade dependencies
|
54
|
+
The libraries that the library itself depends on are listed in the `line-bot-api.gemspec` file.
|
55
|
+
Those needed only for development are written in the `Gemfile`.
|
56
|
+
The versions in the gemspec file are set as low as possible, allowing users to specify higher versions in their application's Gemfile.
|
57
|
+
|
58
|
+
For files related to RBS, refer to `rbs_collections.yaml` and the `Steepfile`.
|
59
|
+
You can update by running `rbs collection update <LIB_NAME>`.
|
12
60
|
|
13
61
|
### YARD
|
14
62
|
|
@@ -41,5 +89,5 @@ For more details on how to write YARD doc comments, refer to YARD’s official [
|
|
41
89
|
|
42
90
|
### Contributor license agreement
|
43
91
|
|
44
|
-
When you
|
92
|
+
When you send a pull request and it's a non-trivial change beyond fixing typos, please make sure to sign [the ICLA (individual contributor license agreement)](https://cla-assistant.io/line/line-bot-sdk-ruby).
|
45
93
|
Please [contact us](mailto:dl_oss_dev@linecorp.com) if you need the CCLA (corporate contributor license agreement).
|
data/README.md
CHANGED
@@ -15,7 +15,8 @@ See the official API documentation for more information
|
|
15
15
|
|
16
16
|
Also, generated documentation by YARD is available.
|
17
17
|
|
18
|
-
- https://
|
18
|
+
- https://line.github.io/line-bot-sdk-ruby/
|
19
|
+
- https://line.github.io/line-bot-sdk-ruby/_index.html
|
19
20
|
|
20
21
|
## Requirements
|
21
22
|
This library requires Ruby 3.2 or later.
|
@@ -40,46 +41,79 @@ Or install it yourself as:
|
|
40
41
|
gem install line-bot-api
|
41
42
|
```
|
42
43
|
|
44
|
+
## Example projects
|
45
|
+
We provide examples to help you get started with the SDK.
|
46
|
+
They work in your local environment if you have owned your bot account.
|
47
|
+
|
48
|
+
Go the [examples](examples/v2) directory for more examples.
|
49
|
+
|
43
50
|
## Synopsis
|
51
|
+
### RBS
|
52
|
+
This library provides [RBS](https://github.com/ruby/rbs) files for type checking.\
|
53
|
+
You can code with type support in the corresponding IDE or editor.
|
44
54
|
|
45
|
-
Usage
|
55
|
+
### Basic Usage
|
46
56
|
|
47
57
|
```ruby
|
48
58
|
# app.rb
|
49
59
|
require 'sinatra'
|
50
|
-
require 'line
|
60
|
+
require 'line-bot-api'
|
61
|
+
|
62
|
+
set :environment, :production
|
51
63
|
|
52
64
|
def client
|
53
|
-
@client ||= Line::Bot::
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
65
|
+
@client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
|
66
|
+
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def blob_client
|
71
|
+
@blob_client ||= Line::Bot::V2::MessagingApi::ApiBlobClient.new(
|
72
|
+
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN")
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def parser
|
77
|
+
@parser ||= Line::Bot::V2::WebhookParser.new(channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"))
|
58
78
|
end
|
59
79
|
|
60
80
|
post '/callback' do
|
61
81
|
body = request.body.read
|
62
|
-
|
63
82
|
signature = request.env['HTTP_X_LINE_SIGNATURE']
|
64
|
-
|
65
|
-
|
83
|
+
|
84
|
+
begin
|
85
|
+
events = parser.parse(body: body, signature: signature)
|
86
|
+
rescue Line::Bot::V2::WebhookParser::InvalidSignatureError
|
87
|
+
halt 400, { 'Content-Type' => 'text/plain' }, 'Bad Request'
|
66
88
|
end
|
67
89
|
|
68
|
-
events = client.parse_events_from(body)
|
69
90
|
events.each do |event|
|
70
91
|
case event
|
71
|
-
when Line::Bot::
|
72
|
-
case event.
|
73
|
-
when Line::Bot::
|
74
|
-
message
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
92
|
+
when Line::Bot::V2::Webhook::MessageEvent
|
93
|
+
case event.message
|
94
|
+
when Line::Bot::V2::Webhook::TextMessageContent
|
95
|
+
case event.message.text
|
96
|
+
when 'profile'
|
97
|
+
if event.source.type == 'user'
|
98
|
+
profile_response = client.get_profile(user_id: event.source.user_id)
|
99
|
+
reply_text(event, "Display name: #{profile_response.display_name}\nStatus message: #{profile_response.status_message}")
|
100
|
+
else
|
101
|
+
reply_text(event, "Bot can't use profile API without user ID")
|
102
|
+
end
|
103
|
+
else
|
104
|
+
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
|
105
|
+
reply_token: event.reply_token,
|
106
|
+
messages: [
|
107
|
+
Line::Bot::V2::MessagingApi::TextMessage.new(text: "[ECHO] #{event.message.text}")
|
108
|
+
]
|
109
|
+
)
|
110
|
+
client.reply_message(reply_message_request: request)
|
111
|
+
end
|
112
|
+
|
113
|
+
when Line::Bot::V2::Webhook::ImageMessageContent, Line::Bot::V2::Webhook::VideoMessageContent
|
114
|
+
response = blob_client.get_message_content(message_id: event.message.message_id)
|
81
115
|
tf = Tempfile.open("content")
|
82
|
-
tf.write(response
|
116
|
+
tf.write(response)
|
83
117
|
end
|
84
118
|
end
|
85
119
|
end
|
@@ -89,16 +123,206 @@ post '/callback' do
|
|
89
123
|
end
|
90
124
|
```
|
91
125
|
|
92
|
-
|
93
|
-
|
126
|
+
### Main classes
|
127
|
+
You may use this classes to use LINE Messaging API features.
|
94
128
|
|
95
|
-
|
129
|
+
#### Webhook
|
130
|
+
- [Line::Bot::V2::WebhookParser](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/WebhookParser.html) ([LINE Developers](https://developers.line.biz/en/reference/messaging-api/#webhooks))
|
131
|
+
- [Line::Bot::V2::Webhook::Event](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Webhook/Event.html) ([LINE Developers](https://developers.line.biz/en/reference/messaging-api/#webhook-event-objects))
|
132
|
+
|
133
|
+
### Clients
|
134
|
+
|
135
|
+
| Class(YARD documentation) | API EndPoint | LINE Developers |
|
136
|
+
|----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
|
137
|
+
| [Line::Bot::V2::ChannelAccessToken::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ChannelAccessToken/ApiClient.html) | https://api.line.me/** (related to oauth) | https://developers.line.biz/en/reference/messaging-api/#channel-access-token |
|
138
|
+
| [Line::Bot::V2::Insight::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Insight/ApiClient.html) | https://api.line.me/v2/bot/insight/** | https://developers.line.biz/en/reference/messaging-api/#get-insight |
|
139
|
+
| [Line::Bot::V2::Liff::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Liff/ApiClient.html) | https://api.line.me/liff/** | https://developers.line.biz/en/reference/liff-server/#server-api |
|
140
|
+
| [Line::Bot::V2::ManageAudience::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ManageAudience/ApiClient.html) | https://api.line.me/v2/bot/audienceGroup/** | https://developers.line.biz/en/reference/messaging-api/#manage-audience-group |
|
141
|
+
| [Line::Bot::V2::ManageAudience::ApiBlobClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ManageAudience/ApiBlobClient.html) | https://api-data.line.me/v2/bot/audienceGroup/** | https://developers.line.biz/en/reference/messaging-api/#manage-audience-group |
|
142
|
+
| [Line::Bot::V2::MessagingApi::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/MessagingApi/ApiClient.html) | https://api.line.me/v2/bot/** | https://developers.line.biz/en/reference/messaging-api/<br/>https://developers.line.biz/en/reference/partner-docs/ |
|
143
|
+
| [Line::Bot::V2::MessagingApi::ApiBlobClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/MessagingApi/ApiBlobClient.html) | https://api-data.line.me/v2/bot/** | https://developers.line.biz/en/reference/messaging-api/ |
|
144
|
+
| [Line::Bot::V2::Module::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Module/ApiClient.html) | https://api.line.me/v2/bot/** (related to module) | https://developers.line.biz/en/reference/partner-docs/#module |
|
145
|
+
| [Line::Bot::V2::ModuleAttach::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ModuleAttach/ApiClient.html) | https://manager.line.biz/module/auth/v1/token/** | https://developers.line.biz/en/reference/partner-docs/#module |
|
146
|
+
| [Line::Bot::V2::Shop::ApiClient](https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/Shop/ApiClient.html) | https://api.line.me/shop/** | https://developers.line.biz/en/reference/partner-docs/#mission-stickers |
|
147
|
+
|
148
|
+
### Use HTTP Information
|
149
|
+
You may need to store the ```x-line-request-id``` header obtained as a response from several APIs.\
|
150
|
+
In this case, please use ```*_with_http_info``` methods. You can get headers and status codes.\
|
151
|
+
The `x-line-accepted-request-id` or `content-type` header can also be obtained in the same way. Note header name must be lowercase.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
push_request = Line::Bot::V2::MessagingApi::PushMessageRequest.new(
|
155
|
+
to: event.source.user_id,
|
156
|
+
messages: [
|
157
|
+
Line::Bot::V2::MessagingApi::TextMessage.new(text: "[^Request ID] #{headers['x-line-request-id']}")
|
158
|
+
]
|
159
|
+
)
|
160
|
+
_body, _status_code, headers = client.push_message_with_http_info(push_message_request: push_request)
|
161
|
+
|
162
|
+
puts headers['x-line-request-id']
|
163
|
+
puts headers['x-line-accepted-request-id']
|
164
|
+
puts headers['content-type']
|
165
|
+
```
|
166
|
+
|
167
|
+
### Error handling
|
168
|
+
If an API call fails, the SDK does not generate an Error in Ruby; use the status code for proper error handling.
|
169
|
+
Error details are stored in body.
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
require 'json'
|
173
|
+
require 'line-bot-api'
|
174
|
+
|
175
|
+
def client
|
176
|
+
@client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
|
177
|
+
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN"),
|
178
|
+
)
|
179
|
+
end
|
180
|
+
|
181
|
+
def main
|
182
|
+
dummy_message = Line::Bot::V2::MessagingApi::TextMessage.new(
|
183
|
+
text: "Hello, world!",
|
184
|
+
)
|
185
|
+
|
186
|
+
valid_request = Line::Bot::V2::MessagingApi::ValidateMessageRequest.new(
|
187
|
+
messages: [dummy_message, dummy_message, dummy_message, dummy_message, dummy_message],
|
188
|
+
)
|
189
|
+
body, status_code, _headers = client.validate_push_with_http_info(validate_message_request: valid_request)
|
190
|
+
handle_response(body, status_code)
|
191
|
+
|
192
|
+
invalid_request = Line::Bot::V2::MessagingApi::ValidateMessageRequest.new(
|
193
|
+
messages: [dummy_message, dummy_message, dummy_message, dummy_message, dummy_message, dummy_message],
|
194
|
+
)
|
195
|
+
body, status_code, _headers = client.validate_push_with_http_info(validate_message_request: invalid_request)
|
196
|
+
handle_response(body, status_code)
|
197
|
+
end
|
198
|
+
|
199
|
+
def handle_response(body, status_code)
|
200
|
+
case status_code
|
201
|
+
when 200
|
202
|
+
puts "Valid"
|
203
|
+
when 400..499
|
204
|
+
puts "Invalid: #{JSON.parse(body)}"
|
205
|
+
else
|
206
|
+
puts "Other Status: #{status_code}"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
main
|
211
|
+
```
|
212
|
+
|
213
|
+
### Use with Hash / JSON
|
214
|
+
You can use Hash instead of the SDK classes.
|
215
|
+
So you can also use Hash parsed from JSON as a parameter.
|
216
|
+
|
217
|
+
This is useful, for example, in migrating from v1 or building Flex Message.
|
218
|
+
|
219
|
+
**But this is not recommended because you lose type checking by RBS.**
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
client = Line::Bot::V2::MessagingApi::ApiClient.new(
|
223
|
+
channel_access_token: ENV.fetch("LINE_CHANNEL_ACCESS_TOKEN"),
|
224
|
+
)
|
225
|
+
|
226
|
+
request = {
|
227
|
+
to: "U4af4980629...",
|
228
|
+
messages: [
|
229
|
+
{
|
230
|
+
type: "flex",
|
231
|
+
alt_text: "This is a Flex Message",
|
232
|
+
contents: {
|
233
|
+
type: "bubble",
|
234
|
+
body: {
|
235
|
+
type: "box",
|
236
|
+
layout: "horizontal",
|
237
|
+
contents: [
|
238
|
+
{
|
239
|
+
type: "text",
|
240
|
+
text: "Hello"
|
241
|
+
}
|
242
|
+
]
|
243
|
+
}
|
244
|
+
}
|
245
|
+
}
|
246
|
+
]
|
247
|
+
}
|
248
|
+
client.push_message(push_message_request: request)
|
249
|
+
|
250
|
+
# or
|
251
|
+
|
252
|
+
request = JSON.parse(
|
253
|
+
<<~JSON
|
254
|
+
{
|
255
|
+
"to": "U4af4980629...",
|
256
|
+
"messages": [
|
257
|
+
{
|
258
|
+
"type": "flex",
|
259
|
+
"alt_text": "This is a Flex Message",
|
260
|
+
"contents": {
|
261
|
+
"type": "bubble",
|
262
|
+
"body": {
|
263
|
+
"type": "box",
|
264
|
+
"layout": "horizontal",
|
265
|
+
"contents": [
|
266
|
+
{
|
267
|
+
"type": "text",
|
268
|
+
"text": "Hello"
|
269
|
+
}
|
270
|
+
]
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}
|
274
|
+
]
|
275
|
+
}
|
276
|
+
JSON
|
277
|
+
)
|
278
|
+
client.push_message(push_message_request: request)
|
279
|
+
```
|
280
|
+
|
281
|
+
#### Convert to SDK classes
|
282
|
+
You can convert Hash / JSON to SDK classes using `#create` method.
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
json = <<~JSON
|
286
|
+
{
|
287
|
+
"to": "U4af4980629...",
|
288
|
+
"messages": [
|
289
|
+
{
|
290
|
+
"type": "flex",
|
291
|
+
"alt_text": "This is a Flex Message",
|
292
|
+
"contents": {
|
293
|
+
"type": "bubble",
|
294
|
+
"body": {
|
295
|
+
"type": "box",
|
296
|
+
"layout": "horizontal",
|
297
|
+
"contents": [
|
298
|
+
{
|
299
|
+
"type": "text",
|
300
|
+
"text": "Hello"
|
301
|
+
}
|
302
|
+
]
|
303
|
+
}
|
304
|
+
}
|
305
|
+
}
|
306
|
+
]
|
307
|
+
}
|
308
|
+
JSON
|
309
|
+
request = Line::Bot::V2::MessagingApi::PushMessageRequest.create(
|
310
|
+
JSON.parse(json)
|
311
|
+
)
|
312
|
+
```
|
96
313
|
|
97
314
|
## Versioning
|
98
315
|
This project respects semantic versioning.
|
99
316
|
|
100
317
|
See https://semver.org/
|
101
318
|
|
319
|
+
### v1 and v2
|
320
|
+
v1 and v2 are completely different implementations. Migration to v2 is strongly recommended.
|
321
|
+
Please refer to [Migration guide](migration_from_v1_to_v2_guide.md) for migration procedure.
|
322
|
+
|
323
|
+
## Media
|
324
|
+
News: https://developers.line.biz/en/news/
|
325
|
+
|
102
326
|
## Contributing
|
103
327
|
Please check [CONTRIBUTING](CONTRIBUTING.md) before making a contribution.
|
104
328
|
|