Class: Telnyx::Resources::EmailInboxes::Drafts

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/email_inboxes/drafts.rb,
sig/telnyx/resources/email_inboxes/drafts.rbs

Overview

Create, list, retrieve, update, delete, and send unsent draft messages belonging to an agent inbox.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Drafts

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Drafts.

Parameters:



323
324
325
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 323

def initialize(client:)
  @client = client
end

Instance Method Details

#create(inbox_id, attachments: nil, bcc: nil, cc: nil, from_email: nil, from_name: nil, headers: nil, html: nil, html_body: nil, labels: nil, metadata: nil, reply_to: nil, subject: nil, tags: nil, text: nil, text_body: nil, to: nil, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::EmailDraftResponse

Creates an unsent draft in the inbox. Every field is optional — a draft is a work-in-progress and may be saved incomplete. Send-time requirements (sender, subject, at least one recipient) are enforced when the draft is sent, not when it is created.

Drafts are unbillable and emit no Email Detail Records until they are sent.

Parameters:

Returns:

See Also:



57
58
59
60
61
62
63
64
65
66
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 57

def create(inbox_id, params = {})
  parsed, options = Telnyx::EmailInboxes::DraftCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["email_inboxes/%1$s/drafts", inbox_id],
    body: parsed,
    model: Telnyx::EmailInboxes::EmailDraftResponse,
    options: options
  )
end

#delete(draft_id, inbox_id:, request_options: {}) ⇒ nil

Permanently deletes an unsent draft. Drafts that are being sent or have been sent cannot be deleted; sent drafts are retained for audit.

Parameters:

  • draft_id (String)

    Email draft UUID.

  • inbox_id (String)

    Email inbox UUID.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 210

def delete(draft_id, params)
  parsed, options = Telnyx::EmailInboxes::DraftDeleteParams.dump_request(params)
  inbox_id =
    parsed.delete(:inbox_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["email_inboxes/%1$s/drafts/%2$s", inbox_id, draft_id],
    model: NilClass,
    options: options
  )
end

#list(inbox_id, filter_status: nil, page_after: nil, page_size: nil, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::DraftListResponse

Lists drafts newest first using stable cursor pagination. All access is scoped to the authenticated account and the given inbox.

Parameters:

Returns:

See Also:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 180

def list(inbox_id, params = {})
  parsed, options = Telnyx::EmailInboxes::DraftListParams.dump_request(params)
  query = Telnyx::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["email_inboxes/%1$s/drafts", inbox_id],
    query: query.transform_keys(
      filter_status: "filter[status]",
      page_after: "page[after]",
      page_size: "page[size]"
    ),
    model: Telnyx::Models::EmailInboxes::DraftListResponse,
    options: options
  )
end

#patch(draft_id, inbox_id:, attachments: nil, bcc: nil, cc: nil, from_email: nil, from_name: nil, headers: nil, html: nil, html_body: nil, labels: nil, metadata: nil, reply_to: nil, subject: nil, tags: nil, text: nil, text_body: nil, to: nil, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::EmailDraftResponse

Identical to PUT; both apply a partial update to the supplied fields.

