bobot 3.7.9 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bobot/events/common.rb +28 -28
- data/lib/bobot/page.rb +44 -39
- data/lib/bobot/version.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4683b34a194fb0c457ce91b230377a61e40e6011cc8311d6d34fc55e4ae01fc3
|
4
|
+
data.tar.gz: '09c541649cc4d9b5fa484166f883b8011be77d5237e22af5c906d08ab0c99355'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f75e580fd0a9993776e72ffc8a3f6ff11f22224b758efbb4fd79033364167dfc883a60cfac88ec6f56d2c707f8f20a94042f9075c3b819728d0e06741c0ce6d0
|
7
|
+
data.tar.gz: 1fab9db384a613f60b16c2321281606b56ad478a8660a09143fe3da83be66820ebb209750d8fe2dc65dc123a2d7423aec93c60b2c525572fb9d7eeb73b642ee2
|
data/lib/bobot/events/common.rb
CHANGED
@@ -29,60 +29,60 @@ module Bobot
|
|
29
29
|
Time.zone.at(@messaging['timestamp'] / 1000)
|
30
30
|
end
|
31
31
|
|
32
|
-
def sender_action(sender_action:,
|
33
|
-
page.sender_action(sender_action: sender_action, to: sender["id"],
|
32
|
+
def sender_action(sender_action:, messaging_options: nil)
|
33
|
+
page.sender_action(sender_action: sender_action, to: sender["id"], messaging_options: messaging_options)
|
34
34
|
end
|
35
35
|
|
36
|
-
def show_typing(state:,
|
37
|
-
page.show_typing(state: state, to: sender["id"],
|
36
|
+
def show_typing(state:, messaging_options: nil)
|
37
|
+
page.show_typing(state: state, to: sender["id"], messaging_options: messaging_options)
|
38
38
|
end
|
39
39
|
|
40
|
-
def mark_as_seen(
|
41
|
-
page.mark_as_seen(to: sender["id"],
|
40
|
+
def mark_as_seen(messaging_options: nil)
|
41
|
+
page.mark_as_seen(to: sender["id"], messaging_options: messaging_options)
|
42
42
|
end
|
43
43
|
|
44
|
-
def reply(payload_message:,
|
45
|
-
page.send(payload_message: payload_message, to: sender["id"],
|
44
|
+
def reply(payload_message:, messaging_options: nil)
|
45
|
+
page.send(payload_message: payload_message, to: sender["id"], messaging_options: messaging_options)
|
46
46
|
end
|
47
47
|
|
48
|
-
def reply_with_text(text:,
|
49
|
-
page.send_text(text: text, to: sender["id"],
|
48
|
+
def reply_with_text(text:, messaging_options: nil)
|
49
|
+
page.send_text(text: text, to: sender["id"], messaging_options: messaging_options)
|
50
50
|
end
|
51
51
|
|
52
|
-
def reply_with_youtube_video(url:,
|
53
|
-
page.send_youtube_video(url: url, to: sender["id"],
|
52
|
+
def reply_with_youtube_video(url:, messaging_options: nil)
|
53
|
+
page.send_youtube_video(url: url, to: sender["id"], messaging_options: messaging_options)
|
54
54
|
end
|
55
55
|
|
56
|
-
def reply_with_attachment(url:, type:,
|
57
|
-
page.send_attachment(url: url, type: type, to: sender["id"],
|
56
|
+
def reply_with_attachment(url:, type:, messaging_options: nil)
|
57
|
+
page.send_attachment(url: url, type: type, to: sender["id"], messaging_options: messaging_options)
|
58
58
|
end
|
59
59
|
|
60
|
-
def reply_with_image(url:,
|
61
|
-
page.send_image(url: url, to: sender["id"],
|
60
|
+
def reply_with_image(url:, messaging_options: nil)
|
61
|
+
page.send_image(url: url, to: sender["id"], messaging_options: messaging_options)
|
62
62
|
end
|
63
63
|
|
64
|
-
def reply_with_audio(url:,
|
65
|
-
page.send_audio(url: url, to: sender["id"],
|
64
|
+
def reply_with_audio(url:, messaging_options: nil)
|
65
|
+
page.send_audio(url: url, to: sender["id"], messaging_options: messaging_options)
|
66
66
|
end
|
67
67
|
|
68
|
-
def reply_with_video(url:,
|
69
|
-
page.send_video(url: url, to: sender["id"],
|
68
|
+
def reply_with_video(url:, messaging_options: nil)
|
69
|
+
page.send_video(url: url, to: sender["id"], messaging_options: messaging_options)
|
70
70
|
end
|
71
71
|
|
72
|
-
def reply_with_file(url:,
|
73
|
-
page.send_file(url: url, to: sender["id"],
|
72
|
+
def reply_with_file(url:, messaging_options: nil)
|
73
|
+
page.send_file(url: url, to: sender["id"], messaging_options: messaging_options)
|
74
74
|
end
|
75
75
|
|
76
|
-
def reply_with_quick_replies(text:, quick_replies:,
|
77
|
-
page.send_quick_replies(text: text, quick_replies: quick_replies, to: sender["id"],
|
76
|
+
def reply_with_quick_replies(text:, quick_replies:, messaging_options: nil)
|
77
|
+
page.send_quick_replies(text: text, quick_replies: quick_replies, to: sender["id"], messaging_options: messaging_options)
|
78
78
|
end
|
79
79
|
|
80
|
-
def reply_with_buttons(text:, buttons:,
|
81
|
-
page.send_buttons(text: text, buttons: buttons, to: sender["id"],
|
80
|
+
def reply_with_buttons(text:, buttons:, messaging_options: nil)
|
81
|
+
page.send_buttons(text: text, buttons: buttons, to: sender["id"], messaging_options: messaging_options)
|
82
82
|
end
|
83
83
|
|
84
|
-
def reply_with_generic(elements:, image_aspect_ratio: 'square',
|
85
|
-
page.send_generic(elements: elements, image_aspect_ratio: image_aspect_ratio, to: sender["id"],
|
84
|
+
def reply_with_generic(elements:, image_aspect_ratio: 'square', messaging_options: nil)
|
85
|
+
page.send_generic(elements: elements, image_aspect_ratio: image_aspect_ratio, to: sender["id"], messaging_options: messaging_options)
|
86
86
|
end
|
87
87
|
alias_method :reply_with_carousel, :reply_with_generic
|
88
88
|
|
data/lib/bobot/page.rb
CHANGED
@@ -35,37 +35,42 @@ module Bobot
|
|
35
35
|
#####################################
|
36
36
|
|
37
37
|
def deliver(payload_template:, to:)
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
if payload_template.present?
|
39
|
+
if payload_template.key?(:messaging_options) && !payload_template[:messaging_options].nil? && payload_template[:messaging_options].key?(:messaging_type)
|
40
|
+
if !%w[RESPONSE UPDATE MESSAGE_TAG].include?(payload_template[:messaging_options][:messaging_type])
|
41
|
+
raise Bobot::FieldFormat.new('payload_template[:messaging_options][:messaging_type] is invalid, only "RESPONSE, UPDATE, MESSAGE_TAG" are permitted.', payload_template[:messaging_options][:messaging_type])
|
42
|
+
elsif "MESSAGE_TAG" == payload_template[:messaging_options][:messaging_type] && !payload_template[:messaging_options].key?(:tag)
|
43
|
+
raise Bobot::FieldFormat.new('payload_template[:messaging_options][:key] is required when messaging_type is MESSAGE_TAG.', payload_template[:messaging_options][:tag])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
raise Bobot::FieldFormat.new('payload_template is required')
|
48
|
+
end
|
49
|
+
body = { recipient: { id: to }, messaging_type: "RESPONSE" }.merge(payload_template).merge(payload_template[:messaging_options] || {})
|
50
|
+
query = { access_token: page_access_token }
|
41
51
|
Bobot::Commander.deliver(
|
42
|
-
body:
|
43
|
-
|
44
|
-
messaging_type: "RESPONSE",
|
45
|
-
}.merge(payload_template),
|
46
|
-
query: {
|
47
|
-
access_token: page_access_token,
|
48
|
-
},
|
52
|
+
body: body,
|
53
|
+
query: query,
|
49
54
|
)
|
50
55
|
end
|
51
|
-
|
52
|
-
def sender_action(sender_action:, to: nil,
|
53
|
-
deliver(payload_template: { sender_action: sender_action,
|
56
|
+
|
57
|
+
def sender_action(sender_action:, to: nil, messaging_options: nil)
|
58
|
+
deliver(payload_template: { sender_action: sender_action, messaging_options: messaging_options }, to: to)
|
54
59
|
end
|
55
60
|
|
56
|
-
def show_typing(state:, to: nil,
|
57
|
-
sender_action(sender_action: (state ? 'typing_on' : 'typing_off'),
|
61
|
+
def show_typing(state:, to: nil, messaging_options: nil)
|
62
|
+
sender_action(sender_action: (state ? 'typing_on' : 'typing_off'), messaging_options: messaging_options, to: to)
|
58
63
|
end
|
59
64
|
|
60
|
-
def mark_as_seen(to: nil,
|
61
|
-
sender_action(sender_action: 'mark_seen',
|
65
|
+
def mark_as_seen(to: nil, messaging_options: nil)
|
66
|
+
sender_action(sender_action: 'mark_seen', messaging_options: messaging_options, to: to)
|
62
67
|
end
|
63
68
|
|
64
|
-
def send(payload_message:, to: nil,
|
65
|
-
deliver(payload_template: { message: payload_message,
|
69
|
+
def send(payload_message:, to: nil, messaging_options: nil)
|
70
|
+
deliver(payload_template: { message: payload_message, messaging_options: messaging_options }, to: to)
|
66
71
|
end
|
67
72
|
|
68
|
-
def send_text(text:, to: nil,
|
73
|
+
def send_text(text:, to: nil, messaging_options: nil)
|
69
74
|
raise Bobot::FieldFormat.new('text is required') unless text.present?
|
70
75
|
raise Bobot::FieldFormat.new('text size is limited to 640.', "#{text} (#{text.size} chars)") if text.size > 640
|
71
76
|
send(
|
@@ -73,11 +78,11 @@ module Bobot
|
|
73
78
|
text: text,
|
74
79
|
},
|
75
80
|
to: to,
|
76
|
-
|
81
|
+
messaging_options: messaging_options,
|
77
82
|
)
|
78
83
|
end
|
79
84
|
|
80
|
-
def send_attachment(url:, type:, to: nil,
|
85
|
+
def send_attachment(url:, type:, to: nil, messaging_options: nil)
|
81
86
|
raise Bobot::FieldFormat.new('url is required') unless url.present?
|
82
87
|
raise Bobot::FieldFormat.new('type is required') unless type.present?
|
83
88
|
raise Bobot::FieldFormat.new('type is invalid, only "image, audio, video, file" are permitted.', type) unless %w[image audio video file].include?(type)
|
@@ -91,11 +96,11 @@ module Bobot
|
|
91
96
|
},
|
92
97
|
},
|
93
98
|
to: to,
|
94
|
-
|
99
|
+
messaging_options: messaging_options,
|
95
100
|
)
|
96
101
|
end
|
97
102
|
|
98
|
-
def send_youtube_video(url:, to: nil,
|
103
|
+
def send_youtube_video(url:, to: nil, messaging_options: nil)
|
99
104
|
raise Bobot::FieldFormat.new('url is required') unless url.present?
|
100
105
|
raise Bobot::FieldFormat.new('url is not valid', url) unless url =~ %r{^(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?([\w-]{10,})}
|
101
106
|
send(
|
@@ -111,27 +116,27 @@ module Bobot
|
|
111
116
|
},
|
112
117
|
},
|
113
118
|
to: to,
|
114
|
-
|
119
|
+
messaging_options: messaging_options,
|
115
120
|
)
|
116
121
|
end
|
117
122
|
|
118
|
-
def send_image(url:, to: nil,
|
119
|
-
send_attachment(url: url, type: 'image', to: to,
|
123
|
+
def send_image(url:, to: nil, messaging_options: nil)
|
124
|
+
send_attachment(url: url, type: 'image', to: to, messaging_options: messaging_options)
|
120
125
|
end
|
121
126
|
|
122
|
-
def send_audio(url:, to: nil,
|
123
|
-
send_attachment(url: url, type: 'audio', to: to,
|
127
|
+
def send_audio(url:, to: nil, messaging_options: nil)
|
128
|
+
send_attachment(url: url, type: 'audio', to: to, messaging_options: messaging_options)
|
124
129
|
end
|
125
130
|
|
126
|
-
def send_video(url:, to: nil,
|
127
|
-
send_attachment(url: url, type: 'video', to: to,
|
131
|
+
def send_video(url:, to: nil, messaging_options: nil)
|
132
|
+
send_attachment(url: url, type: 'video', to: to, messaging_options: messaging_options)
|
128
133
|
end
|
129
134
|
|
130
|
-
def send_file(url:, to: nil,
|
131
|
-
send_attachment(url: url, type: 'file', to: to,
|
135
|
+
def send_file(url:, to: nil, messaging_options: nil)
|
136
|
+
send_attachment(url: url, type: 'file', to: to, messaging_options: messaging_options)
|
132
137
|
end
|
133
138
|
|
134
|
-
def send_quick_replies(text:, quick_replies:, to: nil,
|
139
|
+
def send_quick_replies(text:, quick_replies:, to: nil, messaging_options: nil)
|
135
140
|
raise Bobot::FieldFormat.new('text is required') unless text.present?
|
136
141
|
raise Bobot::FieldFormat.new('text size is limited to 640.', "#{text} (#{text.size} chars)") if text.size > 640
|
137
142
|
raise Bobot::FieldFormat.new('quick_replies are required') unless quick_replies.present?
|
@@ -142,11 +147,11 @@ module Bobot
|
|
142
147
|
quick_replies: quick_replies,
|
143
148
|
},
|
144
149
|
to: to,
|
145
|
-
|
150
|
+
messaging_options: messaging_options,
|
146
151
|
)
|
147
152
|
end
|
148
153
|
|
149
|
-
def send_buttons(text:, buttons:, to: nil,
|
154
|
+
def send_buttons(text:, buttons:, to: nil, messaging_options: nil)
|
150
155
|
raise Bobot::FieldFormat.new('text is required') unless text.present?
|
151
156
|
raise Bobot::FieldFormat.new('text size is limited to 640.', "#{text} (#{text.size} chars)") if text.size > 640
|
152
157
|
raise Bobot::FieldFormat.new('buttons are required') unless buttons.present?
|
@@ -163,11 +168,11 @@ module Bobot
|
|
163
168
|
},
|
164
169
|
},
|
165
170
|
to: to,
|
166
|
-
|
171
|
+
messaging_options: messaging_options,
|
167
172
|
)
|
168
173
|
end
|
169
174
|
|
170
|
-
def send_generic(elements:, image_aspect_ratio: 'square', to: nil,
|
175
|
+
def send_generic(elements:, image_aspect_ratio: 'square', to: nil, messaging_options: nil)
|
171
176
|
raise Bobot::FieldFormat.new('elements are required') if elements.nil?
|
172
177
|
raise Bobot::FieldFormat.new('elements are limited to 10.', "#{elements.size} elements") if elements.size > 10
|
173
178
|
raise Bobot::FieldFormat.new('image_aspect_ratio is required') if image_aspect_ratio.nil?
|
@@ -184,7 +189,7 @@ module Bobot
|
|
184
189
|
},
|
185
190
|
},
|
186
191
|
to: to,
|
187
|
-
|
192
|
+
messaging_options: messaging_options,
|
188
193
|
)
|
189
194
|
end
|
190
195
|
alias_method :send_carousel, :send_generic
|
data/lib/bobot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bobot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Navid EMAD
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|