line-bot-api 0.1.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +43 -221
- data/lib/line/bot.rb +15 -8
- data/lib/line/bot/api.rb +15 -2
- data/lib/line/bot/api/errors.rb +14 -1
- data/lib/line/bot/api/version.rb +15 -1
- data/lib/line/bot/client.rb +89 -164
- data/lib/line/bot/event.rb +22 -0
- data/lib/line/bot/event/base.rb +30 -0
- data/lib/line/bot/event/beacon.rb +22 -0
- data/lib/line/bot/event/follow.rb +22 -0
- data/lib/line/bot/event/join.rb +22 -0
- data/lib/line/bot/event/leave.rb +22 -0
- data/lib/line/bot/event/message.rb +43 -0
- data/lib/line/bot/event/postback.rb +22 -0
- data/lib/line/bot/event/unfollow.rb +22 -0
- data/lib/line/bot/httpclient.rb +14 -0
- data/lib/line/bot/request.rb +19 -23
- data/line-bot-api.gemspec +1 -5
- metadata +31 -89
- data/lib/line/bot/builder/multiple_message.rb +0 -101
- data/lib/line/bot/builder/rich_message.rb +0 -154
- data/lib/line/bot/event_type.rb +0 -15
- data/lib/line/bot/message.rb +0 -9
- data/lib/line/bot/message/audio.rb +0 -25
- data/lib/line/bot/message/base.rb +0 -35
- data/lib/line/bot/message/contact.rb +0 -18
- data/lib/line/bot/message/content_type.rb +0 -16
- data/lib/line/bot/message/image.rb +0 -23
- data/lib/line/bot/message/location.rb +0 -28
- data/lib/line/bot/message/recipient_type.rb +0 -9
- data/lib/line/bot/message/sticker.rb +0 -26
- data/lib/line/bot/message/text.rb +0 -22
- data/lib/line/bot/message/video.rb +0 -23
- data/lib/line/bot/operation.rb +0 -3
- data/lib/line/bot/operation/added_as_friend.rb +0 -10
- data/lib/line/bot/operation/base.rb +0 -17
- data/lib/line/bot/operation/blocked_account.rb +0 -10
- data/lib/line/bot/operation/op_type.rb +0 -10
- data/lib/line/bot/receive/message.rb +0 -69
- data/lib/line/bot/receive/operation.rb +0 -42
- data/lib/line/bot/receive/request.rb +0 -35
- data/lib/line/bot/response/user/contact.rb +0 -22
- data/lib/line/bot/response/user/profile.rb +0 -30
- data/lib/line/bot/utils.rb +0 -16
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'line/bot/message'
|
2
|
-
|
3
|
-
module Line
|
4
|
-
module Bot
|
5
|
-
module Builder
|
6
|
-
class MultipleMessage
|
7
|
-
|
8
|
-
def initialize(client)
|
9
|
-
@messages ||= []
|
10
|
-
@client = client
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_text(attrs = {})
|
14
|
-
tap {
|
15
|
-
message = Message::Text.new(
|
16
|
-
text: attrs[:text],
|
17
|
-
)
|
18
|
-
push_message(message)
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_image(attrs = {})
|
23
|
-
tap {
|
24
|
-
message = Message::Image.new(
|
25
|
-
image_url: attrs[:image_url],
|
26
|
-
preview_url: attrs[:preview_url],
|
27
|
-
)
|
28
|
-
push_message(message)
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_video(attrs = {})
|
33
|
-
tap {
|
34
|
-
message = Message::Video.new(
|
35
|
-
video_url: attrs[:video_url],
|
36
|
-
preview_url: attrs[:preview_url],
|
37
|
-
)
|
38
|
-
push_message(message)
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_audio(attrs = {})
|
43
|
-
tap {
|
44
|
-
message = Message::Audio.new(
|
45
|
-
audio_url: attrs[:audio_url],
|
46
|
-
duration: attrs[:duration],
|
47
|
-
)
|
48
|
-
push_message(message)
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def add_location(attrs = {})
|
53
|
-
tap {
|
54
|
-
message = Message::Location.new(
|
55
|
-
title: attrs[:title],
|
56
|
-
latitude: attrs[:latitude],
|
57
|
-
longitude: attrs[:longitude],
|
58
|
-
)
|
59
|
-
push_message(message)
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
def add_sticker(attrs = {})
|
64
|
-
tap {
|
65
|
-
message = Message::Sticker.new(
|
66
|
-
stkpkgid: attrs[:stkpkgid],
|
67
|
-
stkid: attrs[:stkid],
|
68
|
-
stkver: attrs[:stkver],
|
69
|
-
)
|
70
|
-
push_message(message)
|
71
|
-
}
|
72
|
-
end
|
73
|
-
|
74
|
-
def push_message(message)
|
75
|
-
raise ArgumentError, "Invalid argument: `message`" unless message.valid?
|
76
|
-
@messages << message.content
|
77
|
-
end
|
78
|
-
|
79
|
-
def send(attrs = {})
|
80
|
-
@client.send_message(attrs[:to_mid], self)
|
81
|
-
end
|
82
|
-
|
83
|
-
def event_type
|
84
|
-
Line::Bot::EventType::MULTIPLE_MESSAGE
|
85
|
-
end
|
86
|
-
|
87
|
-
def content
|
88
|
-
{
|
89
|
-
messageNotified: 0,
|
90
|
-
messages: @messages
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
def valid?
|
95
|
-
@messages.size > 0
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'line/bot/message'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Line
|
5
|
-
module Bot
|
6
|
-
module Builder
|
7
|
-
class RichMessage
|
8
|
-
|
9
|
-
def initialize(client)
|
10
|
-
@actions ||= {}
|
11
|
-
@listeners ||= []
|
12
|
-
@client = client
|
13
|
-
end
|
14
|
-
|
15
|
-
def set_action(attrs = {})
|
16
|
-
tap {
|
17
|
-
attrs.each { |key, value|
|
18
|
-
case value[:type]
|
19
|
-
when 'sendMessage'
|
20
|
-
raise ArgumentError, 'Invalid arguments, :text, :params_text keys.' unless validate_action_attributes_type_send_message(value)
|
21
|
-
@actions[key.to_s] = {
|
22
|
-
type: 'sendMessage',
|
23
|
-
text: value[:text].to_s,
|
24
|
-
params: {
|
25
|
-
text: value[:params_text].to_s
|
26
|
-
},
|
27
|
-
}
|
28
|
-
when 'web', nil
|
29
|
-
raise ArgumentError, 'Invalid arguments, :text, :link_url keys.' unless validate_action_attributes_type_web(value)
|
30
|
-
@actions[key.to_s] = {
|
31
|
-
type: 'web',
|
32
|
-
text: value[:text].to_s,
|
33
|
-
params: {
|
34
|
-
linkUri: value[:link_url].to_s
|
35
|
-
},
|
36
|
-
}
|
37
|
-
end
|
38
|
-
}
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def validate_action_attributes_type_send_message(attrs = {})
|
43
|
-
attrs[:text] && attrs[:params_text]
|
44
|
-
end
|
45
|
-
|
46
|
-
def validate_action_attributes_type_web(attrs = {})
|
47
|
-
attrs[:text] && attrs[:link_url]
|
48
|
-
end
|
49
|
-
|
50
|
-
def add_listener(attrs = {})
|
51
|
-
tap {
|
52
|
-
raise ArgumentError, 'Invalid arguments, :x, :y, :width, :height keys.' unless validate_listener_attributes(attrs)
|
53
|
-
|
54
|
-
listener = {
|
55
|
-
type: 'touch', # Fixed "touch".
|
56
|
-
params: [attrs[:x].to_i, attrs[:y].to_i, attrs[:width].to_i, attrs[:height].to_i],
|
57
|
-
action: attrs[:action].to_s,
|
58
|
-
}
|
59
|
-
@listeners << listener
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
def validate_listener_attributes(attrs = {})
|
64
|
-
attrs[:action] &&
|
65
|
-
attrs[:x] &&
|
66
|
-
attrs[:y] &&
|
67
|
-
attrs[:width] &&
|
68
|
-
attrs[:height]
|
69
|
-
end
|
70
|
-
|
71
|
-
# send rich message to line server and to users
|
72
|
-
#
|
73
|
-
# @param attrs [Hash]
|
74
|
-
# @param attrs [:to_mid] [String or Array] line user's mids
|
75
|
-
# @param attrs [:image_url] [String] image file's url
|
76
|
-
# @param attrs [:alt_text] [String] alt text for image file's url
|
77
|
-
# @raise [ArgumentError] Error raised when supplied argument are missing :to_mid, :image_url, :preview_url keys.
|
78
|
-
#
|
79
|
-
# @return [Net::HTTPResponse] response for a request to line server
|
80
|
-
def send(attrs = {})
|
81
|
-
@image_url = attrs[:image_url]
|
82
|
-
@alt_text = attrs[:alt_text]
|
83
|
-
|
84
|
-
@client.send_message(attrs[:to_mid], self)
|
85
|
-
end
|
86
|
-
|
87
|
-
def height
|
88
|
-
height = 0
|
89
|
-
@listeners.each { |listener|
|
90
|
-
h = listener[:params][1] + listener[:params][3] # params.y + params.height
|
91
|
-
height = h if height < h
|
92
|
-
}
|
93
|
-
|
94
|
-
height > 2080 ? 2080 : height
|
95
|
-
end
|
96
|
-
|
97
|
-
def event_type
|
98
|
-
Line::Bot::EventType::MESSAGE
|
99
|
-
end
|
100
|
-
|
101
|
-
def content
|
102
|
-
{
|
103
|
-
contentType: Line::Bot::Message::ContentType::RICH_MESSAGE,
|
104
|
-
toType: Line::Bot::Message::RecipientType::USER,
|
105
|
-
contentMetadata: {
|
106
|
-
DOWNLOAD_URL: @image_url,
|
107
|
-
SPEC_REV: "1", # Fixed "1".
|
108
|
-
ALT_TEXT: @alt_text,
|
109
|
-
MARKUP_JSON: markup.to_json,
|
110
|
-
},
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
|
-
def valid?
|
115
|
-
@image_url && @alt_text
|
116
|
-
end
|
117
|
-
|
118
|
-
def markup
|
119
|
-
{
|
120
|
-
canvas: {
|
121
|
-
height: height,
|
122
|
-
width: 1040, # Integer fixed value: 1040
|
123
|
-
initialScene: 'scene1',
|
124
|
-
},
|
125
|
-
images: {
|
126
|
-
image1: {
|
127
|
-
x: 0,
|
128
|
-
y: 0,
|
129
|
-
w: 1040, # Integer fixed value: 1040
|
130
|
-
h: height
|
131
|
-
},
|
132
|
-
},
|
133
|
-
actions: @actions,
|
134
|
-
scenes: {
|
135
|
-
scene1: {
|
136
|
-
draws: [
|
137
|
-
{
|
138
|
-
image: 'image1', # Use the image ID "image1".
|
139
|
-
x: 0,
|
140
|
-
y: 0,
|
141
|
-
w: 1040, # Integer fixed value: 1040
|
142
|
-
h: height
|
143
|
-
},
|
144
|
-
],
|
145
|
-
listeners: @listeners
|
146
|
-
}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
data/lib/line/bot/event_type.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Line
|
2
|
-
module Bot
|
3
|
-
module EventType
|
4
|
-
MESSAGE = 138311608800106203
|
5
|
-
MULTIPLE_MESSAGE = 140177271400161403
|
6
|
-
end
|
7
|
-
|
8
|
-
module Receive
|
9
|
-
module EventType
|
10
|
-
MESSAGE = 138311609000106303
|
11
|
-
OPERATION = 138311609100106403
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/line/bot/message.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'line/bot/message/content_type'
|
2
|
-
require 'line/bot/message/text'
|
3
|
-
require 'line/bot/message/image'
|
4
|
-
require 'line/bot/message/video'
|
5
|
-
require 'line/bot/message/audio'
|
6
|
-
require 'line/bot/message/location'
|
7
|
-
require 'line/bot/message/sticker'
|
8
|
-
require 'line/bot/message/contact'
|
9
|
-
require 'line/bot/message/recipient_type'
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'line/bot/message/base'
|
2
|
-
|
3
|
-
module Line
|
4
|
-
module Bot
|
5
|
-
module Message
|
6
|
-
class Audio < Line::Bot::Message::Base
|
7
|
-
|
8
|
-
def content
|
9
|
-
{
|
10
|
-
contentType: ContentType::AUDIO,
|
11
|
-
toType: recipient_type,
|
12
|
-
originalContentUrl: attrs[:audio_url],
|
13
|
-
contentMetadata: {
|
14
|
-
AUDLEN: attrs[:duration].to_s,
|
15
|
-
},
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def valid?
|
20
|
-
attrs[:audio_url] && attrs[:duration]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'line/bot/message/recipient_type'
|
2
|
-
|
3
|
-
module Line
|
4
|
-
module Bot
|
5
|
-
module Message
|
6
|
-
class Base
|
7
|
-
attr_reader :attrs, :recipient_type
|
8
|
-
|
9
|
-
def initialize(attrs = {})
|
10
|
-
@attrs = attrs
|
11
|
-
end
|
12
|
-
|
13
|
-
def recipient_type
|
14
|
-
@attrs[:recipient_type] ||= Line::Bot::Message::RecipientType::USER
|
15
|
-
end
|
16
|
-
|
17
|
-
def [](key)
|
18
|
-
@attrs[key]
|
19
|
-
end
|
20
|
-
|
21
|
-
def event_type
|
22
|
-
Line::Bot::EventType::MESSAGE
|
23
|
-
end
|
24
|
-
|
25
|
-
def content
|
26
|
-
raise NotImplementedError, "Implement this method in a child class"
|
27
|
-
end
|
28
|
-
|
29
|
-
def valid?
|
30
|
-
raise NotImplementedError, "Implement this method in a child class"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'line/bot/message/base'
|
2
|
-
|
3
|
-
module Line
|
4
|
-
module Bot
|
5
|
-
module Message
|
6
|
-
class Contact < Line::Bot::Message::Base
|
7
|
-
|
8
|
-
def content
|
9
|
-
raise Line::Bot::API::NotSupportedError
|
10
|
-
end
|
11
|
-
|
12
|
-
def valid?
|
13
|
-
raise Line::Bot::API::NotSupportedError
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'line/bot/message/base'
|
2
|
-
|
3
|
-
module Line
|
4
|
-
module Bot
|
5
|
-
module Message
|
6
|
-
class Image < Line::Bot::Message::Base
|
7
|
-
|
8
|
-
def content
|
9
|
-
{
|
10
|
-
contentType: ContentType::IMAGE,
|
11
|
-
toType: recipient_type,
|
12
|
-
originalContentUrl: attrs[:image_url],
|
13
|
-
previewImageUrl: attrs[:preview_url],
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
def valid?
|
18
|
-
attrs[:image_url] && attrs[:preview_url]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'line/bot/message/base'
|
2
|
-
|
3
|
-
module Line
|
4
|
-
module Bot
|
5
|
-
module Message
|
6
|
-
class Location < Line::Bot::Message::Base
|
7
|
-
|
8
|
-
def content
|
9
|
-
{
|
10
|
-
contentType: ContentType::LOCATION,
|
11
|
-
toType: recipient_type,
|
12
|
-
text: attrs[:address] || attrs[:title],
|
13
|
-
location: {
|
14
|
-
title: attrs[:title],
|
15
|
-
address: attrs[:address],
|
16
|
-
latitude: attrs[:latitude],
|
17
|
-
longitude: attrs[:longitude],
|
18
|
-
}
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def valid?
|
23
|
-
attrs[:title] && attrs[:latitude] && attrs[:longitude]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|