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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29b1b41bc20cd9dd03e408d9bf5519ba310df150d5d5b2d272f598dd46f486fd
4
- data.tar.gz: b7f48c122d3f718eef872cae8e856a4901d09f4f0a2aa2b0db77c30da4cf6bcd
3
+ metadata.gz: 4683b34a194fb0c457ce91b230377a61e40e6011cc8311d6d34fc55e4ae01fc3
4
+ data.tar.gz: '09c541649cc4d9b5fa484166f883b8011be77d5237e22af5c906d08ab0c99355'
5
5
  SHA512:
6
- metadata.gz: 691997c18880f11670d03d44b9412476ac6c3a579f4962d5657ddb46ba89b43fbc26f96c4bf3fa5db65e08a36b11e9a8bd7c62e41288654426a5bf5142062365
7
- data.tar.gz: 4c2deaae54cfe56e78b21ebd23a74f8f020954683432a370798e8fe110251953ea00d521f0cdebc52f6740e7407be97f6043f541be059a5e45a7bb014b2876e0
6
+ metadata.gz: f75e580fd0a9993776e72ffc8a3f6ff11f22224b758efbb4fd79033364167dfc883a60cfac88ec6f56d2c707f8f20a94042f9075c3b819728d0e06741c0ce6d0
7
+ data.tar.gz: 1fab9db384a613f60b16c2321281606b56ad478a8660a09143fe3da83be66820ebb209750d8fe2dc65dc123a2d7423aec93c60b2c525572fb9d7eeb73b642ee2
@@ -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:, messaging_type: "RESPONSE")
33
- page.sender_action(sender_action: sender_action, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
37
- page.show_typing(state: state, to: sender["id"], messaging_type: messaging_type)
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(messaging_type: "RESPONSE")
41
- page.mark_as_seen(to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
45
- page.send(payload_message: payload_message, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
49
- page.send_text(text: text, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
53
- page.send_youtube_video(url: url, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
57
- page.send_attachment(url: url, type: type, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
61
- page.send_image(url: url, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
65
- page.send_audio(url: url, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
69
- page.send_video(url: url, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
73
- page.send_file(url: url, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
77
- page.send_quick_replies(text: text, quick_replies: quick_replies, to: sender["id"], messaging_type: messaging_type)
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:, messaging_type: "RESPONSE")
81
- page.send_buttons(text: text, buttons: buttons, to: sender["id"], messaging_type: messaging_type)
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', messaging_type: "RESPONSE")
85
- page.send_generic(elements: elements, image_aspect_ratio: image_aspect_ratio, to: sender["id"], messaging_type: messaging_type)
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
- raise Bobot::FieldFormat.new('payload_template is required') unless payload_template.present?
39
- raise Bobot::FieldFormat.new('payload_template[:messaging_type] is required') unless payload_template.key?(:messaging_type)
40
- raise Bobot::FieldFormat.new('payload_template[:messaging_type] is invalid, only "RESPONSE, UPDATE, MESSAGE_TAG" are permitted.', payload_template[:messaging_type]) unless %w[RESPONSE UPDATE MESSAGE_TAG].include?(payload_template[:messaging_type])
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
- recipient: { id: to },
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, messaging_type: "RESPONSE")
53
- deliver(payload_template: { sender_action: sender_action, messaging_type: messaging_type }, to: to)
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, messaging_type: "RESPONSE")
57
- sender_action(sender_action: (state ? 'typing_on' : 'typing_off'), messaging_type: messaging_type, to: to)
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, messaging_type: "RESPONSE")
61
- sender_action(sender_action: 'mark_seen', messaging_type: messaging_type, to: to)
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, messaging_type: "RESPONSE")
65
- deliver(payload_template: { message: payload_message, messaging_type: messaging_type }, to: to)
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, messaging_type: "RESPONSE")
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
- messaging_type: messaging_type,
81
+ messaging_options: messaging_options,
77
82
  )
78
83
  end
79
84
 
80
- def send_attachment(url:, type:, to: nil, messaging_type: "RESPONSE")
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
- messaging_type: messaging_type,
99
+ messaging_options: messaging_options,
95
100
  )
96
101
  end
97
102
 
98
- def send_youtube_video(url:, to: nil, messaging_type: "RESPONSE")
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
- messaging_type: messaging_type,
119
+ messaging_options: messaging_options,
115
120
  )
116
121
  end
117
122
 
118
- def send_image(url:, to: nil, messaging_type: "RESPONSE")
119
- send_attachment(url: url, type: 'image', to: to, messaging_type: messaging_type)
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, messaging_type: "RESPONSE")
123
- send_attachment(url: url, type: 'audio', to: to, messaging_type: messaging_type)
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, messaging_type: "RESPONSE")
127
- send_attachment(url: url, type: 'video', to: to, messaging_type: messaging_type)
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, messaging_type: "RESPONSE")
131
- send_attachment(url: url, type: 'file', to: to, messaging_type: messaging_type)
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, messaging_type: "RESPONSE")
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
- messaging_type: messaging_type,
150
+ messaging_options: messaging_options,
146
151
  )
147
152
  end
148
153
 
149
- def send_buttons(text:, buttons:, to: nil, messaging_type: "RESPONSE")
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
- messaging_type: messaging_type,
171
+ messaging_options: messaging_options,
167
172
  )
168
173
  end
169
174
 
170
- def send_generic(elements:, image_aspect_ratio: 'square', to: nil, messaging_type: "RESPONSE")
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
- messaging_type: messaging_type,
192
+ messaging_options: messaging_options,
188
193
  )
189
194
  end
190
195
  alias_method :send_carousel, :send_generic
data/lib/bobot/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Bobot
2
2
  class Version
3
- MAJOR = 3
4
- MINOR = 7
5
- PATCH = 9
3
+ MAJOR = 4
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  PRE = nil
7
7
 
8
8
  class << self
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: 3.7.9
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-04-30 00:00:00.000000000 Z
11
+ date: 2018-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n