File tree Expand file tree Collapse file tree 11 files changed +43
-19
lines changed Expand file tree Collapse file tree 11 files changed +43
-19
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ An example LINE bot just to echo messages
44
55## Getting started
66
7- ``` ruby
7+ ``` sh
88$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
99$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
1010$ bundle install
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ A kitchen-sink LINE bot example
44
55## Getting started
66
7- ``` ruby
7+ ``` sh
88$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
99$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
1010$ bundle install
Original file line number Diff line number Diff line change 44
55## Getting started
66
7- ``` ruby
7+ ``` sh
88$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
99$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
1010$ bundle install
Original file line number Diff line number Diff line change 55## Getting started
66Update User ID of ` app.rb ` and `audience.txt' to your own.
77
8- ``` ruby
8+ ``` sh
99$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
1010$ export LINE_CHANNEL_ACCESS_TOKEN=YOUR_CHANNEL_ACCESS_TOKEN
1111$ bundle install
Original file line number Diff line number Diff line change 44
55## Getting started
66
7- ``` ruby
7+ ``` sh
88$ export LINE_CHANNEL_ID=YOUR_CHANNEL_ID
99$ export LINE_CHANNEL_SECRET=YOUR_CHANNEL_SECRET
1010$ bundle install
Original file line number Diff line number Diff line change 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
78GEM
89 remote: https://rubygems.org/
Original file line number Diff line number Diff line change 22An 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- ```
Original file line number Diff line number Diff line change 22require 'line-bot-api'
33
44set :environment , :production
5+ set :app_base_url , ENV . fetch ( 'APP_BASE_URL' )
56
67def 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" ) )
1415end
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+
1630post '/callback' do
1731 body = request . body . read
1832 signature = request . env [ 'HTTP_X_LINE_SIGNATURE' ]
Original file line number Diff line number Diff line change 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- ```
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' )
77
88THUMBNAIL_URL = 'https://via.placeholder.com/1024x1024'
99HORIZONTAL_THUMBNAIL_URL = 'https://via.placeholder.com/1024x768'
@@ -39,6 +39,19 @@ def parser
3939 @parser ||= Line ::Bot ::V2 ::WebhookParser . new ( channel_secret : ENV . fetch ( "LINE_CHANNEL_SECRET" ) )
4040end
4141
42+ configure do
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 } "
50+ else
51+ p "❌ Failed to set LINE Webhook. code=#{ code } , error body=#{ body } "
52+ end
53+ end
54+
4255post '/callback' do
4356 body = request . body . read
4457 signature = request . env [ 'HTTP_X_LINE_SIGNATURE' ]
You can’t perform that action at this time.
0 commit comments