From b8a2068e4f1997d2949afd421f94735292dcdb7d Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 6 Nov 2023 17:52:28 +0530 Subject: [PATCH] chore: added PreviewMessaging directory --- src/rest/PreviewMessaging.ts | 15 ++ src/rest/previewMessaging/V1.ts | 47 ++++ src/rest/previewMessaging/v1/broadcast.ts | 204 ++++++++++++++++ src/rest/previewMessaging/v1/message.ts | 274 ++++++++++++++++++++++ 4 files changed, 540 insertions(+) create mode 100644 src/rest/PreviewMessaging.ts create mode 100644 src/rest/previewMessaging/V1.ts create mode 100644 src/rest/previewMessaging/v1/broadcast.ts create mode 100644 src/rest/previewMessaging/v1/message.ts diff --git a/src/rest/PreviewMessaging.ts b/src/rest/PreviewMessaging.ts new file mode 100644 index 000000000..6f26f3841 --- /dev/null +++ b/src/rest/PreviewMessaging.ts @@ -0,0 +1,15 @@ +import PreviewMessagingBase from "./PreviewMessagingBase"; +import {MessageListInstance} from "./previewMessaging/v1/message"; + +class PreviewMessaging extends PreviewMessagingBase { + /** + * @deprecated - Use v1.messages; instead + */ + get messages(): MessageListInstance { + console.warn( + "messages is deprecated. Use v1.messages; instead." + ); + return this.v1.messages; + } +} +export = PreviewMessaging diff --git a/src/rest/previewMessaging/V1.ts b/src/rest/previewMessaging/V1.ts new file mode 100644 index 000000000..b3a0f5a57 --- /dev/null +++ b/src/rest/previewMessaging/V1.ts @@ -0,0 +1,47 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Bulk Messaging and Broadcast + * Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import PreviewMessagingBase from "../PreviewMessagingBase"; +import Version from "../../base/Version"; +import { BroadcastListInstance } from "./v1/broadcast"; +import { MessageListInstance } from "./v1/message"; + +export default class V1 extends Version { + /** + * Initialize the V1 version of PreviewMessaging + * + * @param domain - The Twilio (Twilio.PreviewMessaging) domain + */ + constructor(domain: PreviewMessagingBase) { + super(domain, "v1"); + } + + /** broadcasts - { Twilio.PreviewMessaging.V1.BroadcastListInstance } resource */ + protected _broadcasts?: BroadcastListInstance; + /** messages - { Twilio.PreviewMessaging.V1.MessageListInstance } resource */ + protected _messages?: MessageListInstance; + + /** Getter for broadcasts resource */ + get broadcasts(): BroadcastListInstance { + this._broadcasts = this._broadcasts || BroadcastListInstance(this); + return this._broadcasts; + } + + /** Getter for messages resource */ + get messages(): MessageListInstance { + this._messages = this._messages || MessageListInstance(this); + return this._messages; + } + +} diff --git a/src/rest/previewMessaging/v1/broadcast.ts b/src/rest/previewMessaging/v1/broadcast.ts new file mode 100644 index 000000000..71849b6b0 --- /dev/null +++ b/src/rest/previewMessaging/v1/broadcast.ts @@ -0,0 +1,204 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Bulk Messaging and Broadcast + * Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + + +/** + * Details on the statuses of messages sent to recipients + */ +export class MessagingV1BroadcastExecutionDetails { + /** + * Number of recipients in the Broadcast request + */ + "totalRecords"?: number; + /** + * Number of recipients with messages successfully sent to them + */ + "totalCompleted"?: number; + /** + * Number of recipients with messages unsuccessfully sent to them, producing an error + */ + "totalErrors"?: number; +} + + + +/** + * Options to pass to create a BroadcastInstance + */ +export interface BroadcastListInstanceCreateOptions { + /** Idempotency key provided by the client */ + "xTwilioRequestKey"?: string; +} + + +export interface BroadcastSolution { +} + +export interface BroadcastListInstance { + _version: V1; + _solution: BroadcastSolution; + _uri: string; + + + + /** + * Create a BroadcastInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed BroadcastInstance + */ + create(callback?: (error: Error | null, item?: BroadcastInstance) => any): Promise; + /** + * Create a BroadcastInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed BroadcastInstance + */ + create(params: BroadcastListInstanceCreateOptions, callback?: (error: Error | null, item?: BroadcastInstance) => any): Promise; + + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function BroadcastListInstance(version: V1): BroadcastListInstance { + const instance = {} as BroadcastListInstance; + + instance._version = version; + instance._solution = { }; + instance._uri = `/Broadcasts`; + + instance.create = function create(params?: BroadcastListInstanceCreateOptions | ((error: Error | null, items: BroadcastInstance) => any), callback?: (error: Error | null, items: BroadcastInstance) => any): Promise { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + + + + + const headers: any = {}; + if (params["xTwilioRequestKey"] !== undefined) headers["X-Twilio-Request-Key"] = params["xTwilioRequestKey"]; + + let operationVersion = version, + operationPromise = operationVersion.create({ uri: instance._uri, method: "post", data, headers }); + + operationPromise = operationPromise.then(payload => new BroadcastInstance(operationVersion, payload)); + + + operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + return operationPromise; + + + } + + instance.toJSON = function toJSON() { + return instance._solution; + } + + instance[inspect.custom] = function inspectImpl(_depth: any, options: InspectOptions) { + return inspect(instance.toJSON(), options); + } + + return instance; +} + +interface BroadcastPayload extends BroadcastResource {} + +interface BroadcastResource { + broadcast_sid: string; + created_date: Date; + updated_date: Date; + broadcast_status: string; + execution_details: MessagingV1BroadcastExecutionDetails; + errors_file: string; +} + +/** + * Details of a Broadcast + */ +export class BroadcastInstance { + + constructor(protected _version: V1, payload: BroadcastResource) { + this.broadcastSid = (payload.broadcast_sid); + this.createdDate = deserialize.iso8601DateTime(payload.created_date); + this.updatedDate = deserialize.iso8601DateTime(payload.updated_date); + this.broadcastStatus = (payload.broadcast_status); + this.executionDetails = (payload.execution_details); + this.errorsFile = (payload.errors_file); + + } + + /** + * Numeric ID indentifying individual Broadcast requests + */ + broadcastSid: string; + /** + * Timestamp of when the Broadcast was created + */ + createdDate: Date; + /** + * Timestamp of when the Broadcast was last updated + */ + updatedDate: Date; + /** + * Status of the Broadcast request. Valid values are None, Pending-Upload, Uploaded, Queued, Executing, Execution-Failure, Execution-Completed, Cancelation-Requested, and Canceled + */ + broadcastStatus: string; + executionDetails: MessagingV1BroadcastExecutionDetails; + /** + * Path to a file detailing errors from Broadcast execution + */ + errorsFile: string; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + broadcastSid: this.broadcastSid, + createdDate: this.createdDate, + updatedDate: this.updatedDate, + broadcastStatus: this.broadcastStatus, + executionDetails: this.executionDetails, + errorsFile: this.errorsFile, + } + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} + + diff --git a/src/rest/previewMessaging/v1/message.ts b/src/rest/previewMessaging/v1/message.ts new file mode 100644 index 000000000..25031cfd3 --- /dev/null +++ b/src/rest/previewMessaging/v1/message.ts @@ -0,0 +1,274 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Bulk Messaging and Broadcast + * Bulk Sending is a public Twilio REST API for 1:Many Message creation up to 100 recipients. Broadcast is a public Twilio REST API for 1:Many Message creation up to 10,000 recipients via file upload. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + + +export class CreateMessagesRequest { + "messages"?: Array; + /** + * A Twilio phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format, an [alphanumeric sender ID](https://www.twilio.com/docs/sms/send-messages#use-an-alphanumeric-sender-id), or a [Channel Endpoint address](https://www.twilio.com/docs/sms/channels#channel-addresses) that is enabled for the type of message you want to send. Phone numbers or [short codes](https://www.twilio.com/docs/sms/api/short-code) purchased from Twilio also work here. You cannot, for example, spoof messages from a private cell phone number. If you are using `messaging_service_sid`, this parameter must be empty. + */ + "from"?: string; + /** + * The SID of the [Messaging Service](https://www.twilio.com/docs/sms/services#send-a-message-with-copilot) you want to associate with the Message. Set this parameter to use the [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) you have configured and leave the `from` parameter empty. When only this parameter is set, Twilio will use your enabled Copilot Features to select the `from` phone number for delivery. + */ + "messagingServiceSid"?: string; + /** + * The text of the message you want to send. Can be up to 1,600 characters in length. + */ + "body"?: string; + /** + * The SID of the preconfigured [Content Template](https://www.twilio.com/docs/content-api/create-and-send-your-first-content-api-template#create-a-template) you want to associate with the Message. Must be used in conjuction with a preconfigured [Messaging Service Settings and Copilot Features](https://www.twilio.com/console/sms/services) When this parameter is set, Twilio will use your configured content template and the provided `ContentVariables`. This Twilio product is currently in Private Beta. + */ + "contentSid"?: string; + /** + * The URL of the media to send with the message. The media can be of type `gif`, `png`, and `jpeg` and will be formatted correctly on the recipient\'s device. The media size limit is 5MB for supported file types (JPEG, PNG, GIF) and 500KB for [other types](https://www.twilio.com/docs/sms/accepted-mime-types) of accepted media. To send more than one image in the message body, provide multiple `media_url` parameters in the POST request. You can include up to 10 `media_url` parameters per message. You can send images in an SMS message in only the US and Canada. + */ + "mediaUrl"?: Array; + /** + * The URL we should call using the \"status_callback_method\" to send status information to your application. If specified, we POST these message status changes to the URL - queued, failed, sent, delivered, or undelivered. Twilio will POST its [standard request parameters](https://www.twilio.com/docs/messaging/twiml#request-parameters) as well as some additional parameters including \"MessageSid\", \"MessageStatus\", and \"ErrorCode\". If you include this parameter with the \"messaging_service_sid\", we use this URL instead of the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/messaging/services/api). URLs must contain a valid hostname and underscores are not allowed. + */ + "statusCallback"?: string; + /** + * How long in seconds the message can remain in our outgoing message queue. After this period elapses, the message fails and we call your status callback. Can be between 1 and the default value of 14,400 seconds. After a message has been accepted by a carrier, however, we cannot guarantee that the message will not be queued after this period. We recommend that this value be at least 5 seconds. + */ + "validityPeriod"?: number; + /** + * The time at which Twilio will send the message. This parameter can be used to schedule a message to be sent at a particular time. Must be in ISO 8601 format. + */ + "sendAt"?: string; + /** + * This parameter indicates your intent to schedule a message. Pass the value `fixed` to schedule a message at a fixed time. This parameter works in conjuction with the `SendAt` parameter. + */ + "scheduleType"?: string; + /** + * Determines the usage of Click Tracking. Setting it to `true` will instruct Twilio to replace all links in the Message with a shortened version based on the associated Domain Sid and track clicks on them. If this parameter is not set on an API call, we will use the value set on the Messaging Service. If this parameter is not set and the value is not configured on the Messaging Service used this will default to `false`. + */ + "shortenUrls"?: boolean; + /** + * If set to True, Twilio will deliver the message as a single MMS message, regardless of the presence of media. + */ + "sendAsMms"?: boolean; + /** + * The maximum total price in US dollars that you will pay for the message to be delivered. Can be a decimal value that has up to 4 decimal places. All messages are queued for delivery and the message cost is checked before the message is sent. If the cost exceeds max_price, the message will fail and a status of Failed is sent to the status callback. If MaxPrice is not set, the message cost is not checked. + */ + "maxPrice"?: number; + /** + * Total number of attempts made ( including this ) to send out the message regardless of the provider used + */ + "attempt"?: number; + /** + * This parameter indicates whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be true or false. + */ + "smartEncoded"?: boolean; + /** + * This parameter allows Twilio to send SMS traffic to carriers without checking/caring whether the destination number is a mobile or a landline. + */ + "forceDelivery"?: boolean; + /** + * The SID of the application that should receive message status. We POST a message_sid parameter and a message_status parameter with a value of sent or failed to the application\'s message_status_callback. If a status_callback parameter is also passed, it will be ignored and the application\'s message_status_callback parameter will be used. + */ + "applicationSid"?: string; +} + + +export class MessagingV1FailedMessageReceipt { + /** + * The recipient phone number + */ + "to"?: string; + /** + * The description of the error_code + */ + "errorMessage"?: string; + /** + * The error code associated with the message creation attempt + */ + "errorCode"?: number; +} + + +export class MessagingV1Message { + /** + * The destination phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format for SMS/MMS or [Channel user address](https://www.twilio.com/docs/sms/channels#channel-addresses) for other 3rd-party channels. + */ + "to"?: string; + /** + * The text of the message you want to send. Can be up to 1,600 characters in length. Overrides the request-level body and content template if provided. + */ + "body"?: string; + /** + * Key-value pairs of variable names to substitution values. Refer to the [Twilio Content API Resources](https://www.twilio.com/docs/content-api/content-api-resources#send-a-message-with-preconfigured-content) for more details. + */ + "contentVariables"?: { [key: string]: string; }; +} + + +export class MessagingV1MessageReceipt { + /** + * The recipient phone number + */ + "to"?: string | null; + /** + * The unique string that identifies the resource + */ + "sid"?: string | null; +} + + + +/** + * Options to pass to create a MessageInstance + */ +export interface MessageListInstanceCreateOptions { + /** */ + "createMessagesRequest": CreateMessagesRequest; +} + + +export interface MessageSolution { +} + +export interface MessageListInstance { + _version: V1; + _solution: MessageSolution; + _uri: string; + + + + /** + * Create a MessageInstance + * + * @param params - Body for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed MessageInstance + */ + create(params: CreateMessagesRequest, callback?: (error: Error | null, item?: MessageInstance) => any): Promise; + + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function MessageListInstance(version: V1): MessageListInstance { + const instance = {} as MessageListInstance; + + instance._version = version; + instance._solution = { }; + instance._uri = `/Messages`; + + instance.create = function create(params: CreateMessagesRequest, callback?: (error: Error | null, items: MessageInstance) => any): Promise { + if (params === null || params === undefined) { + throw new Error('Required parameter "params" missing.'); + } + + let data: any = {}; + + + + data = params + + const headers: any = {}; + headers["Content-Type"] = "application/json" + + let operationVersion = version, + operationPromise = operationVersion.create({ uri: instance._uri, method: "post", data, headers }); + + operationPromise = operationPromise.then(payload => new MessageInstance(operationVersion, payload)); + + + operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + return operationPromise; + + + } + + instance.toJSON = function toJSON() { + return instance._solution; + } + + instance[inspect.custom] = function inspectImpl(_depth: any, options: InspectOptions) { + return inspect(instance.toJSON(), options); + } + + return instance; +} + +interface MessagePayload extends MessageResource {} + +interface MessageResource { + total_message_count: number; + success_count: number; + error_count: number; + message_receipts: Array; + failed_message_receipts: Array; +} + +export class MessageInstance { + + constructor(protected _version: V1, payload: MessageResource) { + this.totalMessageCount = deserialize.integer(payload.total_message_count); + this.successCount = deserialize.integer(payload.success_count); + this.errorCount = deserialize.integer(payload.error_count); + this.messageReceipts = (payload.message_receipts); + this.failedMessageReceipts = (payload.failed_message_receipts); + + } + + /** + * The number of Messages processed in the request, equal to the sum of success_count and error_count. + */ + totalMessageCount: number; + /** + * The number of Messages successfully created. + */ + successCount: number; + /** + * The number of Messages unsuccessfully processed in the request. + */ + errorCount: number; + messageReceipts: Array; + failedMessageReceipts: Array; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + totalMessageCount: this.totalMessageCount, + successCount: this.successCount, + errorCount: this.errorCount, + messageReceipts: this.messageReceipts, + failedMessageReceipts: this.failedMessageReceipts, + } + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} + +