File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 33require 'line-bot-api'
44
55set :environment , :production
6- set :app_base_url , ENV [ 'APP_BASE_URL' ]
6+ set :app_base_url , ENV . fetch ( 'APP_BASE_URL' , nil )
77
88THUMBNAIL_URL = 'https://via.placeholder.com/1024x1024'
99HORIZONTAL_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" ) )
4040end
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+
4259post '/callback' do
4360 body = request . body . read
4461 signature = request . env [ 'HTTP_X_LINE_SIGNATURE' ]
You can’t perform that action at this time.
0 commit comments