Class: Gupshup::REST::OutboundMessage
- Defined in:
- lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb
Instance Attribute Summary collapse
-
#apikey ⇒ Object
Returns the value of attribute apikey.
-
#app ⇒ Object
Returns the value of attribute app.
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#path ⇒ Object
Returns the value of attribute path.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(app, apikey, phone, version = '2') ⇒ OutboundMessage
constructor
A new instance of OutboundMessage.
- #send(destination, message_params) ⇒ Object
-
#send_audio(destination, url) ⇒ Object
Sends an audio.
-
#send_button(destination, content, options) ⇒ Object
Sends a button/quick reply.
-
#send_file(destination, url, filename) ⇒ Object
Sends a file.
-
#send_image(destination, image_url, preview_url, caption) ⇒ Object
Sends an image the image.
-
#send_list(destination, title, body, global_buttons, items) ⇒ Object
Sends a list.
-
#send_location(destination, longitude, latitude, name, address) ⇒ Object
Sends a location.
-
#send_sticker(destination, url) ⇒ Object
Sends a Whatsapp Sticker.
-
#send_text_message(destination, message, is_hsm = false) ⇒ Object
Sends a text.
-
#send_video(destination, url, caption) ⇒ Object
Sends a video.
Constructor Details
#initialize(app, apikey, phone, version = '2') ⇒ OutboundMessage
Returns a new instance of OutboundMessage.
7 8 9 10 11 12 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 7 def initialize(app, apikey, phone, version = '2') super @channel = 'whatsapp' @source = phone @headers = { 'Content-type' => @content_type, 'apikey' => @apikey } end |
Instance Attribute Details
#apikey ⇒ Object
Returns the value of attribute apikey.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def apikey @apikey end |
#app ⇒ Object
Returns the value of attribute app.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def app @app end |
#base_uri ⇒ Object
Returns the value of attribute base_uri.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def base_uri @base_uri end |
#content_type ⇒ Object
Returns the value of attribute content_type.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def content_type @content_type end |
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def headers @headers end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def path @path end |
#phone ⇒ Object
Returns the value of attribute phone.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def phone @phone end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 5 def version @version end |
Instance Method Details
#send(destination, message_params) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 14 def send(destination, ) # Exception handling for parameters to be added case [:type] when 'text' if [:isHSM] (destination, [:text], is_hsm = true) else (destination, [:text], is_hsm = false) end when 'sticker' send_sticker(destination, [:url]) when 'image' send_image(destination, [:originalUrl], [:previewUrl], [:caption]) when 'video' send_video(destination, [:url], [:caption]) when 'audio' send_audio(destination, [:url]) when 'file' send_file(destination, [:url], [:filename]) when 'location' send_location(destination, [:longitude], [:latitude], [:name], [:address]) when 'list' send_list(destination, [:title], [:body], [:globalButtons], [:items]) when 'quick_reply' (destination, [:content], [:options]) else puts 'Done' end end |
#send_audio(destination, url) ⇒ Object
Sends an audio
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 136 def send_audio(destination, url) payload = {'url' => url, 'type' => 'audio' }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_button(destination, content, options) ⇒ Object
Sends a button/quick reply
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 194 def (destination, content, ) uuid = UUID.new payload = { "type": 'quick_reply', "content": content, "msgid": uuid.generate, "options": }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_file(destination, url, filename) ⇒ Object
Sends a file
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 119 def send_file(destination, url, filename) payload = {'url' => url, 'type' => 'file', 'filename' => filename }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_image(destination, image_url, preview_url, caption) ⇒ Object
Sends an image the image
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 68 def send_image(destination, image_url, preview_url, caption) payload = { 'type' => 'image', 'originalUrl' => image_url, 'previewUrl' => preview_url, 'caption' => caption }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } puts payload r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_list(destination, title, body, global_buttons, items) ⇒ Object
Sends a list
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 175 def send_list(destination, title, body, , items) uuid = UUID.new payload = { "type": 'list', "title": title, "body": body, "msgid": uuid.generate , "globalButtons": [{ "type": [0][:type], "title": [0][:title] }], "items": items }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_location(destination, longitude, latitude, name, address) ⇒ Object
Sends a location
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 155 def send_location(destination, longitude, latitude, name, address) payload = { "type": 'location', "longitude": longitude, "latitude": latitude, "name": name, "address": address }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_sticker(destination, url) ⇒ Object
Sends a Whatsapp Sticker
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 82 def send_sticker(destination, url) payload = { 'type': 'sticker', 'url': url }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_text_message(destination, message, is_hsm = false) ⇒ Object
Sends a text
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 48 def (destination, , is_hsm=false) payload = {'isHSM' => is_hsm, 'type' => 'text', 'text' => }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |
#send_video(destination, url, caption) ⇒ Object
Sends a video
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gupshup_whatsapp/rest/whatsapp/message/outbound_message.rb', line 101 def send_video(destination, url, caption) payload = {'url' => url, 'type' => 'video', 'caption' => caption }.to_json data = { 'channel' => @channel, 'destination' => destination.to_s, 'source' => @source, 'src.name' => @app, 'message' => payload } r = Gupshup::HTTP::Client.new r.request(host = base_uri, port = 443, method = 'POST', url = path, data = data, headers = @headers) end |