telnyx-messaging-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- 由Telnyx OpenAPI规范自动生成,请勿编辑。 -->
Telnyx Messaging - Ruby
Telnyx 消息服务 - Ruby
Installation
安装
bash
gem install telnyxbash
gem install telnyxSetup
配置
ruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted
)All examples below assume is already initialized as shown above.
clientruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # 这是默认配置,可省略
)以下所有示例均假设已按上述方式完成初始化。
clientSend a message
发送消息
Send a message with a Phone Number, Alphanumeric Sender ID, Short Code or Number Pool.
POST /messagestoOptional: (boolean), (enum), (string), (array[string]), (string), (date-time), (string), (string), (enum), (boolean), (url), (url)
auto_detectencodingfrommedia_urlsmessaging_profile_idsend_atsubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_(to: "+18445550001")
puts(response)可使用电话号码、字母数字发送方ID、短码或号码池发送消息。
POST /messagesto可选参数:(布尔值)、(枚举)、(字符串)、(字符串数组)、(字符串)、(日期时间)、(字符串)、(字符串)、(枚举)、(布尔值)、(URL)、(URL)
auto_detectencodingfrommedia_urlsmessaging_profile_idsend_atsubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_(to: "+18445550001")
puts(response)Retrieve a message
检索消息
Note: This API endpoint can only retrieve messages that are no older than 10 days since their creation.
GET /messages/{id}ruby
message = client.messages.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
puts(message)注意:此API端点仅能检索创建时间不超过10天的消息。
GET /messages/{id}ruby
message = client.messages.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
puts(message)Cancel a scheduled message
取消已调度的消息
Cancel a scheduled message that has not yet been sent.
DELETE /messages/{id}ruby
response = client.messages.cancel_scheduled("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
puts(response)取消尚未发送的已调度消息。
DELETE /messages/{id}ruby
response = client.messages.cancel_scheduled("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
puts(response)Send a Whatsapp message
发送WhatsApp消息
POST /messages/whatsappfromtowhatsapp_messageOptional: (enum), (url)
typewebhook_urlruby
response = client.messages.send_whatsapp(from: "+13125551234", to: "+13125551234", whatsapp_message: {})
puts(response)POST /messages/whatsappfromtowhatsapp_message可选参数:(枚举)、(URL)
typewebhook_urlruby
response = client.messages.send_whatsapp(from: "+13125551234", to: "+13125551234", whatsapp_message: {})
puts(response)Send a group MMS message
发送群组MMS消息
POST /messages/group_mmsfromtoOptional: (array[string]), (string), (string), (boolean), (url), (url)
media_urlssubjecttextuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_group_mms(from: "+13125551234", to: ["+18655551234", "+14155551234"])
puts(response)POST /messages/group_mmsfromto可选参数:(字符串数组)、(字符串)、(字符串)、(布尔值)、(URL)、(URL)
media_urlssubjecttextuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_group_mms(from: "+13125551234", to: ["+18655551234", "+14155551234"])
puts(response)Send a long code message
发送长码消息
POST /messages/long_codefromtoOptional: (boolean), (enum), (array[string]), (string), (string), (enum), (boolean), (url), (url)
auto_detectencodingmedia_urlssubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_long_code(from: "+18445550001", to: "+13125550002")
puts(response)POST /messages/long_codefromto可选参数:(布尔值)、(枚举)、(字符串数组)、(字符串)、(字符串)、(枚举)、(布尔值)、(URL)、(URL)
auto_detectencodingmedia_urlssubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_long_code(from: "+18445550001", to: "+13125550002")
puts(response)Send a message using number pool
使用号码池发送消息
POST /messages/number_pooltomessaging_profile_idOptional: (boolean), (enum), (array[string]), (string), (string), (enum), (boolean), (url), (url)
auto_detectencodingmedia_urlssubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_number_pool(
messaging_profile_id: "abc85f64-5717-4562-b3fc-2c9600000000",
to: "+13125550002"
)
puts(response)POST /messages/number_pooltomessaging_profile_id可选参数:(布尔值)、(枚举)、(字符串数组)、(字符串)、(字符串)、(枚举)、(布尔值)、(URL)、(URL)
auto_detectencodingmedia_urlssubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_number_pool(
messaging_profile_id: "abc85f64-5717-4562-b3fc-2c9600000000",
to: "+13125550002"
)
puts(response)Schedule a message
调度消息
Schedule a message with a Phone Number, Alphanumeric Sender ID, Short Code or Number Pool.
POST /messages/scheduletoOptional: (boolean), (string), (array[string]), (string), (date-time), (string), (string), (enum), (boolean), (url), (url)
auto_detectfrommedia_urlsmessaging_profile_idsend_atsubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.schedule(to: "+18445550001")
puts(response)可使用电话号码、字母数字发送方ID、短码或号码池调度消息。
POST /messages/scheduleto可选参数:(布尔值)、(字符串)、(字符串数组)、(字符串)、(日期时间)、(字符串)、(字符串)、(枚举)、(布尔值)、(URL)、(URL)
auto_detectfrommedia_urlsmessaging_profile_idsend_atsubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.schedule(to: "+18445550001")
puts(response)Send a short code message
发送短码消息
POST /messages/short_codefromtoOptional: (boolean), (enum), (array[string]), (string), (string), (enum), (boolean), (url), (url)
auto_detectencodingmedia_urlssubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_short_code(from: "+18445550001", to: "+18445550001")
puts(response)POST /messages/short_codefromto可选参数:(布尔值)、(枚举)、(字符串数组)、(字符串)、(字符串)、(枚举)、(布尔值)、(URL)、(URL)
auto_detectencodingmedia_urlssubjecttexttypeuse_profile_webhookswebhook_failover_urlwebhook_urlruby
response = client.messages.send_short_code(from: "+18445550001", to: "+18445550001")
puts(response)List opt-outs
列出退订记录
Retrieve a list of opt-out blocks.
GET /messaging_optoutsruby
page = client.messaging_optouts.list
puts(page)检索退订阻止列表。
GET /messaging_optoutsruby
page = client.messaging_optouts.list
puts(page)Retrieve a phone number with messaging settings
检索带消息设置的电话号码
GET /phone_numbers/{id}/messagingruby
messaging = client.phone_numbers.messaging.retrieve("id")
puts(messaging)GET /phone_numbers/{id}/messagingruby
messaging = client.phone_numbers.messaging.retrieve("id")
puts(messaging)Update the messaging profile and/or messaging product of a phone number
更新电话号码的消息配置文件和/或消息产品
PATCH /phone_numbers/{id}/messagingOptional: (string), (string), (array[string])
messaging_productmessaging_profile_idtagsruby
messaging = client.phone_numbers.messaging.update("id")
puts(messaging)PATCH /phone_numbers/{id}/messaging可选参数:(字符串)、(字符串)、(字符串数组)
messaging_productmessaging_profile_idtagsruby
messaging = client.phone_numbers.messaging.update("id")
puts(messaging)List phone numbers with messaging settings
列出带消息设置的电话号码
GET /phone_numbers/messagingruby
page = client.phone_numbers.messaging.list
puts(page)GET /phone_numbers/messagingruby
page = client.phone_numbers.messaging.list
puts(page)Retrieve a mobile phone number with messaging settings
检索带消息设置的移动电话号码
GET /mobile_phone_numbers/{id}/messagingruby
messaging = client.mobile_phone_numbers.messaging.retrieve("id")
puts(messaging)GET /mobile_phone_numbers/{id}/messagingruby
messaging = client.mobile_phone_numbers.messaging.retrieve("id")
puts(messaging)List mobile phone numbers with messaging settings
列出带消息设置的移动电话号码
GET /mobile_phone_numbers/messagingruby
page = client.mobile_phone_numbers.messaging.list
puts(page)GET /mobile_phone_numbers/messagingruby
page = client.mobile_phone_numbers.messaging.list
puts(page)Bulk update phone number profiles
批量更新电话号码配置文件
POST /messaging_numbers/bulk_updatesmessaging_profile_idnumbersOptional: (boolean)
assign_onlyruby
messaging_numbers_bulk_update = client.messaging_numbers_bulk_updates.create(
messaging_profile_id: "00000000-0000-0000-0000-000000000000",
numbers: ["+18880000000", "+18880000001", "+18880000002"]
)
puts(messaging_numbers_bulk_update)POST /messaging_numbers/bulk_updatesmessaging_profile_idnumbers可选参数:(布尔值)
assign_onlyruby
messaging_numbers_bulk_update = client.messaging_numbers_bulk_updates.create(
messaging_profile_id: "00000000-0000-0000-0000-000000000000",
numbers: ["+18880000000", "+18880000001", "+18880000002"]
)
puts(messaging_numbers_bulk_update)Retrieve bulk update status
检索批量更新状态
GET /messaging_numbers/bulk_updates/{order_id}ruby
messaging_numbers_bulk_update = client.messaging_numbers_bulk_updates.retrieve("order_id")
puts(messaging_numbers_bulk_update)GET /messaging_numbers/bulk_updates/{order_id}ruby
messaging_numbers_bulk_update = client.messaging_numbers_bulk_updates.retrieve("order_id")
puts(messaging_numbers_bulk_update)Webhooks
Webhook
The following webhook events are sent to your configured webhook URL.
All webhooks include and headers for verification (Standard Webhooks compatible).
telnyx-timestamptelnyx-signature-ed25519| Event | Description |
|---|---|
| Delivery Update |
| Inbound Message |
| Replaced Link Click |
以下Webhook事件将发送到您配置的Webhook URL。所有Webhook均包含和头用于验证(兼容标准Webhook)。
telnyx-timestamptelnyx-signature-ed25519| 事件 | 描述 |
|---|---|
| 投递更新 |
| 入站消息 |
| 替换链接点击 |
Webhook payload fields
Webhook 负载字段
deliveryUpdate| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| uuid | Identifies the type of resource. |
| enum | The type of event being delivered. |
| date-time | ISO 8601 formatted date indicating when the resource was created. |
| enum | Identifies the type of the resource. |
| enum | The direction of the message. |
| uuid | Identifies the type of resource. |
| enum | The type of message. |
| string | Unique identifier for a messaging profile. |
| uuid | The id of the organization the messaging profile belongs to. |
| array[object] | |
| array[object] | |
| string | Message body (i.e., content) as a non-empty string. |
| ['string', 'null'] | Subject of multimedia message |
| array[object] | |
| url | The URL where webhooks related to this message will be sent. |
| url | The failover URL where webhooks related to this message will be sent if sending to the primary URL fails. |
| string | Encoding scheme used for the message body. |
| integer | Number of parts into which the message's body must be split. |
| array[string] | Tags associated with the resource. |
| ['object', 'null'] | |
| ['object', 'null'] | Detailed breakdown of the message cost components. |
| ['string', 'null'] | The Campaign Registry (TCR) campaign ID associated with the message. |
| boolean | Indicates whether the TCR campaign is billable. |
| ['string', 'null'] | The registration status of the TCR campaign. |
| date-time | ISO 8601 formatted date indicating when the message request was received. |
| date-time | ISO 8601 formatted date indicating when the message was sent. |
| date-time | ISO 8601 formatted date indicating when the message was finalized. |
| date-time | Message must be out of the queue by this time or else it will be discarded and marked as 'sending_failed'. |
| array[object] | These errors may point at addressees when referring to unsuccessful/unconfirmed delivery statuses. |
| boolean | Indicates whether smart encoding was applied to this message. |
| integer | Number of attempts to deliver the webhook event. |
| url | The webhook URL the event was delivered to. |
inboundMessage| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| uuid | Identifies the type of resource. |
| enum | The type of event being delivered. |
| date-time | ISO 8601 formatted date indicating when the resource was created. |
| enum | Identifies the type of the resource. |
| enum | The direction of the message. |
| uuid | Identifies the type of resource. |
| enum | The type of message. |
| string | Unique identifier for a messaging profile. |
| string | Unique identifier for a messaging profile. |
| array[object] | |
| array[object] | |
| string | Message body (i.e., content) as a non-empty string. |
| ['string', 'null'] | Message subject. |
| array[object] | |
| url | The URL where webhooks related to this message will be sent. |
| url | The failover URL where webhooks related to this message will be sent if sending to the primary URL fails. |
| string | Encoding scheme used for the message body. |
| integer | Number of parts into which the message's body must be split. |
| array[string] | Tags associated with the resource. |
| ['object', 'null'] | |
| ['object', 'null'] | Detailed breakdown of the message cost components. |
| ['string', 'null'] | The Campaign Registry (TCR) campaign ID associated with the message. |
| boolean | Indicates whether the TCR campaign is billable. |
| ['string', 'null'] | The registration status of the TCR campaign. |
| date-time | ISO 8601 formatted date indicating when the message request was received. |
| date-time | Not used for inbound messages. |
| date-time | Not used for inbound messages. |
| date-time | Not used for inbound messages. |
| array[object] | These errors may point at addressees when referring to unsuccessful/unconfirmed delivery statuses. |
replacedLinkClick| Field | Type | Description |
|---|---|---|
| string | Identifies the type of the resource. |
| string | The original link that was sent in the message. |
| string | Sending address (+E.164 formatted phone number, alphanumeric sender ID, or short code). |
| uuid | The message ID associated with the clicked link. |
| date-time | ISO 8601 formatted date indicating when the message request was received. |
deliveryUpdate| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型。 |
| UUID | 标识资源类型。 |
| 枚举 | 投递的事件类型。 |
| 日期时间 | ISO 8601格式的日期,指示资源创建时间。 |
| 枚举 | 标识资源类型。 |
| 枚举 | 消息的方向。 |
| UUID | 标识资源类型。 |
| 枚举 | 消息类型。 |
| 字符串 | 消息配置文件的唯一标识符。 |
| UUID | 消息配置文件所属组织的ID。 |
| 对象数组 | |
| 对象数组 | |
| 字符串 | 消息正文(即内容),非空字符串。 |
| ['字符串', '空值'] | 多媒体消息的主题 |
| 对象数组 | |
| URL | 与该消息相关的Webhook将发送到的URL。 |
| URL | 如果主URL投递失败,与该消息相关的Webhook将发送到的故障转移URL。 |
| 字符串 | 消息正文使用的编码方案。 |
| 整数 | 消息正文必须拆分的部分数量。 |
| 字符串数组 | 与资源关联的标签。 |
| ['对象', '空值'] | |
| ['对象', '空值'] | 消息成本构成的详细细分。 |
| ['字符串', '空值'] | 与消息关联的Campaign Registry (TCR) 活动ID。 |
| 布尔值 | 指示TCR活动是否可计费。 |
| ['字符串', '空值'] | TCR活动的注册状态。 |
| 日期时间 | ISO 8601格式的日期,指示消息请求的接收时间。 |
| 日期时间 | ISO 8601格式的日期,指示消息的发送时间。 |
| 日期时间 | ISO 8601格式的日期,指示消息的完成时间。 |
| 日期时间 | 消息必须在此时间前离开队列,否则将被丢弃并标记为'sending_failed'。 |
| 对象数组 | 当涉及未成功/未确认的投递状态时,这些错误可能指向收件人。 |
| 布尔值 | 指示是否对该消息应用了智能编码。 |
| 整数 | 投递Webhook事件的尝试次数。 |
| URL | 事件投递到的Webhook URL。 |
inboundMessage| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举 | 标识资源类型。 |
| UUID | 标识资源类型。 |
| 枚举 | 投递的事件类型。 |
| 日期时间 | ISO 8601格式的日期,指示资源创建时间。 |
| 枚举 | 标识资源类型。 |
| 枚举 | 消息的方向。 |
| UUID | 标识资源类型。 |
| 枚举 | 消息类型。 |
| 字符串 | 消息配置文件的唯一标识符。 |
| 字符串 | 消息配置文件的唯一标识符。 |
| 对象数组 | |
| 对象数组 | |
| 字符串 | 消息正文(即内容),非空字符串。 |
| ['字符串', '空值'] | 消息主题。 |
| 对象数组 | |
| URL | 与该消息相关的Webhook将发送到的URL。 |
| URL | 如果主URL投递失败,与该消息相关的Webhook将发送到的故障转移URL。 |
| 字符串 | 消息正文使用的编码方案。 |
| 整数 | 消息正文必须拆分的部分数量。 |
| 字符串数组 | 与资源关联的标签。 |
| ['对象', '空值'] | |
| ['对象', '空值'] | 消息成本构成的详细细分。 |
| ['字符串', '空值'] | 与消息关联的Campaign Registry (TCR) 活动ID。 |
| 布尔值 | 指示TCR活动是否可计费。 |
| ['字符串', '空值'] | TCR活动的注册状态。 |
| 日期时间 | ISO 8601格式的日期,指示消息请求的接收时间。 |
| 日期时间 | 入站消息不使用此字段。 |
| 日期时间 | 入站消息不使用此字段。 |
| 日期时间 | 入站消息不使用此字段。 |
| 对象数组 | 当涉及未成功/未确认的投递状态时,这些错误可能指向收件人。 |
replacedLinkClick| 字段 | 类型 | 描述 |
|---|---|---|
| 字符串 | 标识资源类型。 |
| 字符串 | 消息中发送的原始链接。 |
| 字符串 | 发送地址(+E.164格式电话号码、字母数字发送方ID或短码)。 |
| UUID | 与点击链接关联的消息ID。 |
| 日期时间 | ISO 8601格式的日期,指示消息请求的接收时间。 |