line-bot-message-builder 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +224 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/line/bot/message_builder.rb +5 -0
- data/lib/line/bot/message_builder/action.rb +12 -0
- data/lib/line/bot/message_builder/actions/message.rb +25 -0
- data/lib/line/bot/message_builder/actions/postback.rb +26 -0
- data/lib/line/bot/message_builder/actions/uri.rb +25 -0
- data/lib/line/bot/message_builder/base.rb +51 -0
- data/lib/line/bot/message_builder/message.rb +17 -0
- data/lib/line/bot/message_builder/messages/audio.rb +25 -0
- data/lib/line/bot/message_builder/messages/image.rb +25 -0
- data/lib/line/bot/message_builder/messages/location.rb +29 -0
- data/lib/line/bot/message_builder/messages/sticker.rb +25 -0
- data/lib/line/bot/message_builder/messages/template.rb +31 -0
- data/lib/line/bot/message_builder/messages/text.rb +23 -0
- data/lib/line/bot/message_builder/messages/video.rb +25 -0
- data/lib/line/bot/message_builder/template.rb +12 -0
- data/lib/line/bot/message_builder/templates/buttons.rb +41 -0
- data/lib/line/bot/message_builder/version.rb +7 -0
- data/line-bot-message-builder.gemspec +35 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f0ac40fde8424ff37b23cb15d822f3087b2affbe6de0dba70369deffadc2e1d5
|
4
|
+
data.tar.gz: 42414273b1291662cbebe9164375a8f8d8b87da8b351625eb8f34054771c93db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5306b4ca12c04becbc383d1122b5b4f43655da3df657aee841657d5e03e06707be85b83fad627f93824a62b192847d715888107cae8a6b3c7517241ea2c1950e
|
7
|
+
data.tar.gz: a7cfd320bf158d176c4d608c5e7e4f921e422c2f6b90adddbad628e0a4f75f117aaff1c8377c364d76bfa74a4e0526a6b8d4668c126fd1649a6dd3457e097be3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jk195417@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 楊竑昕
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
# Line::Bot::MessageBuilder
|
2
|
+
|
3
|
+
Plain Old Ruby Object to [Line Messaging API](https://developers.line.me/en/docs/messaging-api/reference/#message-objects) hash format.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'line-bot-message-builder'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install line-bot-message-builder
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
require it:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'line/bot/message_builder'
|
27
|
+
```
|
28
|
+
|
29
|
+
> if you using Rails, you can create a initiializer `config/initiializers/line_bot` and require
|
30
|
+
|
31
|
+
include `Line::Bot::MessageBuilder` for use shorter class name or not:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# didn't include usage
|
35
|
+
Line::Bot::MessageBuilder::Message::Text.new do |m|
|
36
|
+
m.text= '123'
|
37
|
+
end
|
38
|
+
|
39
|
+
# included usage
|
40
|
+
include Line::Bot::MessageBuilder
|
41
|
+
Message::Text.new do |m|
|
42
|
+
m.text= '123'
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
more complex example:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Message::Template.new do |t|
|
50
|
+
t.alt_text = 'example1'
|
51
|
+
t.template = Template::Buttons.new do |b|
|
52
|
+
b.text = 'example2'
|
53
|
+
b.actions << Action::Postback.new do |a|
|
54
|
+
a.label = 'example3'
|
55
|
+
a.data = 'action=example3'
|
56
|
+
end
|
57
|
+
b.actions << Action::Postback.new do |a|
|
58
|
+
a.label = 'example4'
|
59
|
+
a.data = 'action=example4'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
use `to_h` method convert `MessageBuilder` instance to `hash`:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
m = Message::Template.new do |t|
|
69
|
+
t.alt_text = 'example1'
|
70
|
+
t.template = Template::Buttons.new do |b|
|
71
|
+
b.text = 'example2'
|
72
|
+
b.actions << Action::Postback.new do |a|
|
73
|
+
a.label = 'example3'
|
74
|
+
a.data = 'action=example3'
|
75
|
+
end
|
76
|
+
b.actions << Action::Postback.new do |a|
|
77
|
+
a.label = 'example4'
|
78
|
+
a.data = 'action=example4'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
m.to_h
|
84
|
+
=> {"type"=>"template",
|
85
|
+
"altText"=>"example1",
|
86
|
+
"template"=>
|
87
|
+
{"type"=>"buttons",
|
88
|
+
"text"=>"example2",
|
89
|
+
"actions"=>
|
90
|
+
[{"type"=>"postback", "label"=>"example3", "data"=>"action=example3"},
|
91
|
+
{"type"=>"postback", "label"=>"example4", "data"=>"action=example4"}]}}
|
92
|
+
```
|
93
|
+
|
94
|
+
### with line-bot-sdk-ruby
|
95
|
+
|
96
|
+
Example with [line-bot-sdk-ruby](https://github.com/line/line-bot-sdk-ruby) and service object.
|
97
|
+
|
98
|
+
create a service object:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# services/line_bot_service
|
102
|
+
class LineBotService
|
103
|
+
include Line::Bot::MessageBuilder
|
104
|
+
attr_reader :bot, :chats, :request
|
105
|
+
|
106
|
+
def initialize(request)
|
107
|
+
@request = request
|
108
|
+
@body = @request.raw_post
|
109
|
+
@signature = @request.env['HTTP_X_LINE_SIGNATURE']
|
110
|
+
@bot = Line::Bot::Client.new(Rails.application.config.line_bot)
|
111
|
+
@chats = @bot.parse_events_from(@body)
|
112
|
+
raise 'signature invalid' unless @bot.validate_signature(@body, @signature)
|
113
|
+
end
|
114
|
+
|
115
|
+
def perform
|
116
|
+
@chats.each do |chat|
|
117
|
+
token = chat['replyToken']
|
118
|
+
message = bulid_msg_and_react(chat).to_h
|
119
|
+
next if message.blank?
|
120
|
+
|
121
|
+
@bot.reply_message token, message
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def bulid_msg_and_react(chat)
|
128
|
+
# write your reply logic here
|
129
|
+
case chat
|
130
|
+
when Line::Bot::Event::Message
|
131
|
+
text = chat['message'].fetch('text') { '' }
|
132
|
+
return message1 if conditions
|
133
|
+
return message2 if conditions2
|
134
|
+
return message3
|
135
|
+
when Line::Bot::Event::Postback
|
136
|
+
data = chat['postback'].fetch('data') { '' }
|
137
|
+
data = ActionController::Parameters.new(Rack::Utils.parse_nested_query(data))
|
138
|
+
return message4 if data[:action] == 'action'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# messages and reactions
|
143
|
+
def message1
|
144
|
+
do_something1
|
145
|
+
Message::Text.new(text: 'message1')
|
146
|
+
end
|
147
|
+
|
148
|
+
def message2
|
149
|
+
do_something2
|
150
|
+
Message::Template.new do |t|
|
151
|
+
t.alt_text = 'message2'
|
152
|
+
t.template = Template::Buttons.new do |b|
|
153
|
+
b.text = 'message2'
|
154
|
+
b.actions << Action::Postback.new do |a|
|
155
|
+
a.label = 'action1'
|
156
|
+
a.data = 'action=action1'
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def message3
|
163
|
+
do_something3
|
164
|
+
Message::Text.new(text: 'message3')
|
165
|
+
end
|
166
|
+
|
167
|
+
def message4
|
168
|
+
do_something3
|
169
|
+
Messages::Sticker.new(package_id: 1, sticker_id: 5)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
and use it like this in Rails
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
# line_controller #webhook
|
178
|
+
def webhook
|
179
|
+
service = LineBotService.new(request)
|
180
|
+
service.perform
|
181
|
+
render plain: 'Success', status: 200
|
182
|
+
end
|
183
|
+
```
|
184
|
+
|
185
|
+
## TODO
|
186
|
+
|
187
|
+
* [ ] messages
|
188
|
+
* [x] image
|
189
|
+
* [x] text
|
190
|
+
* [x] video
|
191
|
+
* [x] audio
|
192
|
+
* [x] sticker
|
193
|
+
* [x] location
|
194
|
+
* [ ] template
|
195
|
+
* [ ] templates
|
196
|
+
* [x] buttons
|
197
|
+
* [ ] confirm
|
198
|
+
* [ ] imagecarousel
|
199
|
+
* [ ] carousel
|
200
|
+
* [ ] actions
|
201
|
+
* [x] message
|
202
|
+
* [x] postback
|
203
|
+
* [x] uri
|
204
|
+
* [ ] datetimepicker
|
205
|
+
|
206
|
+
Feel free to create a PR to contribute.
|
207
|
+
|
208
|
+
## Development
|
209
|
+
|
210
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
211
|
+
|
212
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
213
|
+
|
214
|
+
## Contributing
|
215
|
+
|
216
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/jk195417/line-bot-message-builder>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
217
|
+
|
218
|
+
## License
|
219
|
+
|
220
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
221
|
+
|
222
|
+
## Code of Conduct
|
223
|
+
|
224
|
+
Everyone interacting in the Line::Bot::MessageBuilder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/line-bot-message-builder/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "line/bot/message_builder"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Action < Base; end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'line/bot/message_builder/actions/message'
|
10
|
+
require 'line/bot/message_builder/actions/postback'
|
11
|
+
require 'line/bot/message_builder/actions/uri'
|
12
|
+
# require 'line/bot/message_builder/actions/datetimepicker'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Action::Message < Action
|
5
|
+
attr_accessor :label, :text
|
6
|
+
|
7
|
+
def initialize(label: nil, text: nil)
|
8
|
+
super 'message' do
|
9
|
+
@label = label
|
10
|
+
@text = text
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.required
|
16
|
+
{
|
17
|
+
'type' => String,
|
18
|
+
'label' => String,
|
19
|
+
'text' => String
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Action::Postback < Action
|
5
|
+
attr_accessor :label, :data, :display_text
|
6
|
+
|
7
|
+
def initialize(label: nil, data: nil, display_text: nil)
|
8
|
+
super 'postback' do
|
9
|
+
@label = label
|
10
|
+
@data = data
|
11
|
+
@display_text = display_text
|
12
|
+
yield self if block_given?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.required
|
17
|
+
{
|
18
|
+
'type' => String,
|
19
|
+
'label' => String,
|
20
|
+
'data' => String
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Action::Uri < Action
|
5
|
+
attr_accessor :label, :uri
|
6
|
+
|
7
|
+
def initialize(label: nil, uri: nil)
|
8
|
+
super 'uri' do
|
9
|
+
@label = label
|
10
|
+
@uri = uri
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.required
|
16
|
+
{
|
17
|
+
'type' => String,
|
18
|
+
'label' => String,
|
19
|
+
'uri' => String
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# abstract class
|
2
|
+
module Line
|
3
|
+
module Bot
|
4
|
+
module MessageBuilder
|
5
|
+
class Base
|
6
|
+
attr_accessor :type
|
7
|
+
|
8
|
+
def initialize(type)
|
9
|
+
@type = type
|
10
|
+
yield
|
11
|
+
verify_required
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.required
|
15
|
+
{
|
16
|
+
'type' => String
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_h
|
21
|
+
result = {}
|
22
|
+
instance_values.each do |key, value|
|
23
|
+
camelCase = key.split('_').map.with_index do |str, i|
|
24
|
+
if i == 0
|
25
|
+
str.downcase
|
26
|
+
else
|
27
|
+
str.capitalize
|
28
|
+
end
|
29
|
+
end.join
|
30
|
+
result[camelCase] = value unless value.nil?
|
31
|
+
end
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def instance_values
|
38
|
+
Hash[instance_variables.map { |name| [name[1..-1], instance_variable_get(name)] }]
|
39
|
+
end
|
40
|
+
|
41
|
+
def verify_required
|
42
|
+
self.class.required.each { |key, value| verify_instance_value_type key, value }
|
43
|
+
end
|
44
|
+
|
45
|
+
def verify_instance_value_type(name, type)
|
46
|
+
raise TypeError, "@#{name}: #{instance_values[name]}, expect to be #{type}" unless instance_values[name].is_a? type
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message < Base; end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
require 'line/bot/message_builder/messages/image'
|
11
|
+
require 'line/bot/message_builder/messages/text'
|
12
|
+
require 'line/bot/message_builder/messages/video'
|
13
|
+
require 'line/bot/message_builder/messages/audio'
|
14
|
+
require 'line/bot/message_builder/messages/sticker'
|
15
|
+
require 'line/bot/message_builder/messages/location'
|
16
|
+
require 'line/bot/message_builder/messages/template'
|
17
|
+
# require 'line/bot/message_builder/messages/imagemap'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message::Audio < Message
|
5
|
+
attr_accessor :original_content_url, :duration
|
6
|
+
|
7
|
+
def initialize(original_content_url: nil, duration: nil)
|
8
|
+
super 'audio' do
|
9
|
+
@original_content_url = original_content_url
|
10
|
+
@duration = duration
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.required
|
16
|
+
{
|
17
|
+
'type' => String,
|
18
|
+
'original_content_url' => String,
|
19
|
+
'duration' => Integer
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message::Image < Message
|
5
|
+
attr_accessor :original_content_url, :preview_image_url
|
6
|
+
|
7
|
+
def initialize(original_content_url: nil, preview_image_url: nil)
|
8
|
+
super 'image' do
|
9
|
+
@original_content_url = original_content_url
|
10
|
+
@preview_image_url = preview_image_url
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.required
|
16
|
+
{
|
17
|
+
'type' => String,
|
18
|
+
'original_content_url' => String,
|
19
|
+
'preview_image_url' => String
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message::Location < Message
|
5
|
+
attr_accessor :title, :address, :latitude, :longitude
|
6
|
+
|
7
|
+
def initialize(title: nil, address: nil, latitude: nil, longitude: nil)
|
8
|
+
super 'location' do
|
9
|
+
@title = title
|
10
|
+
@address = address
|
11
|
+
@latitude = latitude
|
12
|
+
@longitude = longitude
|
13
|
+
yield self if block_given?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.required
|
18
|
+
{
|
19
|
+
'type' => String,
|
20
|
+
'title' => String,
|
21
|
+
'address' => String,
|
22
|
+
'latitude' => Float,
|
23
|
+
'longitude' => Float
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message::Sticker < Message
|
5
|
+
attr_accessor :package_id, :sticker_id
|
6
|
+
|
7
|
+
def initialize(package_id: nil, sticker_id: nil)
|
8
|
+
super 'sticker' do
|
9
|
+
@package_id = package_id
|
10
|
+
@sticker_id = sticker_id
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.required
|
16
|
+
{
|
17
|
+
'type' => String,
|
18
|
+
'package_id' => String,
|
19
|
+
'sticker_id' => String
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message::Template < Message
|
5
|
+
attr_accessor :alt_text, :template
|
6
|
+
|
7
|
+
def initialize(alt_text: nil, template: nil)
|
8
|
+
super 'template' do
|
9
|
+
@alt_text = alt_text
|
10
|
+
@template = template
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.required
|
16
|
+
{
|
17
|
+
'type' => String,
|
18
|
+
'alt_text' => String,
|
19
|
+
'template' => Template
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_h
|
24
|
+
result = super
|
25
|
+
result['template'] = template.to_h
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message::Text < Message
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
def initialize(text: nil)
|
8
|
+
super 'text' do
|
9
|
+
@text = text
|
10
|
+
yield self if block_given?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.required
|
15
|
+
{
|
16
|
+
'type' => String,
|
17
|
+
'text' => String
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Message::Video < Message
|
5
|
+
attr_accessor :original_content_url, :preview_image_url
|
6
|
+
|
7
|
+
def initialize(original_content_url: nil, preview_image_url: nil)
|
8
|
+
super 'video' do
|
9
|
+
@original_content_url = original_content_url
|
10
|
+
@preview_image_url = preview_image_url
|
11
|
+
yield self if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.required
|
16
|
+
{
|
17
|
+
'type' => String,
|
18
|
+
'original_content_url' => String,
|
19
|
+
'preview_image_url' => String
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Template < Base; end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'line/bot/message_builder/templates/buttons'
|
10
|
+
# require 'line/bot/message_builder/templates/confirm'
|
11
|
+
# require 'line/bot/message_builder/templates/imagecarousel'
|
12
|
+
# require 'line/bot/message_builder/templates/carousel'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Line
|
2
|
+
module Bot
|
3
|
+
module MessageBuilder
|
4
|
+
class Template::Buttons < Template
|
5
|
+
attr_accessor :thumbnail_image_url, :image_aspect_ratio,
|
6
|
+
:image_size, :image_background_color, :title,
|
7
|
+
:text, :default_action, :actions
|
8
|
+
|
9
|
+
def initialize(thumbnail_image_url: nil, image_aspect_ratio: nil,
|
10
|
+
image_size: nil, image_background_color: nil, title: nil,
|
11
|
+
text: nil, default_action: nil, actions: [])
|
12
|
+
super 'buttons' do
|
13
|
+
@thumbnail_image_url = thumbnail_image_url
|
14
|
+
@image_aspect_ratio = image_aspect_ratio
|
15
|
+
@image_size = image_size
|
16
|
+
@image_background_color = image_background_color
|
17
|
+
@title = title
|
18
|
+
@text = text
|
19
|
+
@default_action = default_action
|
20
|
+
@actions = actions
|
21
|
+
yield self if block_given?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.required
|
26
|
+
{
|
27
|
+
'type' => String,
|
28
|
+
'text' => String,
|
29
|
+
'actions' => Array
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_h
|
34
|
+
result = super
|
35
|
+
result['actions'] = result['actions'].map { |action| action.to_h }
|
36
|
+
result
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "line/bot/message_builder/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "line-bot-message-builder"
|
8
|
+
spec.version = Line::Bot::MessageBuilder::VERSION
|
9
|
+
spec.authors = ["楊竑昕"]
|
10
|
+
spec.email = ["jk195417@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Reply Message Builders for Line Messaging API}
|
13
|
+
spec.homepage = "https://github.com/jk195417/line-bot-message-builder"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: line-bot-message-builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 楊竑昕
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jk195417@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/line/bot/message_builder.rb
|
73
|
+
- lib/line/bot/message_builder/action.rb
|
74
|
+
- lib/line/bot/message_builder/actions/message.rb
|
75
|
+
- lib/line/bot/message_builder/actions/postback.rb
|
76
|
+
- lib/line/bot/message_builder/actions/uri.rb
|
77
|
+
- lib/line/bot/message_builder/base.rb
|
78
|
+
- lib/line/bot/message_builder/message.rb
|
79
|
+
- lib/line/bot/message_builder/messages/audio.rb
|
80
|
+
- lib/line/bot/message_builder/messages/image.rb
|
81
|
+
- lib/line/bot/message_builder/messages/location.rb
|
82
|
+
- lib/line/bot/message_builder/messages/sticker.rb
|
83
|
+
- lib/line/bot/message_builder/messages/template.rb
|
84
|
+
- lib/line/bot/message_builder/messages/text.rb
|
85
|
+
- lib/line/bot/message_builder/messages/video.rb
|
86
|
+
- lib/line/bot/message_builder/template.rb
|
87
|
+
- lib/line/bot/message_builder/templates/buttons.rb
|
88
|
+
- lib/line/bot/message_builder/version.rb
|
89
|
+
- line-bot-message-builder.gemspec
|
90
|
+
homepage: https://github.com/jk195417/line-bot-message-builder
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.7.4
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Reply Message Builders for Line Messaging API
|
115
|
+
test_files: []
|