Skip to content

Commit 16d2e11

Browse files
committed
NO-ISSUE No need to allow nil
1 parent ff8d7ed commit 16d2e11

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

examples/v2/echobot/Gemfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ PATH
22
remote: ../../..
33
specs:
44
line-bot-api (0.0.1.pre.test)
5-
multipart-post (~> 2.4.1)
5+
base64 (~> 0.2)
6+
multipart-post (~> 2.4)
67

78
GEM
89
remote: https://rubygems.org/

examples/v2/echobot/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
An example LINE bot just to echo messages
33

44
## Getting started
5-
```ruby
5+
This projects tries to set `${APP_BASE_URL}/callback` as webhook URL automatically on starting app.
6+
7+
```sh
68
$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
79
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
810
$ bundle install
11+
$ export APP_BASE_URL="https://your.base.url:4567"
912
$ bundle exec ruby app.rb
1013
```
1114

12-
```
13-
https://127.0.0.1:4567/callback
14-
```

examples/v2/echobot/app.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'line-bot-api'
33

44
set :environment, :production
5+
set :app_base_url, ENV.fetch('APP_BASE_URL')
56

67
def client
78
@client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
@@ -13,6 +14,19 @@ def parser
1314
@parser ||= Line::Bot::V2::WebhookParser.new(channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"))
1415
end
1516

17+
configure do
18+
webhook_endpoint = "#{settings.app_base_url}/callback"
19+
body, code, _ = client.set_webhook_endpoint_with_http_info(set_webhook_endpoint_request: Line::Bot::V2::MessagingApi::SetWebhookEndpointRequest.new(
20+
endpoint: webhook_endpoint
21+
))
22+
23+
if code == 200
24+
p "✅ LINE Webhook URL set to #{webhook_endpoint}"
25+
else
26+
p "❌ Failed to set LINE Webhook. code=#{code}, error body=#{body}"
27+
end
28+
end
29+
1630
post '/callback' do
1731
body = request.body.read
1832
signature = request.env['HTTP_X_LINE_SIGNATURE']

examples/v2/kitchensink/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# Kitchen Sink Bot
22

3-
A kitchen-sink LINE bot example
3+
A kitchen-sink LINE bot example. This contains many examples of line-bot-api gem's features.
44

55
## Getting started
6+
This projects tries to set `${APP_BASE_URL}/callback` as webhook URL automatically on starting app.
67

7-
```ruby
8+
```sh
89
$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
910
$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
1011
$ bundle install
1112
$ export APP_BASE_URL="https://your.base.url:4567"
1213
$ bundle exec ruby app.rb
1314
```
14-
15-
Then set url as webhook url in https://developers.line.biz/console/
16-
```
17-
https://your.base.url:4567/callback
18-
```

examples/v2/kitchensink/app.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'line-bot-api'
44

55
set :environment, :production
6-
set :app_base_url, ENV.fetch('APP_BASE_URL', nil)
6+
set :app_base_url, ENV.fetch('APP_BASE_URL')
77

88
THUMBNAIL_URL = 'https://via.placeholder.com/1024x1024'
99
HORIZONTAL_THUMBNAIL_URL = 'https://via.placeholder.com/1024x768'
@@ -40,19 +40,15 @@ def parser
4040
end
4141

4242
configure do
43-
if settings.app_base_url
44-
webhook_endpoint = "#{settings.app_base_url}/callback"
45-
body, code, _ = client.set_webhook_endpoint_with_http_info(set_webhook_endpoint_request: Line::Bot::V2::MessagingApi::SetWebhookEndpointRequest.new(
46-
endpoint: webhook_endpoint
47-
))
48-
49-
if code == 200
50-
p "✅ LINE Webhook URL set to #{webhook_endpoint}"
51-
else
52-
p "❌ Failed to set LINE Webhook. code=#{code}, error body=#{body}"
53-
end
43+
webhook_endpoint = "#{settings.app_base_url}/callback"
44+
body, code, _ = client.set_webhook_endpoint_with_http_info(set_webhook_endpoint_request: Line::Bot::V2::MessagingApi::SetWebhookEndpointRequest.new(
45+
endpoint: webhook_endpoint
46+
))
47+
48+
if code == 200
49+
p "✅ LINE Webhook URL set to #{webhook_endpoint}"
5450
else
55-
p "⚠️ APP_BASE_URL is not set; skipping LINE Webhook auto-configuration."
51+
p "❌ Failed to set LINE Webhook. code=#{code}, error body=#{body}"
5652
end
5753
end
5854

0 commit comments

Comments
 (0)