Class: VoiceML::MessagesResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- VoiceML::MessagesResource
- Defined in:
- lib/voiceml/resources/messages.rb
Overview
Operations on ‘/Messages` — VoiceTel’s Twilio-compatible SMS surface, backed by the SDK 2.2 gateway. Outbound-only today (no MMS, no inbound webhook delivery).
All methods accept idiomatic snake_case keyword arguments — they’re translated to the PascalCase wire names internally.
Constant Summary collapse
- CREATE_FIELDS =
{ 'To' => :to, 'Body' => :body, 'From' => :from, 'MessagingServiceSid' => :messaging_service_sid, 'StatusCallback' => :status_callback }.freeze
- LIST_FIELDS =
{ 'To' => :to, 'From' => :from, 'DateSent' => :date_sent, 'DateSent<' => :date_sent_lt, 'DateSent>' => :date_sent_gt, 'Page' => :page, 'PageSize' => :page_size, 'PageToken' => :page_token }.freeze
- UPDATE_FIELDS =
{ 'Body' => :body, 'Status' => :status }.freeze
Instance Method Summary collapse
-
#create(**kwargs) ⇒ VoiceML::Message
Dispatch an outbound SMS.
-
#delete(sid) ⇒ nil
Remove a Message resource from the account’s store.
-
#each(**kwargs) {|VoiceML::Message| ... } ⇒ Enumerator<VoiceML::Message>
Walk every page of /Messages and yield each Message.
-
#fetch(sid) ⇒ VoiceML::Message
Retrieve a previously-sent Message by sid.
-
#list(**kwargs) ⇒ VoiceML::MessageList
Return a single page of Messages, narrowed by the Twilio-documented filter set (To, From, DateSent eq/gt/lt) plus pagination.
-
#update(sid, **kwargs) ⇒ VoiceML::Message
Mutate an existing Message — redact ‘body:` to empty string, or attempt `status: “canceled”`.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from VoiceML::BaseResource
Instance Method Details
#create(**kwargs) ⇒ VoiceML::Message
Dispatch an outbound SMS. ‘to:` and `body:` are required; `from:` falls back to the tenant’s configured default sender when omitted.
42 43 44 45 |
# File 'lib/voiceml/resources/messages.rb', line 42 def create(**kwargs) data = @transport.request(:post, path('Messages'), form: form_params(CREATE_FIELDS, kwargs)) Message.from_hash(data) end |
#delete(sid) ⇒ nil
Remove a Message resource from the account’s store.
96 97 98 99 |
# File 'lib/voiceml/resources/messages.rb', line 96 def delete(sid) @transport.request(:delete, path('Messages', sid)) nil end |
#each(**kwargs) {|VoiceML::Message| ... } ⇒ Enumerator<VoiceML::Message>
Walk every page of /Messages and yield each Message. Returns an Enumerator when called without a block.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/voiceml/resources/messages.rb', line 69 def each(**kwargs, &block) return enum_for(:each, **kwargs) unless block page_num = kwargs.delete(:page) || 0 loop do chunk = list(**kwargs, page: page_num) chunk..each(&block) break if chunk.next_page_uri.nil? || chunk.next_page_uri.empty? || chunk..empty? page_num += 1 end end |
#fetch(sid) ⇒ VoiceML::Message
Retrieve a previously-sent Message by sid.
50 51 52 |
# File 'lib/voiceml/resources/messages.rb', line 50 def fetch(sid) Message.from_hash(@transport.request(:get, path('Messages', sid))) end |
#list(**kwargs) ⇒ VoiceML::MessageList
Return a single page of Messages, narrowed by the Twilio-documented filter set (To, From, DateSent eq/gt/lt) plus pagination.
58 59 60 61 62 |
# File 'lib/voiceml/resources/messages.rb', line 58 def list(**kwargs) MessageList.from_hash( @transport.request(:get, path('Messages'), params: form_params(LIST_FIELDS, kwargs)) ) end |
#update(sid, **kwargs) ⇒ VoiceML::Message
Mutate an existing Message — redact ‘body:` to empty string, or attempt `status: “canceled”`. Cancellation returns 21610 today because the gateway is fire-and-forget.
87 88 89 90 91 |
# File 'lib/voiceml/resources/messages.rb', line 87 def update(sid, **kwargs) data = @transport.request(:post, path('Messages', sid), form: form_params(UPDATE_FIELDS, kwargs)) Message.from_hash(data) end |