Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 1:n and custom tag in SMS #13377

Closed
wants to merge 14 commits into from
1 change: 1 addition & 0 deletions sdk/communication/communication-sms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@azure/communication-common": "1.0.0-beta.4",
"@azure/core-auth": "^1.1.3",
"@azure/core-http": "^1.2.0",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "1.0.0-preview.9",
"@azure/logger": "^1.0.0",
"@opentelemetry/api": "^0.10.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import { KeyCredential } from '@azure/core-auth';
import { OperationOptions } from '@azure/core-http';
import { PipelineOptions } from '@azure/core-http';
import { RestResponse } from '@azure/core-http';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface SendOptions extends OperationOptions {
enableDeliveryReport?: boolean;
tag?: string;
}

// @public
Expand All @@ -27,7 +27,8 @@ export class SmsClient {
constructor(connectionString: string, options?: SmsClientOptions);
constructor(url: string, credential: KeyCredential, options?: SmsClientOptions);
constructor(url: string, credential: TokenCredential, options?: SmsClientOptions);
send(sendRequest: SendRequest, options?: SendOptions): Promise<RestResponse>;
// Warning: (ae-forgotten-export) The symbol "SendSmsResponseItem" needs to be exported by the entry point index.d.ts
send(_sendRequest: SendRequest, _options?: SendOptions): Promise<SendSmsResponseItem>;
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ async function main() {
const from = "+12345678901";

// The list of E.164 formatted phone numbers to which message is being send
const to = ["+12345678901"];
const to = ["+12345678901", "+14251234567", "+12061234567"];

// The message being sent
const message = "Hey!";

console.log("-- Sending SMS --");
console.log("-- Sending Group SMS --");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not create new sample called sendGroupSms?


// Send SMS message
await client.send({ from, to, message }, { enableDeliveryReport: false });
await client.send({ from, to, message }, { enableDeliveryReport: true, tag: "customTag" });

console.log("Message sent!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export const main = async () => {
const from = "+12345678901";

// The list of E.164 formatted phone numbers to which message is being send
const to = ["+12345678901"];
const to = ["+12345678901", "+14251234567", "+12061234567"];

// The message being sent
const message = "Hey!";

console.log("-- Sending SMS --");
console.log("-- Sending Group SMS --");

// Send SMS message
await client.send({ from, to, message });
await client.send({ from, to, message }, { enableDeliveryReport: true, tag: "customTag" });

console.log("Message sent!");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/


import * as coreHttp from "@azure/core-http";

/**
* Optional configuration for sending SMS messages
* Optional configuration for sending SMS messages.
*/
export interface SendSmsOptions {
/**
* Enable this flag to receive a delivery report for this message on the Azure Resource EventGrid
* Enable this flag to receive a delivery report for this message on the Azure Resource
* EventGrid.
*/
enableDeliveryReport?: boolean;
/**
* Use this field to provide metadata that will then be sent back in the corresponding Delivery
* Report.
*/
tag?: string;
}

/**
Expand All @@ -27,8 +34,8 @@ export interface SendMessageRequest {
*/
from: string;
/**
* The recipients' phone number in E.164 format. In this version, only one recipient in the list
* is supported.
* The recipient's phone number in E.164 format. In this version, a minimum of 1 and upto 100
* recipients in the list are supported.
*/
to: string[];
/**
Expand All @@ -40,31 +47,87 @@ export interface SendMessageRequest {
}

/**
* Response for a successful send Sms request.
* Response for a single recipient.
*/
export interface SendSmsResponse {
export interface SendSmsResponseItem {
/**
* The identifier of the outgoing SMS message
* The recipients's phone number in E.164 format.
*/
to: string;
/**
* The identifier of the outgoing SMS message. Only present if message processed.
*/
messageId?: string;
/**
* HTTP Status code.
*/
httpStatusCode: number;
/**
* Optional error message in case of 4xx or 5xx errors.
*/
errorMessage?: string;
}

/**
* Response for a successful or multi status send Sms request.
*/
export interface SendSmsResponse {
value: SendSmsResponseItem[];
nextLink?: string;
}

/**
* Optional Parameters.
*/
export interface SmsSendOptionalParams extends coreHttp.RequestOptionsBase {
/**
* If specified, the client directs that the request is repeatable; that is, the client can make
* the request multiple times with the same Repeatability-Request-ID and get back an appropriate
* response without the server executing the request multiple times. The value of the
* Repeatability-Request-ID is an opaque string representing a client-generated, 36-character
* hexadecimal case-insensitive encoding of a UUID (GUID), identifier for the request.
*/
repeatabilityRequestId?: string;
/**
* MUST be sent by clients to specify that a request is repeatable. Repeatability-First-Sent is
* used to specify the date and time at which the request was first created.eg- Tue, 26 Mar 2019
* 16:06:51 GMT
*/
repeatabilityFirstSent?: string;
}

/**
* Defines headers for Send operation.
*/
export interface SmsSendHeaders {
/**
* Result of repeatibility request, if repeatability-request-id is provided.Values could be
* accepted or rejected.
*/
repeatabilityResult?: string;
}

/**
* Contains response data for the send operation.
*/
export type SmsSendResponse = SendSmsResponse & {
export type SmsSendResponse = SendSmsResponse & SmsSendHeaders & {
/**
* The underlying HTTP response.
*/
_response: coreHttp.HttpResponse & {
/**
* The response body as text (string format)
*/
bodyAsText: string;
/**
* The parsed HTTP response headers.
*/
parsedHeaders: SmsSendHeaders;

/**
* The response body as text (string format)
*/
bodyAsText: string;

/**
* The response body as parsed JSON or XML
*/
parsedBody: SendSmsResponse;
};
/**
* The response body as parsed JSON or XML
*/
parsedBody: SendSmsResponse;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import * as coreHttp from "@azure/core-http";


export const SendSmsOptions: coreHttp.CompositeMapper = {
serializedName: "SendSmsOptions",
type: {
Expand All @@ -19,6 +20,12 @@ export const SendSmsOptions: coreHttp.CompositeMapper = {
type: {
name: "Boolean"
}
},
tag: {
serializedName: "tag",
type: {
name: "String"
}
}
}
}
Expand Down Expand Up @@ -52,6 +59,10 @@ export const SendMessageRequest: coreHttp.CompositeMapper = {
message: {
required: true,
serializedName: "message",
constraints: {
MaxLength: 2048,
MinLength: 0
},
type: {
name: "String"
}
Expand All @@ -67,14 +78,79 @@ export const SendMessageRequest: coreHttp.CompositeMapper = {
}
};

export const SendSmsResponseItem: coreHttp.CompositeMapper = {
serializedName: "SendSmsResponseItem",
type: {
name: "Composite",
className: "SendSmsResponseItem",
modelProperties: {
to: {
required: true,
serializedName: "to",
type: {
name: "String"
}
},
messageId: {
serializedName: "messageId",
type: {
name: "String"
}
},
httpStatusCode: {
required: true,
serializedName: "httpStatusCode",
type: {
name: "Number"
}
},
errorMessage: {
serializedName: "errorMessage",
type: {
name: "String"
}
}
}
}
};

export const SendSmsResponse: coreHttp.CompositeMapper = {
serializedName: "SendSmsResponse",
type: {
name: "Composite",
className: "SendSmsResponse",
modelProperties: {
messageId: {
serializedName: "messageId",
value: {
required: true,
serializedName: "value",
type: {
name: "Sequence",
element: {
type: {
name: "Composite",
className: "SendSmsResponseItem"
}
}
}
},
nextLink: {
serializedName: "nextLink",
type: {
name: "String"
}
}
}
}
};

export const SmsSendHeaders: coreHttp.CompositeMapper = {
serializedName: "sms-send-headers",
type: {
name: "Composite",
className: "SmsSendHeaders",
modelProperties: {
repeatabilityResult: {
serializedName: "repeatability-result",
type: {
name: "String"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export const apiVersion: coreHttp.OperationQueryParameter = {
parameterPath: "apiVersion",
mapper: {
required: true,
isConstant: true,
serializedName: "api-version",
defaultValue: "2020-07-20-preview1",
type: {
name: "String"
}
Expand All @@ -27,10 +25,34 @@ export const endpoint: coreHttp.OperationURLParameter = {
mapper: {
required: true,
serializedName: "endpoint",
defaultValue: "",
defaultValue: '',
type: {
name: "String"
}
},
skipEncoding: true
};
export const repeatabilityFirstSent: coreHttp.OperationParameter = {
parameterPath: [
"options",
"repeatabilityFirstSent"
],
mapper: {
serializedName: "repeatability-first-sent",
type: {
name: "String"
}
}
};
export const repeatabilityRequestId: coreHttp.OperationParameter = {
parameterPath: [
"options",
"repeatabilityRequestId"
],
mapper: {
serializedName: "repeatability-request-id",
type: {
name: "String"
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

export { SendMessageRequest, SendSmsOptions, SendSmsResponse } from "../models/mappers";
export {
SendMessageRequest,
SendSmsOptions,
SendSmsResponse,
SendSmsResponseItem,
SmsSendHeaders
} from "../models/mappers";
Loading