Skip to content

Commit 80b0a6f

Browse files
committed
NO-ISSUE Automate to set webhook url
1 parent 1af016f commit 80b0a6f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

examples/v2/kitchensink/app.rb

+18-1
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['APP_BASE_URL']
6+
set :app_base_url, ENV.fetch('APP_BASE_URL', nil)
77

88
THUMBNAIL_URL = 'https://via.placeholder.com/1024x1024'
99
HORIZONTAL_THUMBNAIL_URL = 'https://via.placeholder.com/1024x768'
@@ -39,6 +39,23 @@ def parser
3939
@parser ||= Line::Bot::V2::WebhookParser.new(channel_secret: ENV.fetch("LINE_CHANNEL_SECRET"))
4040
end
4141

42+
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
54+
else
55+
p "⚠️ APP_BASE_URL is not set; skipping LINE Webhook auto-configuration."
56+
end
57+
end
58+
4259
post '/callback' do
4360
body = request.body.read
4461
signature = request.env['HTTP_X_LINE_SIGNATURE']

0 commit comments

Comments
 (0)