Parameters:

  • draft_id (String)

    Path param: Email draft UUID.

  • inbox_id (String)

    Path param: Email inbox UUID.

  • attachments (Array<Object>)

    Body param

  • bcc (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • cc (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • from_email (String)

    Body param

  • from_name (String)

    Body param

  • headers (Hash{Symbol=>String})

    Body param

  • html (String)

    Body param: Alias for html_body, matching the send endpoint.

  • html_body (String)

    Body param

  • labels (Array<String>)

    Body param

  • metadata (Object)

    Body param

  • reply_to (String)

    Body param

  • subject (String)

    Body param

  • tags (Array<String>)

    Body param

  • text (String)

    Body param: Alias for text_body, matching the send endpoint.

  • text_body (String)

    Body param

  • to (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 269

def patch(draft_id, params)
  parsed, options = Telnyx::EmailInboxes::DraftPatchParams.dump_request(params)
  inbox_id =
    parsed.delete(:inbox_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :patch,
    path: ["email_inboxes/%1$s/drafts/%2$s", inbox_id, draft_id],
    body: parsed,
    model: Telnyx::EmailInboxes::EmailDraftResponse,
    options: options
  )
end

#retrieve(draft_id, inbox_id:, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::EmailDraftResponse

Returns a single draft. Drafts that have been sent remain retrievable, so the exact content that was sent stays auditable.

Parameters:

  • draft_id (String)

    Email draft UUID.

  • inbox_id (String)

    Email inbox UUID.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 82

def retrieve(draft_id, params)
  parsed, options = Telnyx::EmailInboxes::DraftRetrieveParams.dump_request(params)
  inbox_id =
    parsed.delete(:inbox_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["email_inboxes/%1$s/drafts/%2$s", inbox_id, draft_id],
    model: Telnyx::EmailInboxes::EmailDraftResponse,
    options: options
  )
end

#send_(draft_id, inbox_id:, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::EmailMessageResponse

Sends the draft through the standard send pipeline — the same domain resolution, suppression, reputation, daily-quota, persistence and Detail Record behaviour as POST /v2/email_messages. The response body is the created email message.

If the draft has no explicit from_email, the inbox address is used.

The draft is marked sent only after the send is accepted; a send rejected for suppression, quota or reputation leaves the draft editable so it can be fixed and retried. A draft that is already sent returns 422 rather than sending twice.

Parameters:

  • draft_id (String)

    Email draft UUID.

  • inbox_id (String)

    Email inbox UUID.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 306

def send_(draft_id, params)
  parsed, options = Telnyx::EmailInboxes::DraftSendParams.dump_request(params)
  inbox_id =
    parsed.delete(:inbox_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["email_inboxes/%1$s/drafts/%2$s/send", inbox_id, draft_id],
    model: Telnyx::EmailInboxes::EmailMessageResponse,
    options: options
  )
end

#update(draft_id, inbox_id:, attachments: nil, bcc: nil, cc: nil, from_email: nil, from_name: nil, headers: nil, html: nil, html_body: nil, labels: nil, metadata: nil, reply_to: nil, subject: nil, tags: nil, text: nil, text_body: nil, to: nil, request_options: {}) ⇒ Telnyx::Models::EmailInboxes::EmailDraftResponse

Updates the supplied fields on a draft. account_id and inbox_id are server-owned and ignored if present in the body, so a draft can never be moved between accounts or inboxes.

A draft that is being sent or has already been sent is immutable and returns 422 — modifying it would race with delivery or rewrite the record of what was actually sent.

Parameters:

  • draft_id (String)

    Path param: Email draft UUID.

  • inbox_id (String)

    Path param: Email inbox UUID.

  • attachments (Array<Object>)

    Body param

  • bcc (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • cc (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • from_email (String)

    Body param

  • from_name (String)

    Body param

  • headers (Hash{Symbol=>String})

    Body param

  • html (String)

    Body param: Alias for html_body, matching the send endpoint.

  • html_body (String)

    Body param

  • labels (Array<String>)

    Body param

  • metadata (Object)

    Body param

  • reply_to (String)

    Body param

  • subject (String)

    Body param

  • tags (Array<String>)

    Body param

  • text (String)

    Body param: Alias for text_body, matching the send endpoint.

  • text_body (String)

    Body param

  • to (Array<String, Telnyx::Models::EmailInboxes::EmailAddress>)

    Body param

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/telnyx/resources/email_inboxes/drafts.rb', line 147

def update(draft_id, params)
  parsed, options = Telnyx::EmailInboxes::DraftUpdateParams.dump_request(params)
  inbox_id =
    parsed.delete(:inbox_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["email_inboxes/%1$s/drafts/%2$s", inbox_id, draft_id],
    body: parsed,
    model: Telnyx::EmailInboxes::EmailDraftResponse,
    options: options
  )
end