Class: Whatsapp::RecordProxy
- Inherits:
-
Object
- Object
- Whatsapp::RecordProxy
- Defined in:
- lib/whatsapp/record_proxy.rb
Overview
Proxy for sending messages to a specific phone number.
Created by the +whatsapp+ model macro in destination mode (default). All messages are sent to the phone number bound to this proxy.
Instance Attribute Summary collapse
-
#phone_number ⇒ String
readonly
The phone number this proxy sends to.
Instance Method Summary collapse
-
#initialize(phone_number) ⇒ RecordProxy
constructor
A new instance of RecordProxy.
-
#mark_as_read(message_ids) ⇒ Hash
Mark messages from this contact as read.
-
#react(message_id:, emoji:) ⇒ Message
React to a message with an emoji.
-
#reply(quoted_message_id:, text: nil, media: nil) ⇒ Message
Reply to a message (quoted reply).
-
#send_audio(file) ⇒ Message
Send an audio file.
-
#send_composing ⇒ Hash
Send a "composing" (typing) indicator to this contact.
-
#send_contact(name:, phone:) ⇒ Message
Send a contact card.
-
#send_document(file, filename: nil, caption: nil) ⇒ Message
Send a document.
-
#send_document_later(file, filename: nil, caption: nil) ⇒ void
Send a document asynchronously via ActiveJob.
-
#send_image(file, caption: nil) ⇒ Message
Send an image.
-
#send_image_later(file, caption: nil) ⇒ void
Send an image asynchronously via ActiveJob.
-
#send_later(text) ⇒ void
Send a text message asynchronously via ActiveJob.
-
#send_location(latitude:, longitude:, name: nil, address: nil) ⇒ Message
Send a location.
-
#send_message(text) ⇒ Message
Send a text message.
-
#send_paused ⇒ Hash
Clear the typing/recording indicator for this contact.
-
#send_poll(question:, options:, selectable_count: 1) ⇒ Message
Send a poll to this contact.
-
#send_recording ⇒ Hash
Send a "recording" (audio) indicator to this contact.
-
#send_sticker(file) ⇒ Message
Send a sticker.
-
#send_video(file, caption: nil) ⇒ Message
Send a video.
Constructor Details
#initialize(phone_number) ⇒ RecordProxy
Returns a new instance of RecordProxy.
18 19 20 |
# File 'lib/whatsapp/record_proxy.rb', line 18 def initialize(phone_number) @phone_number = phone_number end |
Instance Attribute Details
#phone_number ⇒ String (readonly)
Returns the phone number this proxy sends to.
15 16 17 |
# File 'lib/whatsapp/record_proxy.rb', line 15 def phone_number @phone_number end |
Instance Method Details
#mark_as_read(message_ids) ⇒ Hash
Mark messages from this contact as read.
156 157 158 159 160 |
# File 'lib/whatsapp/record_proxy.rb', line 156 def mark_as_read() ids = Array() keys = ids.map { |id| {remote_jid: phone_number, id: id} } client.(keys) end |
#react(message_id:, emoji:) ⇒ Message
React to a message with an emoji.
102 103 104 |
# File 'lib/whatsapp/record_proxy.rb', line 102 def react(message_id:, emoji:) client.(to: phone_number, react: {emoji: emoji, message_id: }) end |
#reply(quoted_message_id:, text: nil, media: nil) ⇒ Message
Reply to a message (quoted reply).
112 113 114 |
# File 'lib/whatsapp/record_proxy.rb', line 112 def reply(quoted_message_id:, text: nil, media: nil) client.(to: phone_number, text: text, media: media, quoted_message_id: ) end |
#send_audio(file) ⇒ Message
Send an audio file.
62 63 64 |
# File 'lib/whatsapp/record_proxy.rb', line 62 def send_audio(file) send_media(:audio, file) end |
#send_composing ⇒ Hash
Send a "composing" (typing) indicator to this contact.
134 135 136 |
# File 'lib/whatsapp/record_proxy.rb', line 134 def send_composing client.send_presence("composing", to: phone_number) end |
#send_contact(name:, phone:) ⇒ Message
Send a contact card.
93 94 95 |
# File 'lib/whatsapp/record_proxy.rb', line 93 def send_contact(name:, phone:) client.(to: phone_number, contact: {name: name, phone: phone}) end |
#send_document(file, filename: nil, caption: nil) ⇒ Message
Send a document.
45 46 47 |
# File 'lib/whatsapp/record_proxy.rb', line 45 def send_document(file, filename: nil, caption: nil) send_media(:document, file, filename: filename, caption: caption) end |
#send_document_later(file, filename: nil, caption: nil) ⇒ void
This method returns an undefined value.
Send a document asynchronously via ActiveJob.
193 194 195 196 197 198 199 |
# File 'lib/whatsapp/record_proxy.rb', line 193 def send_document_later(file, filename: nil, caption: nil) ensure_active_job! WhatsappSendJob.perform_later( to: phone_number, media: {type: "document", file: file, filename: filename, caption: caption} ) end |
#send_image(file, caption: nil) ⇒ Message
Send an image.
35 36 37 |
# File 'lib/whatsapp/record_proxy.rb', line 35 def send_image(file, caption: nil) send_media(:image, file, caption: caption) end |
#send_image_later(file, caption: nil) ⇒ void
This method returns an undefined value.
Send an image asynchronously via ActiveJob.
178 179 180 181 182 183 184 |
# File 'lib/whatsapp/record_proxy.rb', line 178 def send_image_later(file, caption: nil) ensure_active_job! WhatsappSendJob.perform_later( to: phone_number, media: {type: "image", file: file, caption: caption} ) end |
#send_later(text) ⇒ void
This method returns an undefined value.
Send a text message asynchronously via ActiveJob.
167 168 169 170 |
# File 'lib/whatsapp/record_proxy.rb', line 167 def send_later(text) ensure_active_job! WhatsappSendJob.perform_later(to: phone_number, text: text) end |
#send_location(latitude:, longitude:, name: nil, address: nil) ⇒ Message
Send a location.
81 82 83 84 85 86 |
# File 'lib/whatsapp/record_proxy.rb', line 81 def send_location(latitude:, longitude:, name: nil, address: nil) client.( to: phone_number, location: {latitude: latitude, longitude: longitude, name: name, address: address} ) end |
#send_message(text) ⇒ Message
Send a text message.
26 27 28 |
# File 'lib/whatsapp/record_proxy.rb', line 26 def (text) client.(to: phone_number, text: text) end |
#send_paused ⇒ Hash
Clear the typing/recording indicator for this contact.
148 149 150 |
# File 'lib/whatsapp/record_proxy.rb', line 148 def send_paused client.send_presence("paused", to: phone_number) end |
#send_poll(question:, options:, selectable_count: 1) ⇒ Message
Send a poll to this contact.
122 123 124 125 126 127 |
# File 'lib/whatsapp/record_proxy.rb', line 122 def send_poll(question:, options:, selectable_count: 1) client.( to: phone_number, poll: {question: question, options: , selectable_count: selectable_count} ) end |
#send_recording ⇒ Hash
Send a "recording" (audio) indicator to this contact.
141 142 143 |
# File 'lib/whatsapp/record_proxy.rb', line 141 def send_recording client.send_presence("recording", to: phone_number) end |
#send_sticker(file) ⇒ Message
Send a sticker.
70 71 72 |
# File 'lib/whatsapp/record_proxy.rb', line 70 def send_sticker(file) send_media(:sticker, file) end |
#send_video(file, caption: nil) ⇒ Message
Send a video.
54 55 56 |
# File 'lib/whatsapp/record_proxy.rb', line 54 def send_video(file, caption: nil) send_media(:video, file, caption: caption) end |