Class: Blueticks::Resources::MessagesResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Blueticks::Resources::MessagesResource
- Defined in:
- lib/blueticks/resources/messages.rb
Instance Attribute Summary
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#batch_acks(message_keys:, chat_id: nil) ⇒ Object
Batch get delivery status for up to 200 sent messages.
-
#create(chat_id, type:, text: nil, media_url: nil, media_base64: nil, media_kind: nil, media_filename: nil, poll_question: nil, poll_options: nil, poll_allow_multiple: nil, reply_to: nil, secret: nil, with_typing: nil, typing_seconds: nil, idempotency_key: nil) ⇒ Object
Send a message immediately to a chat (direct dispatch — no queue row is persisted for the wait; the response carries the WhatsApp wire key).
-
#get_ack(wa_message_key, chat_id: nil) ⇒ Object
Get delivery acknowledgement for a single message.
-
#get_media(wa_message_key, chat_id: nil, max_attempts: nil) ⇒ Object
Fetch media (URL and/or base64 bytes) for a message.
-
#list(chat_id: nil, search_token: nil, order: nil, since: nil, until_: nil, message_types: nil, load_from_phone_if_needed: nil, include_media_content: nil, skip: nil, limit: nil) ⇒ Object
Query messages from the WhatsApp store, newest first.
-
#load_older(chat_id) ⇒ Object
Ask the engine to pull older history from the connected phone.
-
#pin(wa_message_key, chat_id: nil, duration: nil) ⇒ Object
Pin a message.
-
#pinned(chat_id) ⇒ Object
List the pinned messages in a chat.
-
#react(wa_message_key, emoji:, chat_id: nil) ⇒ Object
React to a message.
-
#retrieve(wa_message_key, chat_id: nil) ⇒ Object
Retrieve a single store message by its serialized wire key.
-
#unpin(wa_message_key, chat_id: nil) ⇒ Object
Unpin a message.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Blueticks::BaseResource
Instance Method Details
#batch_acks(message_keys:, chat_id: nil) ⇒ Object
Batch get delivery status for up to 200 sent messages. Offset-paginated (BatchAckEntry rows).
49 50 51 52 53 54 |
# File 'lib/blueticks/resources/messages.rb', line 49 def batch_acks(message_keys:, chat_id: nil) body = { "messageKeys" => } body["chatId"] = chat_id unless chat_id.nil? env = client.request("POST", "/v1/messages/acks", body: body) Types::PaginatedPage.from_hash(env, item_type: Types::BatchAckEntry) end |
#create(chat_id, type:, text: nil, media_url: nil, media_base64: nil, media_kind: nil, media_filename: nil, poll_question: nil, poll_options: nil, poll_allow_multiple: nil, reply_to: nil, secret: nil, with_typing: nil, typing_seconds: nil, idempotency_key: nil) ⇒ Object
Send a message immediately to a chat (direct dispatch — no queue row is
persisted for the wait; the response carries the WhatsApp wire key). The
body is a discriminated union keyed on type (text, media, poll).
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/blueticks/resources/messages.rb', line 105 def create(chat_id, type:, text: nil, media_url: nil, media_base64: nil, media_kind: nil, media_filename: nil, poll_question: nil, poll_options: nil, poll_allow_multiple: nil, reply_to: nil, secret: nil, with_typing: nil, typing_seconds: nil, idempotency_key: nil) body = { "type" => type } body["text"] = text unless text.nil? body["mediaUrl"] = media_url unless media_url.nil? body["mediaBase64"] = media_base64 unless media_base64.nil? body["mediaKind"] = media_kind unless media_kind.nil? body["mediaFilename"] = media_filename unless media_filename.nil? body["pollQuestion"] = poll_question unless poll_question.nil? body["pollOptions"] = unless .nil? body["pollAllowMultiple"] = poll_allow_multiple unless poll_allow_multiple.nil? body["replyTo"] = reply_to unless reply_to.nil? body["secret"] = secret unless secret.nil? body["withTyping"] = with_typing unless with_typing.nil? body["typingSeconds"] = typing_seconds unless typing_seconds.nil? env = client.request("POST", "/v1/messages/#{chat_id}", body: body, idempotency_key: idempotency_key) Types::Message.from_hash(env && env["data"]) end |
#get_ack(wa_message_key, chat_id: nil) ⇒ Object
Get delivery acknowledgement for a single message.
41 42 43 44 45 |
# File 'lib/blueticks/resources/messages.rb', line 41 def get_ack(, chat_id: nil) params = chat_id.nil? ? nil : { "chatId" => chat_id } env = client.request("GET", "/v1/messages/ack/#{}", params: params) Types::MessageAck.from_hash(env && env["data"]) end |
#get_media(wa_message_key, chat_id: nil, max_attempts: nil) ⇒ Object
Fetch media (URL and/or base64 bytes) for a message.
63 64 65 66 67 68 69 70 |
# File 'lib/blueticks/resources/messages.rb', line 63 def get_media(, chat_id: nil, max_attempts: nil) params = {} params["chatId"] = chat_id unless chat_id.nil? params["maxAttempts"] = max_attempts unless max_attempts.nil? env = client.request("GET", "/v1/messages/media/#{}", params: params.empty? ? nil : params) Types::Media.from_hash(env && env["data"]) end |
#list(chat_id: nil, search_token: nil, order: nil, since: nil, until_: nil, message_types: nil, load_from_phone_if_needed: nil, include_media_content: nil, skip: nil, limit: nil) ⇒ Object
Query messages from the WhatsApp store, newest first. Offset-paginated
(PublicMessage rows). message_types is an Array of wire message types
(e.g. %w[chat image]).
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blueticks/resources/messages.rb', line 14 def list(chat_id: nil, search_token: nil, order: nil, since: nil, until_: nil, message_types: nil, load_from_phone_if_needed: nil, include_media_content: nil, skip: nil, limit: nil) params = {} params["chatId"] = chat_id unless chat_id.nil? params["searchToken"] = search_token unless search_token.nil? params["order"] = order unless order.nil? params["since"] = since unless since.nil? params["until"] = until_ unless until_.nil? params["messageTypes"] = .join(",") if && !.empty? params["loadFromPhoneIfNeeded"] = load_from_phone_if_needed unless load_from_phone_if_needed.nil? params["includeMediaContent"] = include_media_content unless include_media_content.nil? params["skip"] = skip unless skip.nil? params["limit"] = limit unless limit.nil? env = client.request("GET", "/v1/messages", params: params.empty? ? nil : params) Types::PaginatedPage.from_hash(env, item_type: Types::PublicMessage) end |
#load_older(chat_id) ⇒ Object
Ask the engine to pull older history from the connected phone.
57 58 59 60 |
# File 'lib/blueticks/resources/messages.rb', line 57 def load_older(chat_id) env = client.request("POST", "/v1/messages/load_older/#{chat_id}") Types::LoadOlderResult.from_hash(env && env["data"]) end |
#pin(wa_message_key, chat_id: nil, duration: nil) ⇒ Object
Pin a message. Optional duration (seconds) sets the pin TTL.
73 74 75 76 77 78 79 |
# File 'lib/blueticks/resources/messages.rb', line 73 def pin(, chat_id: nil, duration: nil) params = chat_id.nil? ? nil : { "chatId" => chat_id } body = {} body["duration"] = duration unless duration.nil? env = client.request("POST", "/v1/messages/pin/#{}", params: params, body: body) Types::OkResult.from_hash(env && env["data"]) end |
#pinned(chat_id) ⇒ Object
List the pinned messages in a chat. Offset-paginated (PinnedMessage rows).
89 90 91 92 |
# File 'lib/blueticks/resources/messages.rb', line 89 def pinned(chat_id) env = client.request("GET", "/v1/messages/pinned/#{chat_id}") Types::PaginatedPage.from_hash(env, item_type: Types::PinnedMessage) end |
#react(wa_message_key, emoji:, chat_id: nil) ⇒ Object
React to a message. Pass an empty emoji string to remove a reaction.
95 96 97 98 99 100 |
# File 'lib/blueticks/resources/messages.rb', line 95 def react(, emoji:, chat_id: nil) params = chat_id.nil? ? nil : { "chatId" => chat_id } env = client.request("POST", "/v1/messages/reactions/#{}", params: params, body: { "emoji" => emoji }) Types::OkResult.from_hash(env && env["data"]) end |
#retrieve(wa_message_key, chat_id: nil) ⇒ Object
Retrieve a single store message by its serialized wire key. Pass
chat_id to scope the lookup.
34 35 36 37 38 |
# File 'lib/blueticks/resources/messages.rb', line 34 def retrieve(, chat_id: nil) params = chat_id.nil? ? nil : { "chatId" => chat_id } env = client.request("GET", "/v1/messages/#{}", params: params) Types::PublicMessage.from_hash(env && env["data"]) end |
#unpin(wa_message_key, chat_id: nil) ⇒ Object
Unpin a message.
82 83 84 85 86 |
# File 'lib/blueticks/resources/messages.rb', line 82 def unpin(, chat_id: nil) params = chat_id.nil? ? nil : { "chatId" => chat_id } env = client.request("POST", "/v1/messages/unpin/#{}", params: params) Types::OkResult.from_hash(env && env["data"]) end |